UI: don't show empty button context menu
This commit is contained in:
parent
cd6cb55ff3
commit
84dbf949d7
@ -6837,13 +6837,33 @@ static void ui_but_menu_add_path_operators(uiLayout *layout, PointerRNA *ptr, Pr
|
||||
RNA_string_set(&props_ptr, "filepath", dir);
|
||||
}
|
||||
|
||||
static void ui_but_menu_lazy_init(
|
||||
bContext *C, uiBut *but,
|
||||
uiPopupMenu **pup_p, uiLayout **layout_p)
|
||||
{
|
||||
if (*pup_p != NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
uiStringInfo label = {BUT_GET_LABEL, NULL};
|
||||
|
||||
/* highly unlikely getting the label ever fails */
|
||||
UI_but_string_info_get(C, but, &label, NULL);
|
||||
|
||||
*pup_p = UI_popup_menu_begin(C, label.strinfo ? label.strinfo : "", ICON_NONE);
|
||||
*layout_p = UI_popup_menu_layout(*pup_p);
|
||||
if (label.strinfo) {
|
||||
MEM_freeN(label.strinfo);
|
||||
}
|
||||
uiLayoutSetOperatorContext(*layout_p, WM_OP_INVOKE_DEFAULT);
|
||||
}
|
||||
|
||||
static bool ui_but_menu(bContext *C, uiBut *but)
|
||||
{
|
||||
uiPopupMenu *pup;
|
||||
uiLayout *layout;
|
||||
uiPopupMenu *pup = NULL;
|
||||
uiLayout *layout = NULL;
|
||||
MenuType *mt = WM_menutype_find("WM_MT_button_context", true);
|
||||
bool is_array, is_array_component;
|
||||
uiStringInfo label = {BUT_GET_LABEL, NULL};
|
||||
|
||||
/* if ((but->rnapoin.data && but->rnaprop) == 0 && but->optype == NULL)*/
|
||||
/* return 0;*/
|
||||
@ -6853,17 +6873,9 @@ static bool ui_but_menu(bContext *C, uiBut *but)
|
||||
return false;
|
||||
}
|
||||
|
||||
/* highly unlikely getting the label ever fails */
|
||||
UI_but_string_info_get(C, but, &label, NULL);
|
||||
|
||||
pup = UI_popup_menu_begin(C, label.strinfo ? label.strinfo : "", ICON_NONE);
|
||||
layout = UI_popup_menu_layout(pup);
|
||||
if (label.strinfo)
|
||||
MEM_freeN(label.strinfo);
|
||||
|
||||
uiLayoutSetOperatorContext(layout, WM_OP_INVOKE_DEFAULT);
|
||||
|
||||
if (but->rnapoin.data && but->rnaprop) {
|
||||
ui_but_menu_lazy_init(C, but, &pup, &layout);
|
||||
|
||||
PointerRNA *ptr = &but->rnapoin;
|
||||
PropertyRNA *prop = but->rnaprop;
|
||||
const PropertyType type = RNA_property_type(prop);
|
||||
@ -6873,8 +6885,7 @@ 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 (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)
|
||||
@ -6886,6 +6897,9 @@ static bool ui_but_menu(bContext *C, uiBut *but)
|
||||
|
||||
/* Keyframes */
|
||||
if (but->flag & UI_BUT_ANIMATED_KEY) {
|
||||
/* Set the (button_pointer, button_prop) and pointer data for Python access to the hovered ui element. */
|
||||
uiLayoutSetContextFromBut(layout, but);
|
||||
|
||||
/* replace/delete keyfraemes */
|
||||
if (is_array_component) {
|
||||
uiItemBooleanO(layout, CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Replace Keyframes"),
|
||||
@ -7060,6 +7074,8 @@ static bool ui_but_menu(bContext *C, uiBut *but)
|
||||
|
||||
/* We do have a shortcut, but only keyboard ones are editbale that way... */
|
||||
if (kmi) {
|
||||
ui_but_menu_lazy_init(C, but, &pup, &layout);
|
||||
|
||||
if (ISKEYBOARD(kmi->type)) {
|
||||
#if 0 /* would rather use a block but, but gets weirdly positioned... */
|
||||
uiDefBlockBut(block, menu_change_shortcut, but, "Change Shortcut",
|
||||
@ -7086,6 +7102,8 @@ static bool ui_but_menu(bContext *C, uiBut *but)
|
||||
}
|
||||
/* only show 'add' if there's a suitable key map for it to go in */
|
||||
else if (WM_keymap_guess_opname(C, but->optype->idname)) {
|
||||
ui_but_menu_lazy_init(C, but, &pup, &layout);
|
||||
|
||||
but2 = uiDefIconTextBut(block, UI_BTYPE_BUT, 0, ICON_HAND,
|
||||
CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Add Shortcut"),
|
||||
0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
|
||||
@ -7102,6 +7120,7 @@ static bool ui_but_menu(bContext *C, uiBut *but)
|
||||
if (ui_block_is_menu(but->block) == false) {
|
||||
ARegion *ar = CTX_wm_region(C);
|
||||
if (ar && (ar->regiontype == RGN_TYPE_HEADER)) {
|
||||
ui_but_menu_lazy_init(C, but, &pup, &layout);
|
||||
uiItemMenuF(layout, IFACE_("Header"), ICON_NONE, ED_screens_header_tools_menu_create, NULL);
|
||||
uiItemS(layout);
|
||||
}
|
||||
@ -7111,6 +7130,8 @@ static bool ui_but_menu(bContext *C, uiBut *but)
|
||||
char buf[512];
|
||||
|
||||
if (UI_but_online_manual_id(but, buf, sizeof(buf))) {
|
||||
ui_but_menu_lazy_init(C, but, &pup, &layout);
|
||||
|
||||
PointerRNA ptr_props;
|
||||
uiItemO(layout, CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Online Manual"),
|
||||
ICON_URL, "WM_OT_doc_view_manual_ui_context");
|
||||
@ -7133,6 +7154,7 @@ static bool ui_but_menu(bContext *C, uiBut *but)
|
||||
}
|
||||
|
||||
if (but->optype) {
|
||||
ui_but_menu_lazy_init(C, but, &pup, &layout);
|
||||
uiItemO(layout, NULL,
|
||||
ICON_NONE, "UI_OT_copy_python_command_button");
|
||||
}
|
||||
@ -7140,22 +7162,27 @@ static bool ui_but_menu(bContext *C, uiBut *but)
|
||||
/* perhaps we should move this into (G.debug & G_DEBUG) - campbell */
|
||||
if (U.flag & USER_DEVELOPER_UI) {
|
||||
if (ui_block_is_menu(but->block) == false) {
|
||||
ui_but_menu_lazy_init(C, but, &pup, &layout);
|
||||
uiItemFullO(layout, "UI_OT_editsource", NULL, ICON_NONE, NULL, WM_OP_INVOKE_DEFAULT, 0, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
if (BKE_addon_find(&U.addons, "ui_translate")) {
|
||||
ui_but_menu_lazy_init(C, but, &pup, &layout);
|
||||
uiItemFullO(layout, "UI_OT_edittranslation_init", NULL, ICON_NONE, NULL, WM_OP_INVOKE_DEFAULT, 0, NULL);
|
||||
}
|
||||
|
||||
mt = WM_menutype_find("WM_MT_button_context", true);
|
||||
if (mt) {
|
||||
ui_but_menu_lazy_init(C, but, &pup, &layout);
|
||||
UI_menutype_draw(C, mt, uiLayoutColumn(layout, false));
|
||||
}
|
||||
|
||||
if (pup != NULL) {
|
||||
UI_popup_menu_end(C, pup);
|
||||
}
|
||||
|
||||
return true;
|
||||
return (pup != NULL);
|
||||
}
|
||||
|
||||
static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent *event)
|
||||
|
Loading…
Reference in New Issue
Block a user