UI: use button_operator in operator_menu_hold

Move draw calls into UI_menutype_draw
This commit is contained in:
Campbell Barton 2017-11-02 18:19:11 +11:00
parent 765e28948e
commit e32c1bd5d0
Notes: blender-bot 2023-02-14 07:40:56 +01:00
Referenced by issue #53231, building Blender 2.79 from source currently fails on Windows
5 changed files with 51 additions and 57 deletions

View File

@ -872,6 +872,10 @@ void uiLayoutSetContextPointer(uiLayout *layout, const char *name, struct Pointe
void uiLayoutContextCopy(uiLayout *layout, struct bContextStore *context);
const char *uiLayoutIntrospect(uiLayout *layout); // XXX - testing
struct MenuType *UI_but_menutype_get(uiBut *but);
void UI_menutype_draw(struct bContext *C, struct MenuType *mt, struct uiLayout *layout);
/* Only for convenience. */
void uiLayoutSetContextFromBut(uiLayout *layout, uiBut *but);
void uiLayoutSetOperatorContext(uiLayout *layout, int opcontext);
void uiLayoutSetActive(uiLayout *layout, bool active);

View File

@ -6789,11 +6789,8 @@ static bool ui_but_menu(bContext *C, uiBut *but)
/*bool is_idprop = RNA_property_is_idprop(prop);*/ /* XXX does not work as expected, not strictly needed */
bool is_set = RNA_property_is_set(ptr, prop);
/* set the prop and pointer data for python access to the hovered ui element; TODO, index could be supported as well*/
PointerRNA temp_ptr;
RNA_pointer_create(NULL, &RNA_Property, but->rnaprop, &temp_ptr);
uiLayoutSetContextPointer(layout, "button_prop", &temp_ptr);
uiLayoutSetContextPointer(layout, "button_pointer", ptr);
/* Set the (button_pointer, button_prop) and pointer data for Python access to the hovered ui element. */
uiLayoutSetContextFromBut(layout, but);
/* second slower test, saved people finding keyframe items in menus when its not possible */
if (is_anim)
@ -7012,9 +7009,7 @@ static bool ui_but_menu(bContext *C, uiBut *but)
}
/* Set the operator pointer for python access */
if (but->opptr) {
uiLayoutSetContextPointer(layout, "button_operator", but->opptr);
}
uiLayoutSetContextFromBut(layout, but);
uiItemS(layout);
}
@ -7066,10 +7061,7 @@ static bool ui_but_menu(bContext *C, uiBut *but)
mt = WM_menutype_find("WM_MT_button_context", true);
if (mt) {
Menu menu = {NULL};
menu.layout = uiLayoutColumn(layout, false);
menu.type = mt;
mt->draw(C, &menu);
UI_menutype_draw(C, mt, uiLayoutColumn(layout, false));
}
UI_popup_menu_end(C, pup);

View File

@ -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);
}
}

View File

@ -3050,7 +3050,6 @@ int UI_pie_menu_invoke(struct bContext *C, const char *idname, const wmEvent *ev
{
uiPieMenu *pie;
uiLayout *layout;
Menu menu;
MenuType *mt = WM_menutype_find(idname, true);
if (mt == NULL) {
@ -3065,14 +3064,7 @@ int UI_pie_menu_invoke(struct bContext *C, const char *idname, const wmEvent *ev
pie = UI_pie_menu_begin(C, IFACE_(mt->label), ICON_NONE, event);
layout = UI_pie_menu_layout(pie);
menu.layout = layout;
menu.type = mt;
if (G.debug & G_DEBUG_WM) {
printf("%s: opening menu \"%s\"\n", __func__, idname);
}
mt->draw(C, &menu);
UI_menutype_draw(C, mt, layout);
UI_pie_menu_end(C, pie);
@ -3283,7 +3275,6 @@ int UI_popup_menu_invoke(bContext *C, const char *idname, ReportList *reports)
{
uiPopupMenu *pup;
uiLayout *layout;
Menu menu;
MenuType *mt = WM_menutype_find(idname, true);
if (mt == NULL) {
@ -3298,14 +3289,7 @@ int UI_popup_menu_invoke(bContext *C, const char *idname, ReportList *reports)
pup = UI_popup_menu_begin(C, IFACE_(mt->label), ICON_NONE);
layout = UI_popup_menu_layout(pup);
menu.layout = layout;
menu.type = mt;
if (G.debug & G_DEBUG_WM) {
printf("%s: opening menu \"%s\"\n", __func__, idname);
}
mt->draw(C, &menu);
UI_menutype_draw(C, mt, layout);
UI_popup_menu_end(C, pup);

View File

@ -1892,10 +1892,7 @@ static uiBlock *wm_block_create_splash(bContext *C, ARegion *ar, void *UNUSED(ar
UI_block_emboss_set(block, UI_EMBOSS);
/* show the splash menu (containing interaction presets), using python */
if (mt) {
Menu menu = {NULL};
menu.layout = layout;
menu.type = mt;
mt->draw(C, &menu);
UI_menutype_draw(C, mt, layout);
// wmWindowManager *wm = CTX_wm_manager(C);
// uiItemM(layout, C, "USERPREF_MT_keyconfigs", U.keyconfigstr, ICON_NONE);
@ -1952,10 +1949,7 @@ static uiBlock *wm_block_create_splash(bContext *C, ARegion *ar, void *UNUSED(ar
mt = WM_menutype_find("USERPREF_MT_splash_footer", false);
if (mt) {
Menu menu = {NULL};
menu.layout = uiLayoutColumn(layout, false);
menu.type = mt;
mt->draw(C, &menu);
UI_menutype_draw(C, mt, uiLayoutColumn(layout, false));
}
UI_block_bounds_set_centered(block, 0);