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:
authorCampbell Barton <ideasman42@gmail.com>2018-06-30 13:08:08 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-06-30 13:08:08 +0300
commit41176cd3d820649488ec5a5475d5dc7e97a01a59 (patch)
tree31d8df071e656f1b629eefc4281c74d28ec2d639 /source/blender/editors/interface/interface_context_menu.c
parent62ff53ff19e36da0203915d04fc0ce295002f173 (diff)
UI: support adding menu's to favourites
Diffstat (limited to 'source/blender/editors/interface/interface_context_menu.c')
-rw-r--r--source/blender/editors/interface/interface_context_menu.c98
1 files changed, 69 insertions, 29 deletions
diff --git a/source/blender/editors/interface/interface_context_menu.c b/source/blender/editors/interface/interface_context_menu.c
index f28d80bebe1..d425ba1f985 100644
--- a/source/blender/editors/interface/interface_context_menu.c
+++ b/source/blender/editors/interface/interface_context_menu.c
@@ -216,10 +216,31 @@ 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 *UNUSED(arg2))
+static bool ui_but_is_user_menu_compatible(uiBut *but)
{
- uiBut *but = arg1;
- bUserMenu *um = ED_screen_user_menu_ensure(C);
+ return (but->optype || UI_but_menutype_get(but));
+}
+
+static bUserMenuItem *ui_but_user_menu_find(uiBut *but, bUserMenu *um)
+{
+ MenuType *mt = NULL;
+ if (but->optype) {
+ IDProperty *prop = (but->opptr) ? but->opptr->data : NULL;
+ return (bUserMenuItem *)ED_screen_user_menu_item_find_operator(
+ &um->items, but->optype, prop, but->opcontext);
+ }
+ else if ((mt = UI_but_menutype_get(but))) {
+ return (bUserMenuItem *)ED_screen_user_menu_item_find_menu(
+ &um->items, mt);
+ }
+ else {
+ return NULL;
+ }
+}
+
+static void ui_but_user_menu_add(uiBut *but, bUserMenu *um)
+{
+ BLI_assert(ui_but_is_user_menu_compatible(but));
char drawstr[sizeof(but->drawstr)];
STRNCPY(drawstr, but->drawstr);
@@ -229,9 +250,25 @@ static void popup_user_menu_add_or_replace_func(bContext *C, void *arg1, void *U
*sep = '\0';
}
}
- ED_screen_user_menu_item_add_operator(
- &um->items, drawstr,
- but->optype, but->opptr ? but->opptr->data : NULL, but->opcontext);
+
+ MenuType *mt = NULL;
+ if (but->optype) {
+ ED_screen_user_menu_item_add_operator(
+ &um->items, drawstr,
+ but->optype, but->opptr ? but->opptr->data : NULL, but->opcontext);
+ }
+ else if ((mt = UI_but_menutype_get(but))) {
+ ED_screen_user_menu_item_add_menu(
+ &um->items, drawstr,
+ mt);
+ }
+}
+
+static void popup_user_menu_add_or_replace_func(bContext *C, void *arg1, void *UNUSED(arg2))
+{
+ uiBut *but = arg1;
+ bUserMenu *um = ED_screen_user_menu_ensure(C);
+ ui_but_user_menu_add(but, um);
}
static void popup_user_menu_remove_func(bContext *UNUSED(C), void *arg1, void *arg2)
@@ -614,33 +651,36 @@ bool ui_popup_context_menu_for_button(bContext *C, uiBut *but)
UI_but_func_set(but2, popup_add_shortcut_func, but, NULL);
}
+ /* Set the operator pointer for python access */
+ uiLayoutSetContextFromBut(layout, but);
+
uiItemS(layout);
+ }
- {
- but2 = uiDefIconTextBut(
- block, UI_BTYPE_BUT, 0, ICON_MENU_PANEL,
- CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Add to Favorites 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, NULL);
-
- bUserMenu *um = ED_screen_user_menu_find(C);
- if (um) {
- bUserMenuItem_Op *umi_op = ED_screen_user_menu_item_find_operator(
- &um->items, but->optype, prop, but->opcontext);
- if (umi_op != NULL) {
- but2 = uiDefIconTextBut(
- block, UI_BTYPE_BUT, 0, ICON_CANCEL,
- CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Remove from Favorites Menu"),
- 0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
- UI_but_func_set(but2, popup_user_menu_remove_func, um, umi_op);
- }
+ /* Favorites Menu */
+ if (ui_but_is_user_menu_compatible(but)) {
+ uiBlock *block = uiLayoutGetBlock(layout);
+ const int w = uiLayoutGetWidth(layout);
+ uiBut *but2;
+
+ but2 = uiDefIconTextBut(
+ block, UI_BTYPE_BUT, 0, ICON_MENU_PANEL,
+ CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Add to Favorites 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, NULL);
+
+ bUserMenu *um = ED_screen_user_menu_find(C);
+ if (um) {
+ bUserMenuItem *umi = ui_but_user_menu_find(but, um);
+ if (umi != NULL) {
+ but2 = uiDefIconTextBut(
+ block, UI_BTYPE_BUT, 0, ICON_CANCEL,
+ CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Remove from Favorites Menu"),
+ 0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
+ UI_but_func_set(but2, popup_user_menu_remove_func, um, umi);
}
}
-
- /* Set the operator pointer for python access */
- uiLayoutSetContextFromBut(layout, but);
-
uiItemS(layout);
}