diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-10-30 02:46:29 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-10-30 02:57:33 +0300 |
commit | 817319a79ef36aad920ed1f8bbb7a617dabc697f (patch) | |
tree | e050bbf752f24a8938a949da9310146fc7379092 /source/blender/editors | |
parent | b3478930d895a610534e6b1ef3eeb105e43f5834 (diff) |
UI: add uiItemMenuFN which frees it's argument
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/include/UI_interface.h | 1 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_layout.c | 19 |
2 files changed, 18 insertions, 2 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index cbca7c8c921..0f160d7263b 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -1203,6 +1203,7 @@ void uiItemPopoverPanelFromGroup( const char *context, const char *category); void uiItemMenuF(uiLayout *layout, const char *name, int icon, uiMenuCreateFunc func, void *arg); +void uiItemMenuFN(uiLayout *layout, const char *name, int icon, uiMenuCreateFunc func, void *argN); void uiItemMenuEnumO_ptr(uiLayout *layout, struct bContext *C, struct wmOperatorType *ot, const char *propname, const char *name, int icon); void uiItemMenuEnumO(uiLayout *layout, struct bContext *C, const char *opname, const char *propname, const char *name, int icon); void uiItemMenuEnumR_prop(uiLayout *layout, struct PointerRNA *ptr, PropertyRNA *prop, const char *name, int icon); diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index e2b1818c958..920d9044f02 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -2224,8 +2224,11 @@ static uiBut *ui_item_menu( else but = uiDefMenuBut(block, func, arg, name, 0, 0, w, h, tip); - if (argN) { /* ugly .. */ - but->poin = (char *)but; + if (argN) { + /* ugly .. */ + if (arg != argN) { + but->poin = (char *)but; + } but->func_argN = argN; } @@ -2451,6 +2454,18 @@ void uiItemMenuF(uiLayout *layout, const char *name, int icon, uiMenuCreateFunc ui_item_menu(layout, name, icon, func, arg, NULL, "", false); } +/** + * Version of #uiItemMenuF that free's `argN`. + */ +void uiItemMenuFN(uiLayout *layout, const char *name, int icon, uiMenuCreateFunc func, void *argN) +{ + if (!func) + return; + + /* Second 'argN' only ensures it gets freed. */ + ui_item_menu(layout, name, icon, func, argN, argN, "", false); +} + typedef struct MenuItemLevel { int opcontext; /* don't use pointers to the strings because python can dynamically |