diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-11-02 10:19:11 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-11-02 10:21:59 +0300 |
commit | e32c1bd5d03148b123c8d2664b6164fe5cbd5c12 (patch) | |
tree | e6e425d4a8723c81f70d7e70e2d4e5fc6fe2ab74 /source/blender/editors/interface/interface_layout.c | |
parent | 765e28948e706d8fce97c23d4d050a607971488b (diff) |
UI: use button_operator in operator_menu_hold
Move draw calls into UI_menutype_draw
Diffstat (limited to 'source/blender/editors/interface/interface_layout.c')
-rw-r--r-- | source/blender/editors/interface/interface_layout.c | 58 |
1 files changed, 39 insertions, 19 deletions
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 936b4fd2bba..f0179cb852f 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -882,10 +882,8 @@ static void ui_item_hold_menu(struct bContext *C, ARegion *butregion, uiBut *but const char *menu_id = but->hold_argN; MenuType *mt = WM_menutype_find(menu_id, true); if (mt) { - Menu menu = {NULL}; - menu.layout = layout; - menu.type = mt; - mt->draw(C, &menu); + uiLayoutSetContextFromBut(layout, but); + UI_menutype_draw(C, mt, layout); } else { uiItemL(layout, "Menu Missing:", ICON_NONE); @@ -1860,22 +1858,8 @@ void uiItemPointerR(uiLayout *layout, struct PointerRNA *ptr, const char *propna static void ui_item_menutype_func(bContext *C, uiLayout *layout, void *arg_mt) { MenuType *mt = (MenuType *)arg_mt; - Menu menu = {NULL}; - menu.type = mt; - menu.layout = layout; - - if (G.debug & G_DEBUG_WM) { - printf("%s: opening menu \"%s\"\n", __func__, mt->idname); - } - - if (layout->context) - CTX_store_set(C, layout->context); - - mt->draw(C, &menu); - - if (layout->context) - CTX_store_set(C, NULL); + UI_menutype_draw(C, mt, layout); /* menus are created flipped (from event handling pov) */ layout->root->block->flag ^= UI_BLOCK_IS_FLIP; @@ -3547,6 +3531,20 @@ void uiLayoutContextCopy(uiLayout *layout, bContextStore *context) layout->context = CTX_store_add_all(&block->contexts, context); } +void uiLayoutSetContextFromBut(uiLayout *layout, uiBut *but) +{ + if (but->opptr) { + uiLayoutSetContextPointer(layout, "button_operator", but->opptr); + } + + if (but->rnapoin.data && but->rnaprop) { + /* TODO: index could be supported as well */ + PointerRNA ptr_prop; + RNA_pointer_create(NULL, &RNA_Property, but->rnaprop, &ptr_prop); + uiLayoutSetContextPointer(layout, "button_prop", &ptr_prop); + uiLayoutSetContextPointer(layout, "button_pointer", &but->rnapoin); + } +} /* introspect funcs */ #include "BLI_dynstr.h" @@ -3645,3 +3643,25 @@ MenuType *UI_but_menutype_get(uiBut *but) return NULL; } } + +void UI_menutype_draw(bContext *C, MenuType *mt, struct uiLayout *layout) +{ + Menu menu = { + .layout = layout, + .type = mt, + }; + + if (G.debug & G_DEBUG_WM) { + printf("%s: opening menu \"%s\"\n", __func__, mt->idname); + } + + if (layout->context) { + CTX_store_set(C, layout->context); + } + + mt->draw(C, &menu); + + if (layout->context) { + CTX_store_set(C, NULL); + } +} |