Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/interface/interface_templates.c')
-rw-r--r--source/blender/editors/interface/interface_templates.c54
1 files changed, 51 insertions, 3 deletions
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index b816d1a8f9c..19d22a432dc 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -2059,7 +2059,7 @@ static int list_item_icon_get(bContext *C, PointerRNA *itemptr, int rnaicon, int
return rnaicon;
}
-static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, PointerRNA *itemptr, int i, int rnaicon, PointerRNA *activeptr, PropertyRNA *activeprop)
+static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, PointerRNA *itemptr, int i, int rnaicon, PointerRNA *activeptr, PropertyRNA *activeprop, const char *prop_list_id)
{
uiBlock *block= uiLayoutGetBlock(layout);
uiBut *but;
@@ -2164,6 +2164,54 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe
/* nothing else special to do... */
uiItemL(sub, name, icon); /* fails, backdrop LISTROW... */
}
+ /* There is a last chance to display custom controls (in addition to the name/label):
+ * If the given item property group features a string property named as prop_list,
+ * this tries to add controls for all properties of the item listed in that string property.
+ * (colon-separated names).
+ *
+ * This is especially useful for python. E.g., if you list a collection of this property
+ * group:
+ *
+ * class TestPropertyGroup(bpy.types.PropertyGroup):
+ * bool = BoolProperty(default=False)
+ * integer = IntProperty()
+ * string = StringProperty()
+ *
+ * # A string of all identifiers (colon-separated) which property’s controls should be
+ * # displayed in a template_list.
+ * template_list_controls = StringProperty(default="integer:bool:string", options={"HIDDEN"})
+ *
+ * … you’ll get a numfield for the integer prop, a check box for the bool prop, and a textfield
+ * for the string prop, after the name of each item of the collection.
+ */
+ else if (prop_list_id) {
+ row = uiLayoutRow(sub, 1);
+ uiItemL(row, name, icon);
+
+ /* XXX: Check, as sometimes we get an itemptr looking like
+ * {id = {data = 0x0}, type = 0x0, data = 0x0}
+ * which would obviously produce a sigsev… */
+ if (itemptr->type) {
+ /* If the special property is set for the item, and it is a collection… */
+ PropertyRNA *prop_list= RNA_struct_find_property(itemptr, prop_list_id);
+
+ if(prop_list && RNA_property_type(prop_list) == PROP_STRING) {
+ int prop_names_len;
+ char *prop_names = RNA_property_string_get_alloc(itemptr, prop_list, NULL, 0, &prop_names_len);
+ char *prop_names_end= prop_names + prop_names_len;
+ char *id= prop_names;
+ char *id_next;
+ while (id < prop_names_end) {
+ if ((id_next= strchr(id, ':'))) *id_next++= '\0';
+ else id_next= prop_names_end;
+ uiItemR(row, itemptr, id, 0, NULL, 0);
+ id= id_next;
+ }
+ MEM_freeN(prop_names);
+ }
+ }
+ }
+
else
uiItemL(sub, name, icon); /* fails, backdrop LISTROW... */
@@ -2172,7 +2220,7 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe
MEM_freeN(namebuf);
}
-void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, PointerRNA *activeptr, const char *activepropname, int rows, int maxrows, int listtype)
+void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, PointerRNA *activeptr, const char *activepropname, const char *prop_list, int rows, int maxrows, int listtype)
{
//Scene *scene= CTX_data_scene(C);
PropertyRNA *prop= NULL, *activeprop;
@@ -2326,7 +2374,7 @@ void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *
/* create list items */
RNA_PROP_BEGIN(ptr, itemptr, prop) {
if(i >= pa->list_scroll && i<pa->list_scroll+items)
- list_item_row(C, col, ptr, &itemptr, i, rnaicon, activeptr, activeprop);
+ list_item_row(C, col, ptr, &itemptr, i, rnaicon, activeptr, activeprop, prop_list);
i++;
}