diff options
author | Ton Roosendaal <ton@blender.org> | 2008-12-24 21:06:51 +0300 |
---|---|---|
committer | Ton Roosendaal <ton@blender.org> | 2008-12-24 21:06:51 +0300 |
commit | febb2c21e4fce4fbbbcc30bbab295b745920a062 (patch) | |
tree | d97d6653a737718bebe80af64066e3bc17b5d449 /source/blender/windowmanager/intern | |
parent | 3c612bc0e237c48bc8a3f6fdc20cec4a3b140228 (diff) |
2.5
Further simplifying making operators with menus;
now you can add an 'invoke' callback:
WM_menu_invoke
which will automatically generate a menu with choices and assign
it to the property 'type'.
What also helps typing is the new RNA_enum_is_equal() function.
Here's a paste of the now committed 'clear parent'. Note the
undo push will become a flag too.
http://pasteall.org/3660
(Brecht; fixed small bug in RNA_enum_is_equal!)
To evaluate: solving dependencies for multipe scenes... probably
will make a more generic flush call.
Diffstat (limited to 'source/blender/windowmanager/intern')
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index b8b7f8fadaa..a446ddb9e82 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -97,13 +97,33 @@ void WM_operatortype_append(void (*opfunc)(wmOperatorType*)) /* ************ default op callbacks, exported *********** */ -static void operator_callback(bContext *C, void *arg, int retval) +/* invoke callback, uses enum property named "type" */ +/* only weak thing is the fixed property name... */ +int WM_menu_invoke(bContext *C, wmOperator *op, wmEvent *event) { - wmOperator *op= arg; - - if(op && retval > 0) - op->type->exec(C, op); - + PropertyRNA *prop= RNA_struct_find_property(op->ptr, "type"); + const EnumPropertyItem *item; + int totitem, i, len= strlen(op->type->name) + 5; + char *menu, *p; + + if(prop) { + RNA_property_enum_items(op->ptr, prop, &item, &totitem); + + for (i=0; i<totitem; i++) + len+= strlen(item[i].name) + 5; + + menu= MEM_callocN(len, "string"); + + p= menu + sprintf(menu, "%s %%t", op->type->name); + for (i=0; i<totitem; i++) + p+= sprintf(p, "|%s %%x%d", item[i].name, item[i].value); + + uiPupmenuOperator(C, totitem/30, op, "type", menu); + MEM_freeN(menu); + + return OPERATOR_RUNNING_MODAL; + } + return OPERATOR_CANCELLED; } /* call anywhere */ @@ -113,7 +133,7 @@ void WM_error(bContext *C, char *str) BLI_strncpy(testbuf, str, 128); sprintf(buf, "Error %%i%d%%t|%s", ICON_ERROR, testbuf); - uiPupmenu(C, 0, operator_callback, NULL, buf); + uiPupmenu(C, 0, NULL, NULL, buf); } |