RNA
* Enums can now be dynamically created in the _itemf callback, using RNA_enum_item(s)_add, RNA_enum_item_end. All places asking for enum items now need to potentially free the items. * This callback now also gets context, this was added specifically for operators. This doesn't fit design well at all, needed to do some ugly hacks, but can't find a good solution at the moment. * All enums must have a default list of items too, even with an _itemf callback, for docs and fallback in case there is no context. * Used by MESH_OT_merge, MESH_OT_select_similar, TFM_OT_select_orientation. * Also changes some operator properties that were enums to booleas (unselected, deselect), to make them consistent with other ops.
This commit is contained in:
@@ -1615,6 +1615,7 @@ uiBlock *uiBeginBlock(const bContext *C, ARegion *region, const char *name, shor
|
||||
block= MEM_callocN(sizeof(uiBlock), "uiBlock");
|
||||
block->active= 1;
|
||||
block->dt= dt;
|
||||
block->evil_C= C; // XXX
|
||||
BLI_strncpy(block->name, name, sizeof(block->name));
|
||||
|
||||
if(region)
|
||||
@@ -2113,11 +2114,11 @@ uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, char *str, short x1,
|
||||
/* use rna values if parameters are not specified */
|
||||
if(!str) {
|
||||
if(type == MENU && proptype == PROP_ENUM) {
|
||||
const EnumPropertyItem *item;
|
||||
EnumPropertyItem *item;
|
||||
DynStr *dynstr;
|
||||
int i, totitem, value;
|
||||
int i, totitem, value, free;
|
||||
|
||||
RNA_property_enum_items(ptr, prop, &item, &totitem);
|
||||
RNA_property_enum_items(block->evil_C, ptr, prop, &item, &totitem, &free);
|
||||
value= RNA_property_enum_get(ptr, prop);
|
||||
|
||||
dynstr= BLI_dynstr_new();
|
||||
@@ -2136,13 +2137,16 @@ uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, char *str, short x1,
|
||||
str= BLI_dynstr_get_cstring(dynstr);
|
||||
BLI_dynstr_free(dynstr);
|
||||
|
||||
if(free)
|
||||
MEM_freeN(item);
|
||||
|
||||
freestr= 1;
|
||||
}
|
||||
else if(type == ROW && proptype == PROP_ENUM) {
|
||||
const EnumPropertyItem *item;
|
||||
int i, totitem;
|
||||
EnumPropertyItem *item;
|
||||
int i, totitem, free;
|
||||
|
||||
RNA_property_enum_items(ptr, prop, &item, &totitem);
|
||||
RNA_property_enum_items(block->evil_C, ptr, prop, &item, &totitem, &free);
|
||||
for(i=0; i<totitem; i++) {
|
||||
if(item[i].identifier[0] && item[i].value == (int)max) {
|
||||
str= (char*)item[i].name;
|
||||
@@ -2152,6 +2156,8 @@ uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, char *str, short x1,
|
||||
|
||||
if(!str)
|
||||
str= (char*)RNA_property_ui_name(prop);
|
||||
if(free)
|
||||
MEM_freeN(item);
|
||||
}
|
||||
else {
|
||||
str= (char*)RNA_property_ui_name(prop);
|
||||
@@ -2161,10 +2167,10 @@ uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, char *str, short x1,
|
||||
|
||||
if(!tip) {
|
||||
if(type == ROW && proptype == PROP_ENUM) {
|
||||
const EnumPropertyItem *item;
|
||||
int i, totitem;
|
||||
EnumPropertyItem *item;
|
||||
int i, totitem, free;
|
||||
|
||||
RNA_property_enum_items(ptr, prop, &item, &totitem);
|
||||
RNA_property_enum_items(block->evil_C, ptr, prop, &item, &totitem, &free);
|
||||
|
||||
for(i=0; i<totitem; i++) {
|
||||
if(item[i].identifier[0] && item[i].value == (int)max) {
|
||||
@@ -2173,6 +2179,9 @@ uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, char *str, short x1,
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(free)
|
||||
MEM_freeN(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user