Page MenuHome

ui_template_list_svn41177.patch

ui_template_list_svn41177.patch

Index: source/blender/makesrna/intern/rna_ui_api.c
===================================================================
--- source/blender/makesrna/intern/rna_ui_api.c (révision 41176)
+++ source/blender/makesrna/intern/rna_ui_api.c (copie de travail)
@@ -410,6 +410,9 @@
RNA_def_property_flag(parm, PROP_REQUIRED|PROP_RNAPTR|PROP_NEVER_NULL);
parm= RNA_def_string(func, "active_property", "", 0, "", "Identifier of property in data, for the active element");
RNA_def_property_flag(parm, PROP_REQUIRED);
+ parm= RNA_def_string(func, "enum_ctrls_name", "", 0, "",
+ "Identifier of a string property in each data memeber, specifying which "
+ "of its properties should have a widget displayed in its row.");
RNA_def_int(func, "rows", 5, 0, INT_MAX, "", "Number of rows to display", 0, INT_MAX);
RNA_def_int(func, "maxrows", 5, 0, INT_MAX, "", "Maximum number of rows to display", 0, INT_MAX);
RNA_def_enum(func, "type", list_type_items, 0, "Type", "Type of list to use");
Index: source/blender/blenlib/BLI_string.h
===================================================================
--- source/blender/blenlib/BLI_string.h (révision 41176)
+++ source/blender/blenlib/BLI_string.h (copie de travail)
@@ -135,6 +135,29 @@
int BLI_natstrcmp(const char *s1, const char *s2);
size_t BLI_strnlen(const char *str, size_t maxlen);
+ /**
+ * Split str on the first occurence of delimiter, returns the first
+ * part as a mallocN'd string, and stores the second part into
+ * ctx (also mallocN'd).
+ * If str is NULL, split on ctx instead.
+ * This allows to iterate over this "generator" function:
+ *
+ * char *ctx = NULL;
+ * char *res = NULL;
+ * for(res = BLI_strtok_r("a;dummy;csv;line", ";", &ctx); res; res = BLI_strtok_r(NULL, ";", &ctx)) {
+ * printf(res);
+ * MEM_freeN(res);
+ * }
+ *
+ * @param str The string to be split.
+ * @param delimiter The char used to split str apart.
+ * @param ctx The "context" string. It’s memmory management is done internally,
+ * except if you do not go to the end of the splitting, in which case
+ * you’ll have to freeN it yourself.
+ * @retval Returns the mallocN'd first element from split str (or ctx).
+ */
+char *BLI_strtok_r(char *str, const char *delimiter, char **ctx);
+
void BLI_timestr(double _time, char *str); /* time var is global */
void BLI_ascii_strtolower(char *str, int len);
Index: source/blender/blenlib/intern/string.c
===================================================================
--- source/blender/blenlib/intern/string.c (révision 41176)
+++ source/blender/blenlib/intern/string.c (copie de travail)
@@ -377,6 +377,51 @@
return 0;
}
+/* As unfortunately strtok_r is not available everywhere... */
+char *BLI_strtok_r(char *str, const char *delimiter, char **ctx)
+{
+ char *split = str;
+ char *cut = NULL;
+
+ if(!split) {
+ if(*ctx) {
+ split = *ctx;
+ }
+ else {
+ return NULL;
+ }
+ }
+
+ cut = strchr(split, *delimiter);
+ if(cut) {
+ size_t len_ret = cut - split;
+ char *ret = BLI_strdupn(split, len_ret);
+ size_t len_ctx = strlen(split) - len_ret - 1;
+ if(len_ctx != 0) {
+ char *new_ctx = BLI_strdupn(cut+1, len_ctx);
+ if(*ctx) {
+ MEM_freeN(*ctx);
+ }
+ *ctx = new_ctx;
+ }
+ else {
+ if(*ctx) {
+ MEM_freeN(*ctx);
+ }
+ *ctx = NULL;
+ }
+ return ret;
+ }
+ else {
+ char *ret = BLI_strdup(split);
+ if(*ctx) {
+ MEM_freeN(*ctx);
+ *ctx = NULL;
+ }
+ return ret;
+ }
+}
+
void BLI_timestr(double _time, char *str)
{
/* format 00:00:00.00 (hr:min:sec) string has to be 12 long */
Index: source/blender/editors/include/UI_interface.h
===================================================================
--- source/blender/editors/include/UI_interface.h (révision 41176)
+++ source/blender/editors/include/UI_interface.h (copie de travail)
@@ -751,7 +751,7 @@
void uiTemplateReportsBanner(uiLayout *layout, struct bContext *C);
void uiTemplateKeymapItemProperties(uiLayout *layout, struct PointerRNA *ptr);
-void uiTemplateList(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, const char *propname, struct PointerRNA *activeptr, const char *activeprop, int rows, int maxrows, int type);
+void uiTemplateList(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, const char *propname, struct PointerRNA *activeptr, const char *activeprop, const char *enum_ctrls_name, int rows, int maxrows, int type);
/* items */
void uiItemO(uiLayout *layout, const char *name, int icon, const char *opname);
Index: source/blender/editors/interface/interface_templates.c
===================================================================
--- source/blender/editors/interface/interface_templates.c (révision 41176)
+++ source/blender/editors/interface/interface_templates.c (copie de travail)
@@ -2061,8 +2061,7 @@
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 *enum_ctrls_name){
uiBlock *block= uiLayoutGetBlock(layout);
uiBut *but;
uiLayout *split, *overlap, *sub, *row;
@@ -2166,6 +2165,52 @@
/* 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 enum_ctrls_name,
+ * 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 (enum_ctrls_name) {
+ PropertyRNA *enum_ctrls;
+ 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… */
+ enum_ctrls = RNA_struct_find_property(itemptr, enum_ctrls_name);
+ if(enum_ctrls) {
+ if(RNA_property_type(enum_ctrls) == PROP_STRING) {
+ char *prop_names = RNA_property_string_get_alloc(itemptr, enum_ctrls, NULL, 0);
+ char *id = NULL;
+ char *ctx = NULL;
+ for(id = BLI_strtok_r(prop_names, ":", &ctx); id; id = BLI_strtok_r(NULL, ":", &ctx)) {
+ uiItemR(row, itemptr, id, 0, NULL, 0);
+ MEM_freeN(id);
+ }
+ MEM_freeN(prop_names);
+ }
+ }
+ }
+ }
+
else
uiItemL(sub, name, icon); /* fails, backdrop LISTROW... */
@@ -2174,7 +2219,7 @@
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 *enum_ctrls_name, int rows, int maxrows, int listtype)
{
//Scene *scene= CTX_data_scene(C);
PropertyRNA *prop= NULL, *activeprop;
@@ -2328,7 +2373,7 @@
/* 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, enum_ctrls_name);
i++;
}

File Metadata

Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
2c/3e/d8744e11066d905235f4921c847d

Event Timeline