Page MenuHome

Fix T103589: Don't open 'Online manual' and 'Online Python' context menu if already open
Needs ReviewPublic

Authored by Sibo Van Gool (SiboVG) on Jan 5 2023, 12:51 AM.

Details

Summary

Fix T103589: right-clicking on the "Online Manual" button inside an "Online Manual" context menu created a duplicate "Online Manual" context menu. The same happened for the "Online Python Reference" context menu.

This PR fixes that by checking for if the currently opened context menu is that of "Online Manual". If it is, then
right-clicking the "Online Manual" button will no longer open the "Online Manual" context menu. Same
goes for the "Online Python Reference" context menu.

To know which type of context menu is currently opened, I didn't find any better way than to parse
the header label of the context menu. If a more experienced developer has a better alternative for
this, I'm happy to change it :).

Diff Detail

Repository
rB Blender
Branch
T103589 (branched from master)
Build Status
Buildable 25245
Build 25245: arc lint + arc unit

Event Timeline

Sibo Van Gool (SiboVG) requested review of this revision.Jan 5 2023, 12:51 AM
Sibo Van Gool (SiboVG) created this revision.
This comment was removed by Sibo Van Gool (SiboVG).

Note: you can still have endless alternating context menus between "Online Manual" and "Online Python Reference".

Sibo Van Gool (SiboVG) edited the summary of this revision. (Show Details)Wed, Jan 25, 6:07 PM
Sibo Van Gool (SiboVG) retitled this revision from [T103589] Don't open 'Online manual' and 'Online Python' context menu if already open to Fix T103589: Don't open 'Online manual' and 'Online Python' context menu if already open.
Sibo Van Gool (SiboVG) edited the summary of this revision. (Show Details)
Sibo Van Gool (SiboVG) edited the summary of this revision. (Show Details)Wed, Jan 25, 6:44 PM

Haven't looked at this much, but rather than not execute the second one why not just not add it? Keeps all the related things together, you don't end up with a menu item that doesn't work, and no need to find the header label:

diff --git a/source/blender/editors/interface/interface_context_menu.cc b/source/blender/editors/interface/interface_context_menu.cc
index 5c31194fb924..433cf6135b9a 100644
--- a/source/blender/editors/interface/interface_context_menu.cc
+++ b/source/blender/editors/interface/interface_context_menu.cc
@@ -1149,36 +1149,41 @@ bool ui_popup_context_menu_for_button(bContext *C, uiBut *but, const wmEvent *ev
     /* Set the operator pointer for python access */
     uiLayoutSetContextFromBut(layout, but);
 
     uiItemS(layout);
   }
 
   { /* Docs */
     char buf[512];
 
     if (UI_but_online_manual_id(but, buf, sizeof(buf))) {
-      PointerRNA ptr_props;
-      uiItemO(layout,
-              CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Online Manual"),
-              ICON_URL,
-              "WM_OT_doc_view_manual_ui_context");
+
+      if (!(but->optype && STREQ(but->optype->idname, "WM_OT_doc_view_manual_ui_context"))) {
+        uiItemO(layout,
+                CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Online Manual"),
+                ICON_URL,
+                "WM_OT_doc_view_manual_ui_context");
+      }
 
       if (U.flag & USER_DEVELOPER_UI) {
-        uiItemFullO(layout,
-                    "WM_OT_doc_view",
-                    CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Online Python Reference"),
-                    ICON_NONE,
-                    nullptr,
-                    WM_OP_EXEC_DEFAULT,
-                    0,
-                    &ptr_props);
-        RNA_string_set(&ptr_props, "doc_id", buf);
+        if (!(but->optype && STREQ(but->optype->idname, "WM_OT_doc_view"))) {
+          PointerRNA ptr_props;
+          uiItemFullO(layout,
+                      "WM_OT_doc_view",
+                      CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Online Python Reference"),
+                      ICON_NONE,
+                      nullptr,
+                      WM_OP_EXEC_DEFAULT,
+                      0,
+                      &ptr_props);
+          RNA_string_set(&ptr_props, "doc_id", buf);
+        }
       }
     }
   }
 
   if (but->optype && U.flag & USER_DEVELOPER_UI) {
     uiItemO(layout, nullptr, ICON_NONE, "UI_OT_copy_python_command_button");
   }
 
   /* perhaps we should move this into (G.debug & G_DEBUG) - campbell */
   if (U.flag & USER_DEVELOPER_UI) {