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:
authorLuca Rood <dev@lucarood.com>2022-08-18 15:42:48 +0300
committerLuca Rood <dev@lucarood.com>2022-08-18 15:46:30 +0300
commit8a799b00f8fa28433ba44cfec09757f77a46ae0d (patch)
tree84bb804b342fb6c4344d0f2729322eafc7c5752c /release/scripts/startup/bl_ui/__init__.py
parentc3757504233ab7b1dca7102bb9239423d6419efc (diff)
Fix T100423: Addon's custom context menu entries get overridden by other addons
This introduces a new `UI_MT_button_context_menu` class which is registered at startup. Addons can append/prepend draw functions to this class, in order to add their custom context menu entries. The new class replaces the old `WM_MT_button_context` class, thus requiring a small change in addons using this feature. This is done because addons were previously required to register the class themselves, which caused addons to override each other's context menu entries. Now the class registration is handled by Blender, and addons need only append their draw functions. The new class name ensures that addons using the old method don't override menu entries made using the new class. Menu entries added with the legacy `WM_MT_button_context` class are still drawn for backwards compatibility, but this class must not be used going forward, as any addon using it still runs the risk of having its menu entries overridden, and support for the legacy class is subject to removal in a future version. Reviewed By: campbellbarton Maniphest Tasks: T100423 Differential Revision: https://developer.blender.org/D15702
Diffstat (limited to 'release/scripts/startup/bl_ui/__init__.py')
-rw-r--r--release/scripts/startup/bl_ui/__init__.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/release/scripts/startup/bl_ui/__init__.py b/release/scripts/startup/bl_ui/__init__.py
index c4e3df469b7..a57a2cc5a4c 100644
--- a/release/scripts/startup/bl_ui/__init__.py
+++ b/release/scripts/startup/bl_ui/__init__.py
@@ -239,3 +239,23 @@ class UI_MT_list_item_context_menu(bpy.types.Menu):
bpy.utils.register_class(UI_MT_list_item_context_menu)
+
+
+class UI_MT_button_context_menu(bpy.types.Menu):
+ """
+ UI button context menu definition. Scripts can append/prepend this to
+ add own operators to the context menu. They must check context though, so
+ their items only draw in a valid context and for the correct buttons.
+ """
+
+ bl_label = "List Item"
+ bl_idname = "UI_MT_button_context_menu"
+
+ def draw(self, context):
+ # Draw menu entries created with the legacy `WM_MT_button_context` class.
+ # This is deprecated, and support will be removed in a future release.
+ if hasattr(bpy.types, "WM_MT_button_context"):
+ self.layout.menu_contents("WM_MT_button_context")
+
+
+bpy.utils.register_class(UI_MT_button_context_menu)