Fix T58327: Quick Favorites "Remove from Favorites" missing for added
authorPhilipp Oeser <info@graphics-engineer.com>
Thu, 20 Dec 2018 12:00:32 +0000 (13:00 +0100)
committerPhilipp Oeser <info@graphics-engineer.com>
Fri, 21 Dec 2018 20:06:52 +0000 (21:06 +0100)
Modifiers

Since user menu entries from SPACE_BUTS/SPACE_TOPBAR are also shown in
other Editors (SPACE_VIEW3D), also allow these entries to be removed
from Quick Favorites from these Editors.
Match and deduplicate logic from screen_user_menu_draw() and
ui_popup_context_menu_for_button().

Reviewers: campbellbarton, brecht

Maniphest Tasks: T58327

Differential Revision: https://developer.blender.org/D4112

source/blender/editors/include/ED_screen.h
source/blender/editors/interface/interface_context_menu.c
source/blender/editors/screen/screen_user_menu.c

index ce0c946..35f5000 100644 (file)
@@ -310,7 +310,7 @@ bool ED_operator_camera(struct bContext *C);
 
 /* screen_user_menu.c */
 
-struct bUserMenu *ED_screen_user_menu_find(struct bContext *C);
+bUserMenu **ED_screen_user_menus_find(struct bContext *C, uint *r_len);
 struct bUserMenu *ED_screen_user_menu_ensure(struct bContext *C);
 
 
index d996762..fc7d329 100644 (file)
@@ -699,8 +699,13 @@ bool ui_popup_context_menu_for_button(bContext *C, uiBut *but)
                        "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) {
+               uint um_array_len;
+               bUserMenu **um_array = ED_screen_user_menus_find(C, &um_array_len);
+               for (int um_index = 0; um_index < um_array_len; um_index++) {
+                       bUserMenu *um = um_array[um_index];
+                       if (um == NULL) {
+                               continue;
+                       }
                        bUserMenuItem *umi = ui_but_user_menu_find(C, but, um);
                        if (umi != NULL) {
                                but2 = uiDefIconTextBut(
@@ -710,6 +715,8 @@ bool ui_popup_context_menu_for_button(bContext *C, uiBut *but)
                                UI_but_func_set(but2, popup_user_menu_remove_func, um, umi);
                        }
                }
+               MEM_freeN(um_array);
+
                uiItemS(layout);
        }
 
index 45f8261..fe2b144 100644 (file)
 /** \name Menu Type
  * \{ */
 
-bUserMenu *ED_screen_user_menu_find(bContext *C)
+bUserMenu **ED_screen_user_menus_find(bContext *C, uint *r_len)
 {
        SpaceLink *sl = CTX_wm_space_data(C);
        const char *context = CTX_data_mode_string(C);
-       return BKE_blender_user_menu_find(&U.user_menus, sl->spacetype, context);
+
+       uint array_len = 3;
+       bUserMenu **um_array = MEM_calloc_arrayN(array_len, sizeof(*um_array), __func__);
+       um_array[0] = BKE_blender_user_menu_find(&U.user_menus, sl->spacetype, context);
+       um_array[1] = (sl->spacetype != SPACE_TOPBAR) ? BKE_blender_user_menu_find(&U.user_menus, SPACE_TOPBAR, context) : NULL;
+       um_array[2] = (sl->spacetype == SPACE_VIEW3D) ? BKE_blender_user_menu_find(&U.user_menus, SPACE_BUTS, context) : NULL;
+
+       *r_len = array_len;
+       return um_array;
 }
 
 bUserMenu *ED_screen_user_menu_ensure(bContext *C)
@@ -182,15 +190,10 @@ void ED_screen_user_menu_item_remove(ListBase *lb, bUserMenuItem *umi)
 
 static void screen_user_menu_draw(const bContext *C, Menu *menu)
 {
-       SpaceLink *sl = CTX_wm_space_data(C);
-       const char *context = CTX_data_mode_string(C);
-       bUserMenu *um_array[] = {
-               BKE_blender_user_menu_find(&U.user_menus, sl->spacetype, context),
-               (sl->spacetype != SPACE_TOPBAR) ? BKE_blender_user_menu_find(&U.user_menus, SPACE_TOPBAR, context) : NULL,
-               (sl->spacetype == SPACE_VIEW3D) ? BKE_blender_user_menu_find(&U.user_menus, SPACE_BUTS, context) : NULL,
-       };
+       uint um_array_len;
+       bUserMenu **um_array = ED_screen_user_menus_find(C, &um_array_len);
        bool is_empty = true;
-       for (int um_index = 0; um_index < ARRAY_SIZE(um_array); um_index++) {
+       for (int um_index = 0; um_index < um_array_len; um_index++) {
                bUserMenu *um = um_array[um_index];
                if (um == NULL) {
                        continue;
@@ -258,6 +261,7 @@ static void screen_user_menu_draw(const bContext *C, Menu *menu)
                        }
                }
        }
+       MEM_freeN(um_array);
 
        if (is_empty) {
                uiItemL(menu->layout, IFACE_("No menu items found."), ICON_NONE);