[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25259] trunk/blender/source/blender/ makesrna/intern/rna_ID.c: give IDPropertyGroups' s an identifier so they can display text in the listview, hardcoded to " name"

Campbell Barton ideasman42 at gmail.com
Wed Dec 9 23:37:02 CET 2009


Revision: 25259
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25259
Author:   campbellbarton
Date:     2009-12-09 23:37:02 +0100 (Wed, 09 Dec 2009)

Log Message:
-----------
give IDPropertyGroups's an identifier so they can display text in the listview, hardcoded to "name"

Modified Paths:
--------------
    trunk/blender/source/blender/makesrna/intern/rna_ID.c

Modified: trunk/blender/source/blender/makesrna/intern/rna_ID.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_ID.c	2009-12-09 21:42:21 UTC (rev 25258)
+++ trunk/blender/source/blender/makesrna/intern/rna_ID.c	2009-12-09 22:37:02 UTC (rev 25259)
@@ -225,6 +225,40 @@
 	return NULL;
 }
 
+static int rna_IDPropertyGroup_name_length(PointerRNA *ptr)
+{
+	IDProperty *group=(IDProperty*)ptr->id.data;
+	IDProperty *idprop;
+	idprop= IDP_GetPropertyFromGroup(group, "name");
+
+	if(idprop && idprop->type == IDP_STRING)
+		return strlen(idprop->data.pointer);
+	else
+		return 0;
+}
+
+static void rna_IDPropertyGroup_name_get(PointerRNA *ptr, char *str)
+{
+	IDProperty *group=(IDProperty*)ptr->id.data;
+	IDProperty *idprop;
+	idprop= IDP_GetPropertyFromGroup(group, "name");
+
+	if(idprop && idprop->type == IDP_STRING)
+		strcpy(str, idprop->data.pointer);
+	else
+		strcpy(str, "");
+}
+
+void rna_IDPropertyGroup_name_set(PointerRNA *ptr, const char *value)
+{
+	IDProperty *group=(IDProperty*)ptr->id.data;
+	IDProperty *idprop;
+	IDPropertyTemplate val = {0};
+	val.str= (char *)value;
+	idprop = IDP_New(IDP_STRING, val, "name");
+	IDP_ReplaceInGroup(group, idprop);
+}
+
 #else
 
 static void rna_def_ID_properties(BlenderRNA *brna)
@@ -275,6 +309,15 @@
 	RNA_def_property_flag(prop, PROP_EXPORT|PROP_IDPROPERTY);
 	RNA_def_property_struct_type(prop, "IDPropertyGroup");
 
+	// never tested, maybe its useful to have this?
+#if 0
+	prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
+	RNA_def_property_flag(prop, PROP_EXPORT|PROP_IDPROPERTY);
+	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+	RNA_def_property_ui_text(prop, "Name", "Unique name used in the code and scripting.");
+	RNA_def_struct_name_property(srna, prop);
+#endif
+
 	/* IDP_ID -- not implemented yet in id properties */
 
 	/* ID property groups > level 0, since level 0 group is merged
@@ -285,6 +328,16 @@
 	RNA_def_struct_idproperties_func(srna, "rna_IDPropertyGroup_idproperties");
 	RNA_def_struct_register_funcs(srna, "rna_IDPropertyGroup_register", "rna_IDPropertyGroup_unregister");
 	RNA_def_struct_refine_func(srna, "rna_IDPropertyGroup_refine");
+
+	/* important so python types can have their name used in list views
+	 * however this isnt prefect because it overrides how python would set the name
+	 * when we only really want this so RNA_def_struct_name_property() is set to something useful */
+	prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
+	RNA_def_property_flag(prop, PROP_EXPORT|PROP_IDPROPERTY);
+	//RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+	RNA_def_property_ui_text(prop, "Name", "Unique name used in the code and scripting.");
+	RNA_def_property_string_funcs(prop, "rna_IDPropertyGroup_name_get", "rna_IDPropertyGroup_name_length", "rna_IDPropertyGroup_name_set");
+	RNA_def_struct_name_property(srna, prop);
 }
 
 static void rna_def_ID(BlenderRNA *brna)





More information about the Bf-blender-cvs mailing list