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:
@@ -429,13 +429,13 @@ static void ui_item_array(uiLayout *layout, uiBlock *block, char *name, int icon
|
||||
|
||||
static void ui_item_enum_row(uiLayout *layout, uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, char *uiname, int x, int y, int w, int h)
|
||||
{
|
||||
const EnumPropertyItem *item;
|
||||
EnumPropertyItem *item;
|
||||
const char *identifier;
|
||||
char *name;
|
||||
int a, totitem, itemw, icon, value;
|
||||
int a, totitem, itemw, icon, value, free;
|
||||
|
||||
identifier= RNA_property_identifier(prop);
|
||||
RNA_property_enum_items(ptr, prop, &item, &totitem);
|
||||
RNA_property_enum_items(block->evil_C, ptr, prop, &item, &totitem, &free);
|
||||
|
||||
uiBlockSetCurLayout(block, ui_item_local_sublayout(layout, layout, 1));
|
||||
for(a=0; a<totitem; a++) {
|
||||
@@ -455,6 +455,9 @@ static void ui_item_enum_row(uiLayout *layout, uiBlock *block, PointerRNA *ptr,
|
||||
uiDefButR(block, ROW, 0, name, 0, 0, itemw, h, ptr, identifier, -1, 0, value, -1, -1, NULL);
|
||||
}
|
||||
uiBlockSetCurLayout(block, layout);
|
||||
|
||||
if(free)
|
||||
MEM_freeN(item);
|
||||
}
|
||||
|
||||
/* create label + button for RNA property */
|
||||
@@ -545,7 +548,7 @@ void uiItemFullO(uiLayout *layout, char *name, int icon, char *idname, IDPropert
|
||||
}
|
||||
}
|
||||
|
||||
static char *ui_menu_enumpropname(char *opname, char *propname, int retval)
|
||||
static char *ui_menu_enumpropname(uiLayout *layout, char *opname, char *propname, int retval)
|
||||
{
|
||||
wmOperatorType *ot= WM_operatortype_find(opname);
|
||||
PointerRNA ptr;
|
||||
@@ -558,13 +561,18 @@ static char *ui_menu_enumpropname(char *opname, char *propname, int retval)
|
||||
prop= RNA_struct_find_property(&ptr, propname);
|
||||
|
||||
if(prop) {
|
||||
const EnumPropertyItem *item;
|
||||
int totitem;
|
||||
EnumPropertyItem *item;
|
||||
int totitem, free;
|
||||
const char *name;
|
||||
|
||||
RNA_property_enum_items(&ptr, prop, &item, &totitem);
|
||||
if(RNA_enum_name(item, retval, &name))
|
||||
RNA_property_enum_items(layout->root->block->evil_C, &ptr, prop, &item, &totitem, &free);
|
||||
if(RNA_enum_name(item, retval, &name)) {
|
||||
if(free) MEM_freeN(item);
|
||||
return (char*)name;
|
||||
}
|
||||
|
||||
if(free)
|
||||
MEM_freeN(item);
|
||||
}
|
||||
|
||||
return "";
|
||||
@@ -578,7 +586,7 @@ void uiItemEnumO(uiLayout *layout, char *name, int icon, char *opname, char *pro
|
||||
RNA_enum_set(&ptr, propname, value);
|
||||
|
||||
if(!name)
|
||||
name= ui_menu_enumpropname(opname, propname, value);
|
||||
name= ui_menu_enumpropname(layout, opname, propname, value);
|
||||
|
||||
uiItemFullO(layout, name, icon, opname, ptr.data, layout->root->opcontext);
|
||||
}
|
||||
@@ -598,16 +606,19 @@ void uiItemsEnumO(uiLayout *layout, char *opname, char *propname)
|
||||
prop= RNA_struct_find_property(&ptr, propname);
|
||||
|
||||
if(prop && RNA_property_type(prop) == PROP_ENUM) {
|
||||
const EnumPropertyItem *item;
|
||||
int totitem, i;
|
||||
EnumPropertyItem *item;
|
||||
int totitem, i, free;
|
||||
|
||||
RNA_property_enum_items(&ptr, prop, &item, &totitem);
|
||||
RNA_property_enum_items(layout->root->block->evil_C, &ptr, prop, &item, &totitem, &free);
|
||||
|
||||
for(i=0; i<totitem; i++)
|
||||
if(item[i].identifier[0])
|
||||
uiItemEnumO(layout, (char*)item[i].name, item[i].icon, opname, propname, item[i].value);
|
||||
else
|
||||
uiItemS(layout);
|
||||
|
||||
if(free)
|
||||
MEM_freeN(item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -618,18 +629,22 @@ void uiItemEnumO_string(uiLayout *layout, char *name, int icon, char *opname, ch
|
||||
|
||||
/* for getting the enum */
|
||||
PropertyRNA *prop;
|
||||
const EnumPropertyItem *item;
|
||||
int value;
|
||||
EnumPropertyItem *item;
|
||||
int value, free;
|
||||
|
||||
WM_operator_properties_create(&ptr, opname);
|
||||
|
||||
/* enum lookup */
|
||||
if((prop= RNA_struct_find_property(&ptr, propname))) {
|
||||
RNA_property_enum_items(&ptr, prop, &item, NULL);
|
||||
RNA_property_enum_items(layout->root->block->evil_C, &ptr, prop, &item, NULL, &free);
|
||||
if(RNA_enum_value_from_id(item, value_str, &value)==0) {
|
||||
if(free) MEM_freeN(item);
|
||||
printf("uiItemEnumO_string: %s.%s, enum %s not found.\n", RNA_struct_identifier(ptr.type), propname, value_str);
|
||||
return;
|
||||
}
|
||||
|
||||
if(free)
|
||||
MEM_freeN(item);
|
||||
}
|
||||
else {
|
||||
printf("uiItemEnumO_string: %s.%s not found.\n", RNA_struct_identifier(ptr.type), propname);
|
||||
@@ -640,7 +655,7 @@ void uiItemEnumO_string(uiLayout *layout, char *name, int icon, char *opname, ch
|
||||
|
||||
/* same as uiItemEnumO */
|
||||
if(!name)
|
||||
name= ui_menu_enumpropname(opname, propname, value);
|
||||
name= ui_menu_enumpropname(layout, opname, propname, value);
|
||||
|
||||
uiItemFullO(layout, name, icon, opname, ptr.data, layout->root->opcontext);
|
||||
}
|
||||
@@ -845,8 +860,8 @@ void uiItemEnumR(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr,
|
||||
void uiItemEnumR_string(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, char *propname, char *value)
|
||||
{
|
||||
PropertyRNA *prop;
|
||||
const EnumPropertyItem *item;
|
||||
int ivalue, a;
|
||||
EnumPropertyItem *item;
|
||||
int ivalue, a, free;
|
||||
|
||||
if(!ptr->data || !propname)
|
||||
return;
|
||||
@@ -859,9 +874,10 @@ void uiItemEnumR_string(uiLayout *layout, char *name, int icon, struct PointerRN
|
||||
return;
|
||||
}
|
||||
|
||||
RNA_property_enum_items(ptr, prop, &item, NULL);
|
||||
RNA_property_enum_items(layout->root->block->evil_C, ptr, prop, &item, NULL, &free);
|
||||
|
||||
if(!RNA_enum_value_from_id(item, value, &ivalue)) {
|
||||
if(free) MEM_freeN(item);
|
||||
ui_item_disabled(layout, propname);
|
||||
printf("uiItemEnumR: enum property value not found: %s\n", value);
|
||||
return;
|
||||
@@ -873,6 +889,9 @@ void uiItemEnumR_string(uiLayout *layout, char *name, int icon, struct PointerRN
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(free)
|
||||
MEM_freeN(item);
|
||||
}
|
||||
|
||||
void uiItemsEnumR(uiLayout *layout, struct PointerRNA *ptr, char *propname)
|
||||
@@ -887,16 +906,19 @@ void uiItemsEnumR(uiLayout *layout, struct PointerRNA *ptr, char *propname)
|
||||
}
|
||||
|
||||
if(RNA_property_type(prop) == PROP_ENUM) {
|
||||
const EnumPropertyItem *item;
|
||||
int totitem, i;
|
||||
EnumPropertyItem *item;
|
||||
int totitem, i, free;
|
||||
|
||||
RNA_property_enum_items(ptr, prop, &item, &totitem);
|
||||
RNA_property_enum_items(layout->root->block->evil_C, ptr, prop, &item, &totitem, &free);
|
||||
|
||||
for(i=0; i<totitem; i++)
|
||||
if(item[i].identifier[0])
|
||||
uiItemEnumR(layout, (char*)item[i].name, 0, ptr, propname, item[i].value);
|
||||
else
|
||||
uiItemS(layout);
|
||||
|
||||
if(free)
|
||||
MEM_freeN(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user