diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-06-23 17:31:28 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-06-23 21:52:47 +0300 |
commit | 85c1e61375532e91d5fc37b1d754cf76c17f7721 (patch) | |
tree | 459ed56b972e108036dc1c7e097003f2b234fdd7 /source/blender/editors/interface | |
parent | 2fa231a86b4179ed513da2469df877497b346162 (diff) |
UI: Add user defined context menu
- Add/Remove from RMB context menu.
- Stored in user preferences.
- Access from Q key.
See T55027.
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index cb37c301031..6f3bbc5ab36 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -6649,6 +6649,30 @@ static void popup_add_shortcut_func(bContext *C, void *arg1, void *UNUSED(arg2)) UI_popup_block_ex(C, menu_add_shortcut, NULL, menu_add_shortcut_cancel, but, NULL); } +static void popup_user_menu_add_or_replace_func(bContext *C, void *arg1, void *arg2) +{ + uiBut *but = arg1; + bUserMenuItem *umi = arg2; + if (umi) { + ED_screen_user_menu_remove(umi); + } + char drawstr[sizeof(but->drawstr)]; + STRNCPY(drawstr, but->drawstr); + if (but->flag & UI_BUT_HAS_SEP_CHAR) { + char *sep = strrchr(drawstr, UI_SEP_CHAR); + if (sep) { + *sep = '\0'; + } + } + ED_screen_user_menu_add(C, drawstr, but->optype, but->opptr ? but->opptr->data : NULL, but->opcontext); +} + +static void popup_user_menu_remove_func(bContext *UNUSED(C), void *UNUSED(arg1), void *arg2) +{ + bUserMenuItem *umi = arg2; + ED_screen_user_menu_remove(umi); +} + /** * menu to chow when right clicking on the panel header */ @@ -7021,6 +7045,27 @@ static bool ui_but_menu(bContext *C, uiBut *but) UI_but_func_set(but2, popup_add_shortcut_func, but, NULL); } + uiItemS(layout); + + { + bUserMenuItem *umi = ED_screen_user_menu_find( + C, but->optype, but->opptr ? but->opptr->data : NULL, but->opcontext); + + but2 = uiDefIconTextBut( + block, UI_BTYPE_BUT, 0, ICON_MENU_PANEL, + CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Add to Favourites Menu"), + 0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, + "Add to a user defined context menu (stored in the user preferences)"); + UI_but_func_set(but2, popup_user_menu_add_or_replace_func, but, umi); + if (umi) { + but2 = uiDefIconTextBut( + block, UI_BTYPE_BUT, 0, ICON_CANCEL, + CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Remove from Favourites Menu"), + 0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, ""); + UI_but_func_set(but2, popup_user_menu_remove_func, NULL, umi); + } + } + /* Set the operator pointer for python access */ uiLayoutSetContextFromBut(layout, but); |