diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-11-14 18:42:47 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-11-14 18:42:47 +0400 |
commit | 9e6860d864d0f630f92f2fb7130412e9387aea26 (patch) | |
tree | 766bbe23db54fea7829a1b2b5c297ae68469c5c8 /source/blender/editors/interface | |
parent | 1ace39c86bf54271cdc2ce7ae5bb4166715cd02a (diff) |
fix [#29242] menus have no keyboard shortcuts
Diffstat (limited to 'source/blender/editors/interface')
6 files changed, 70 insertions, 17 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 81b42277055..ce4e052bd53 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -48,6 +48,8 @@ #include "BKE_context.h" #include "BKE_library.h" #include "BKE_unit.h" +#include "BKE_screen.h" +#include "BKE_idprop.h" #include "BKE_utildefines.h" /* FILE_MAX */ #include "BIF_gl.h" @@ -793,26 +795,61 @@ static void ui_menu_block_set_keyaccels(uiBlock *block) static void ui_menu_block_set_keymaps(const bContext *C, uiBlock *block) { uiBut *but; - IDProperty *prop; char buf[512]; + /* for menu's */ + MenuType *mt; + IDProperty *prop_menu= NULL; + IDProperty *prop_menu_name= NULL; + /* only do it before bounding */ if(block->minx != block->maxx) return; + +#define UI_MENU_KEY_STR_CAT \ + char *butstr_orig= BLI_strdup(but->str); \ + BLI_snprintf(but->strdata, \ + sizeof(but->strdata), \ + "%s|%s", \ + butstr_orig, buf); \ + MEM_freeN(butstr_orig); \ + but->str= but->strdata; \ + ui_check_but(but); \ + + for(but=block->buttons.first; but; but=but->next) { if(but->optype) { - prop= (but->opptr)? but->opptr->data: NULL; - - if(WM_key_event_operator_string(C, but->optype->idname, but->opcontext, prop, buf, sizeof(buf))) { - char *butstr_orig= BLI_strdup(but->str); - BLI_snprintf(but->strdata, sizeof(but->strdata), "%s|%s", butstr_orig, buf); - MEM_freeN(butstr_orig); - but->str= but->strdata; - ui_check_but(but); + IDProperty *prop= (but->opptr)? but->opptr->data: NULL; + + if(WM_key_event_operator_string(C, but->optype->idname, but->opcontext, prop, TRUE, buf, sizeof(buf))) { + UI_MENU_KEY_STR_CAT + } + } + else if ((mt= uiButGetMenuType(but))) { + /* only allocate menu property once */ + if (prop_menu == NULL) { + /* annoying, create a property */ + IDPropertyTemplate val = {0}; + prop_menu= IDP_New(IDP_GROUP, val, __func__); /* dummy, name is unimportant */ + IDP_AddToGroup(prop_menu, (prop_menu_name= IDP_NewString("", "name", sizeof(mt->idname)))); + } + + IDP_AssignString(prop_menu_name, mt->idname, sizeof(mt->idname)); + + if(WM_key_event_operator_string(C, "WM_OT_call_menu", WM_OP_INVOKE_REGION_WIN, prop_menu, FALSE, buf, sizeof(buf))) { + UI_MENU_KEY_STR_CAT } } } + + if (prop_menu) { + IDP_FreeProperty(prop_menu); + MEM_freeN(prop_menu); + } + +#undef UI_MENU_KEY_STR_CAT + } void uiEndBlock(const bContext *C, uiBlock *block) diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 7338aa1983f..ee1f9617813 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -4357,7 +4357,7 @@ static void but_shortcut_name_func(bContext *C, void *arg1, int UNUSED(event)) IDProperty *prop= (but->opptr)? but->opptr->data: NULL; /* complex code to change name of button */ - if(WM_key_event_operator_string(C, but->optype->idname, but->opcontext, prop, buf, sizeof(buf))) { + if(WM_key_event_operator_string(C, but->optype->idname, but->opcontext, prop, TRUE, buf, sizeof(buf))) { char *butstr_orig; // XXX but->str changed... should not, remove the hotkey from it diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 32bcfe51afc..a6f93101fdc 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -2821,3 +2821,14 @@ void uiLayoutOperatorButs(const bContext *C, uiLayout *layout, wmOperator *op,in } } } + +/* this is a bit of a hack but best keep it in one place at least */ +MenuType *uiButGetMenuType(uiBut *but) +{ + if(but->menu_create_func == ui_item_menutype_func) { + return (MenuType *)but->poin; + } + else { + return NULL; + } +} diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 34b62155314..837a9d12af1 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -408,7 +408,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) /* operator keymap (not menus, they already have it) */ prop= (but->opptr)? but->opptr->data: NULL; - if(WM_key_event_operator_string(C, but->optype->idname, but->opcontext, prop, buf, sizeof(buf))) { + if(WM_key_event_operator_string(C, but->optype->idname, but->opcontext, prop, TRUE, buf, sizeof(buf))) { BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), TIP_("Shortcut: %s"), buf); data->color[data->totline]= 0x888888; data->totline++; @@ -493,8 +493,8 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) } else if (ELEM(but->type, MENU, PULLDOWN)) { if ((U.flag & USER_TOOLTIPS_PYTHON) == 0) { - if(but->menu_create_func && WM_menutype_contains((MenuType *)but->poin)) { - MenuType *mt= (MenuType *)but->poin; + MenuType *mt= uiButGetMenuType(but); + if (mt) { BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), TIP_("Python: %s"), mt->idname); data->color[data->totline]= 0x888888; data->totline++; diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 795446e76ef..eb7e06623f7 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -2458,7 +2458,7 @@ static void operator_search_cb(const bContext *C, void *UNUSED(arg), const char /* check for hotkey */ if(len < 256-6) { - if(WM_key_event_operator_string(C, ot->idname, WM_OP_EXEC_DEFAULT, NULL, &name[len+1], 256-len-1)) + if(WM_key_event_operator_string(C, ot->idname, WM_OP_EXEC_DEFAULT, NULL, TRUE, &name[len+1], 256-len-1)) name[len]= '|'; } diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index aa407bbf6d4..c9fcb7f1d24 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -810,6 +810,11 @@ static void widget_draw_preview(BIFIconID icon, float UNUSED(alpha), rcti *rect) } +static int ui_but_draw_menu_icon(uiBut *but) +{ + return (but->flag & UI_ICON_SUBMENU) && (but->dt == UI_EMBOSSP); +} + /* icons have been standardized... and this call draws in untransformed coordinates */ static void widget_draw_icon(uiBut *but, BIFIconID icon, float alpha, rcti *rect) @@ -888,8 +893,8 @@ static void widget_draw_icon(uiBut *but, BIFIconID icon, float alpha, rcti *rect else UI_icon_draw_aspect(xs, ys, icon, aspect, alpha); } - - if((but->flag & UI_ICON_SUBMENU) && (but->dt == UI_EMBOSSP)) { + + if (ui_but_draw_menu_icon(but)) { xs= rect->xmax-17; ys= (rect->ymin+rect->ymax- height)/2; @@ -1139,7 +1144,7 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b /* part text right aligned */ if(cpoin) { fstyle->align= UI_STYLE_TEXT_RIGHT; - rect->xmax-=5; + rect->xmax -= ui_but_draw_menu_icon(but) ? UI_DPI_ICON_SIZE : 5; uiStyleFontDraw(fstyle, rect, cpoin+1); *cpoin= '|'; } |