diff options
author | Luca Rood <dev@lucarood.com> | 2022-08-18 15:42:48 +0300 |
---|---|---|
committer | Luca Rood <dev@lucarood.com> | 2022-08-18 15:46:30 +0300 |
commit | 8a799b00f8fa28433ba44cfec09757f77a46ae0d (patch) | |
tree | 84bb804b342fb6c4344d0f2729322eafc7c5752c /source | |
parent | c3757504233ab7b1dca7102bb9239423d6419efc (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 'source')
-rw-r--r-- | source/blender/editors/interface/interface_context_menu.c | 2 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_layout.c | 7 | ||||
m--------- | source/tools | 0 |
3 files changed, 8 insertions, 1 deletions
diff --git a/source/blender/editors/interface/interface_context_menu.c b/source/blender/editors/interface/interface_context_menu.c index 16d228708eb..7ed9488950e 100644 --- a/source/blender/editors/interface/interface_context_menu.c +++ b/source/blender/editors/interface/interface_context_menu.c @@ -1230,7 +1230,7 @@ bool ui_popup_context_menu_for_button(bContext *C, uiBut *but, const wmEvent *ev } } - MenuType *mt = WM_menutype_find("WM_MT_button_context", true); + MenuType *mt = WM_menutype_find("UI_MT_button_context_menu", true); if (mt) { UI_menutype_draw(C, mt, uiLayoutColumn(layout, false)); } diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 3465373c85d..94d17ed3c88 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -3028,7 +3028,14 @@ void uiItemMContents(uiLayout *layout, const char *menuname) if (WM_menutype_poll(C, mt) == false) { return; } + + bContextStore *previous_ctx = CTX_store_get(C); UI_menutype_draw(C, mt, layout); + + /* Restore context that was cleared by `UI_menutype_draw`. */ + if (layout->context) { + CTX_store_set(C, previous_ctx); + } } void uiItemDecoratorR_prop(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop, int index) diff --git a/source/tools b/source/tools -Subproject da8bdd7244c7b6c2eadf4c949ff391d0cc43027 +Subproject 548055f40213c775a6b77025525c91e8466e70d |