mirror of
https://github.com/blender/blender
synced 2026-09-29 04:37:17 +03:00
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
This commit is contained in:
parent
c375750423
commit
8a799b00f8
8 changed files with 39 additions and 29 deletions
|
|
@ -1 +1 @@
|
|||
Subproject commit 7a8502871c34db0343cc7de52d6b49b15a84238a
|
||||
Subproject commit 32baafe44dc56edd1baf6e5a16b4439ded8238f2
|
||||
|
|
@ -1 +1 @@
|
|||
Subproject commit 95107484d076bc965239942e857c83433bfa86d7
|
||||
Subproject commit 42da56aa73726710107031787af5eea186797984
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue