diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-06-30 21:59:10 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-06-30 22:08:48 +0300 |
commit | 6a13b6324b42fedb0ad886e6c64816358058d627 (patch) | |
tree | dd7e42720031978eb7083b370cce458bfedb0c43 /source/blender/editors/screen/screen_user_menu.c | |
parent | 7d48a342d66cc7664b008ff512bd00e740eb7629 (diff) |
UI: support check-boxes in quick menu
Could support other RNA types,
however menus don't work well in this case.
Diffstat (limited to 'source/blender/editors/screen/screen_user_menu.c')
-rw-r--r-- | source/blender/editors/screen/screen_user_menu.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/source/blender/editors/screen/screen_user_menu.c b/source/blender/editors/screen/screen_user_menu.c index c51227d7107..f62dc1ee500 100644 --- a/source/blender/editors/screen/screen_user_menu.c +++ b/source/blender/editors/screen/screen_user_menu.c @@ -56,6 +56,8 @@ #include "UI_interface.h" #include "UI_resources.h" +#include "RNA_access.h" + /* -------------------------------------------------------------------- */ /** \name Menu Type * \{ */ @@ -113,6 +115,24 @@ struct bUserMenuItem_Menu *ED_screen_user_menu_item_find_menu( return NULL; } +struct bUserMenuItem_Prop *ED_screen_user_menu_item_find_prop( + struct ListBase *lb, + const char *context_data_path, const char *prop_id, int prop_index) +{ + for (bUserMenuItem *umi = lb->first; umi; umi = umi->next) { + if (umi->type == USER_MENU_TYPE_PROP) { + bUserMenuItem_Prop *umi_pr = (bUserMenuItem_Prop *)umi; + if (STREQ(context_data_path, umi_pr->context_data_path) && + STREQ(prop_id, umi_pr->prop_id) && + (prop_index == umi_pr->prop_index)) + { + return umi_pr; + } + } + } + return NULL; +} + void ED_screen_user_menu_item_add_operator( ListBase *lb, const char *ui_name, const wmOperatorType *ot, const IDProperty *prop, short opcontext) @@ -137,6 +157,17 @@ void ED_screen_user_menu_item_add_menu( STRNCPY(umi_mt->mt_idname, mt->idname); } +void ED_screen_user_menu_item_add_prop( + ListBase *lb, const char *ui_name, + const char *context_data_path, const char *prop_id, int prop_index) +{ + bUserMenuItem_Prop *umi_pr = (bUserMenuItem_Prop *)BKE_blender_user_menu_item_add(lb, USER_MENU_TYPE_PROP); + STRNCPY(umi_pr->item.ui_name, ui_name); + STRNCPY(umi_pr->context_data_path, context_data_path); + STRNCPY(umi_pr->prop_id, prop_id); + umi_pr->prop_index = prop_index; +} + void ED_screen_user_menu_item_remove(ListBase *lb, bUserMenuItem *umi) { BLI_remlink(lb, umi); @@ -176,6 +207,47 @@ static void screen_user_menu_draw(const bContext *C, Menu *menu) uiItemM(menu->layout, umi_mt->mt_idname, ui_name, ICON_NONE); } + else if (umi->type == USER_MENU_TYPE_PROP) { + bUserMenuItem_Prop *umi_pr = (bUserMenuItem_Prop *)umi; + + char *data_path = strchr(umi_pr->context_data_path, '.'); + if (data_path) { + *data_path = '\0'; + } + PointerRNA ptr = CTX_data_pointer_get(C, umi_pr->context_data_path); + if (ptr.type == NULL) { + PointerRNA ctx_ptr; + RNA_pointer_create(NULL, &RNA_Context, (void *)C, &ctx_ptr); + if (!RNA_path_resolve_full(&ctx_ptr, umi_pr->context_data_path, &ptr, NULL, NULL)) { + ptr.type = NULL; + } + } + if (data_path) { + *data_path = '.'; + data_path += 1; + } + + bool ok = false; + if (ptr.type != NULL) { + PropertyRNA *prop = NULL; + PointerRNA prop_ptr = ptr; + if ((data_path == NULL) || RNA_path_resolve_full(&ptr, data_path, &prop_ptr, NULL, NULL)) { + prop = RNA_struct_find_property(&prop_ptr, umi_pr->prop_id); + if (prop) { + ok = true; + uiItemFullR( + menu->layout, + &prop_ptr, prop, umi_pr->prop_index, + 0, 0, ui_name, ICON_NONE); + } + } + } + if (!ok) { + char label[512]; + SNPRINTF(label, "Missing: %s.%s", umi_pr->context_data_path, umi_pr->prop_id); + uiItemL(menu->layout, label, ICON_NONE); + } + } else if (umi->type == USER_MENU_TYPE_SEP) { uiItemS(menu->layout); } |