Page MenuHome

Fix T100423: Addon's custom context menu entries get overridden by other addons
ClosedPublic

Authored by Luca Rood (LucaRood) on Aug 16 2022, 6:01 PM.

Details

Summary

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.

Diff Detail

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

Event Timeline

Luca Rood (LucaRood) requested review of this revision.Aug 16 2022, 6:01 PM
Luca Rood (LucaRood) created this revision.
Luca Rood (LucaRood) added a comment.EditedAug 16 2022, 6:10 PM

I've made this patch off of the blender-v3.3-release branch, as I expect it's probably desirable to have this in the upcoming release (after all, I would say the original issue is a bug). Let me know if this is not the case.

Also note the small change in source/blender/editors/interface/interface_layout.c. This was needed as the context was being cleared when drawing the legacy menu (layout.menu_contents("WM_MT_button_context")), which caused any subsequently drawn items to have the wrong context (i.e. any draw function appended to the UI_MT_button_context_menu class). As far as I can tell, this change shouldn't be an issue, as I don't think there was an actual need to clear the context there. Let me know if I'm wrong and this should be handled differently (an alternative could be to just draw both menus in source/blender/editors/interface/interface_context_menu.c instead of using menu_contents).

source/blender/editors/interface/interface_layout.c
5804

Could this be moved to uiItemMContents ? I don't think there are other cases this needs to be done.

  • Move context restoration to uiItemMContents
Campbell Barton (campbellbarton) added inline comments.
release/scripts/startup/bl_ui/__init__.py
256

Worth noting this is is deprecated and will eventually be removed.

This revision is now accepted and ready to land.Aug 18 2022, 2:25 PM