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:
authorJulian Eisel <julian@blender.org>2021-06-29 18:20:33 +0300
committerJulian Eisel <julian@blender.org>2021-06-29 19:20:56 +0300
commit2ff714269e53f9a744242cd6c039ec65a47ec7ec (patch)
tree9c045b9cf56f50a86b7af87bc56a5495813f2e70 /source/blender/editors/interface/interface_layout.c
parent63aa6dd845ebdb0f62c95a720e82e554c0208d95 (diff)
UI: Support setting operator properties for `UILayout.operator_menu_enum()`
`UILayout.operator_menu_enum()` now returns the operator properties, just like `UILayout.operator()`. This makes it possible to set options for the operator displayed in the menu. In C it can be done through the new `uiItemMenuEnumFullO()` or `uiItemMenuEnumFullO_ptr()`. It's reasonable to have this, probably just a small thing never bothered to add. D10912 could use it, the following comment can be addressed now too: https://developer.blender.org/diffusion/B/browse/master/source/blender/editors/space_nla/nla_buttons.c$583-586
Diffstat (limited to 'source/blender/editors/interface/interface_layout.c')
-rw-r--r--source/blender/editors/interface/interface_layout.c54
1 files changed, 39 insertions, 15 deletions
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index cf3abc9be4a..a17a527c868 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -3381,10 +3381,13 @@ typedef struct MenuItemLevel {
static void menu_item_enum_opname_menu(bContext *UNUSED(C), uiLayout *layout, void *arg)
{
- MenuItemLevel *lvl = (MenuItemLevel *)(((uiBut *)arg)->func_argN);
+ uiBut *but = arg;
+ MenuItemLevel *lvl = but->func_argN;
+ /* Use the operator properties from the button owning the menu. */
+ IDProperty *op_props = but->opptr ? but->opptr->data : NULL;
uiLayoutSetOperatorContext(layout, lvl->opcontext);
- uiItemsEnumO(layout, lvl->opname, lvl->propname);
+ uiItemsFullEnumO(layout, lvl->opname, lvl->propname, op_props, lvl->opcontext, 0);
layout->root->block->flag |= UI_BLOCK_IS_FLIP;
@@ -3392,12 +3395,13 @@ static void menu_item_enum_opname_menu(bContext *UNUSED(C), uiLayout *layout, vo
UI_block_direction_set(layout->root->block, UI_DIR_DOWN);
}
-void uiItemMenuEnumO_ptr(uiLayout *layout,
- bContext *C,
- wmOperatorType *ot,
- const char *propname,
- const char *name,
- int icon)
+void uiItemMenuEnumFullO_ptr(uiLayout *layout,
+ bContext *C,
+ wmOperatorType *ot,
+ const char *propname,
+ const char *name,
+ int icon,
+ PointerRNA *r_opptr)
{
/* Caller must check */
BLI_assert(ot->srna != NULL);
@@ -3416,6 +3420,15 @@ void uiItemMenuEnumO_ptr(uiLayout *layout,
lvl->opcontext = layout->root->opcontext;
uiBut *but = ui_item_menu(layout, name, icon, menu_item_enum_opname_menu, NULL, lvl, NULL, true);
+ /* Use the menu button as owner for the operator properties, which will then be passed to the
+ * individual menu items. */
+ if (r_opptr) {
+ but->opptr = MEM_callocN(sizeof(PointerRNA), "uiButOpPtr");
+ WM_operator_properties_create_ptr(but->opptr, ot);
+ BLI_assert(but->opptr->data == NULL);
+ WM_operator_properties_alloc(&but->opptr, (IDProperty **)&but->opptr->data, ot->idname);
+ *r_opptr = *but->opptr;
+ }
/* add hotkey here, lower UI code can't detect it */
if ((layout->root->block->flag & UI_BLOCK_LOOP) && (ot->prop && ot->invoke)) {
@@ -3427,12 +3440,13 @@ void uiItemMenuEnumO_ptr(uiLayout *layout,
}
}
-void uiItemMenuEnumO(uiLayout *layout,
- bContext *C,
- const char *opname,
- const char *propname,
- const char *name,
- int icon)
+void uiItemMenuEnumFullO(uiLayout *layout,
+ bContext *C,
+ const char *opname,
+ const char *propname,
+ const char *name,
+ int icon,
+ PointerRNA *r_opptr)
{
wmOperatorType *ot = WM_operatortype_find(opname, 0); /* print error next */
@@ -3444,7 +3458,17 @@ void uiItemMenuEnumO(uiLayout *layout,
return;
}
- uiItemMenuEnumO_ptr(layout, C, ot, propname, name, icon);
+ uiItemMenuEnumFullO_ptr(layout, C, ot, propname, name, icon, r_opptr);
+}
+
+void uiItemMenuEnumO(uiLayout *layout,
+ bContext *C,
+ const char *opname,
+ const char *propname,
+ const char *name,
+ int icon)
+{
+ uiItemMenuEnumFullO(layout, C, opname, propname, name, icon, NULL);
}
static void menu_item_enum_rna_menu(bContext *UNUSED(C), uiLayout *layout, void *arg)