ensure grease pencil layer names are unique when set through rna.
authorCampbell Barton <ideasman42@gmail.com>
Thu, 13 Oct 2011 04:06:32 +0000 (04:06 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 13 Oct 2011 04:06:32 +0000 (04:06 +0000)
source/blender/blenkernel/intern/gpencil.c
source/blender/makesdna/DNA_gpencil_types.h
source/blender/makesrna/intern/rna_gpencil.c

index 06ca7b7b5090eb5bfdd308cebc697d71892603db..fa493315d4b66dfeaf25d16e09ea416d8d078799 100644 (file)
@@ -185,7 +185,7 @@ bGPDlayer *gpencil_layer_addnew (bGPdata *gpd)
        
        /* auto-name */
        strcpy(gpl->info, "GP_Layer");
-       BLI_uniquename(&gpd->layers, gpl, "GP_Layer", '.', offsetof(bGPDlayer, info[0]), sizeof(gpl->info));
+       BLI_uniquename(&gpd->layers, gpl, "GP_Layer", '.', offsetof(bGPDlayer, info), sizeof(gpl->info));
        
        /* make this one the active one */
        gpencil_layer_setactive(gpd, gpl);
index b259d5928646cea90ab5957a1deed762f74c4d16..a4d0b3685e3e780f4c9d58f5e04b8244a619fcc5 100644 (file)
@@ -99,7 +99,8 @@ typedef struct bGPDlayer {
        
        float color[4];                 /* color that should be used to draw all the strokes in this layer */
        
-       char info[128];                 /* optional reference info about this layer (i.e. "director's comments, 12/3") */
+       char info[128];                 /* optional reference info about this layer (i.e. "director's comments, 12/3")
+                                                        * this is used for the name of the layer  too and kept unique. */
 } bGPDlayer;
 
 /* bGPDlayer->flag */
index 810db9f36345a5a66df56d0f70c6e960b0622704..371c387e871a415025cfca32dd88fc1a8d7237ec 100644 (file)
@@ -40,6 +40,8 @@
 
 #ifdef RNA_RUNTIME
 
+#include "BLI_path_util.h"
+
 static int rna_GPencilLayer_active_frame_editable(PointerRNA *ptr)
 {
        bGPDlayer *gpl= (bGPDlayer *)ptr->data;
@@ -90,6 +92,17 @@ static void rna_GPencil_active_layer_set(PointerRNA *ptr, PointerRNA value)
        }
 }
 
+void rna_GPencilLayer_info_set(PointerRNA *ptr, const char *value)
+{
+       bGPdata *gpd= ptr->id.data;
+       bGPDlayer *gpl= ptr->data;
+
+       /* copy the new name into the name slot */
+       BLI_strncpy_utf8(gpl->info, value, sizeof(gpl->info));
+
+       BLI_uniquename(&gpd->layers, gpl, "GP_Layer", '.', offsetof(bGPDlayer, info), sizeof(gpl->info));
+}
+
 #else
 
 static void rna_def_gpencil_stroke_point(BlenderRNA *brna)
@@ -176,6 +189,7 @@ static void rna_def_gpencil_layer(BlenderRNA *brna)
        /* Name */
        prop= RNA_def_property(srna, "info", PROP_STRING, PROP_NONE);
        RNA_def_property_ui_text(prop, "Info", "Layer name");
+       RNA_def_property_string_funcs(prop, NULL, NULL, "rna_GPencilLayer_info_set");
        RNA_def_struct_name_property(srna, prop);
        
        /* Frames */