fix [#29242] menus have no keyboard shortcuts

This commit is contained in:
Campbell Barton 2011-11-14 14:42:47 +00:00
parent 1ace39c86b
commit 9e6860d864
14 changed files with 78 additions and 45 deletions

@ -763,7 +763,6 @@ class ConstraintButtonsPanel():
layout.prop(con, "track")
layout.operator("clip.constraint_to_fcurve")
def CAMERA_SOLVER(self, context, layout, con):

@ -1449,6 +1449,7 @@ int BKE_tracking_can_solve(MovieTracking *tracking, char *error_msg, int error_s
return 1;
#else
BLI_strncpy(error_msg, "Blender is compiled without motion tracking library", error_size);
(void)tracking;
return 0;
#endif

@ -688,6 +688,7 @@ void uiLayoutSetFunc(uiLayout *layout, uiMenuHandleFunc handlefunc, void *argv);
void uiLayoutSetContextPointer(uiLayout *layout, const char *name, struct PointerRNA *ptr);
const char *uiLayoutIntrospect(uiLayout *layout); // XXX - testing
void uiLayoutOperatorButs(const struct bContext *C, struct uiLayout *layout, struct wmOperator *op, int (*check_prop)(struct PropertyRNA *), const char label_align, const short flag);
struct MenuType *uiButGetMenuType(uiBut *but);
void uiLayoutSetOperatorContext(uiLayout *layout, int opcontext);
void uiLayoutSetActive(uiLayout *layout, int active);

@ -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;
IDProperty *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);
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)

@ -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

@ -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;
}
}

@ -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++;

@ -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]= '|';
}

@ -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= '|';
}

@ -233,7 +233,6 @@ void WM_operator_py_idname(char *to, const char *from);
void WM_menutype_init(void);
struct MenuType *WM_menutype_find(const char *idname, int quiet);
int WM_menutype_add(struct MenuType* mt);
int WM_menutype_contains(struct MenuType* mt);
void WM_menutype_freelink(struct MenuType* mt);
void WM_menutype_free(void);

@ -92,7 +92,7 @@ void WM_keymap_restore_item_to_default(struct bContext *C, struct wmKeyMap *key
const char *WM_key_event_string(short type);
int WM_key_event_operator_id(const struct bContext *C, const char *opname, int opcontext, struct IDProperty *properties, int hotkey, struct wmKeyMap **keymap_r);
char *WM_key_event_operator_string(const struct bContext *C, const char *opname, int opcontext, struct IDProperty *properties, char *str, int len);
char *WM_key_event_operator_string(const struct bContext *C, const char *opname, int opcontext, struct IDProperty *properties, const short sloppy, char *str, int len);
#ifdef __cplusplus
}

@ -175,26 +175,6 @@ int WM_menutype_add(MenuType* mt)
return 1;
}
/* inefficient but only used for tooltip code */
int WM_menutype_contains(MenuType* mt)
{
int found= FALSE;
if(mt) {
GHashIterator *iter= BLI_ghashIterator_new(menutypes_hash);
for( ; !BLI_ghashIterator_isDone(iter); BLI_ghashIterator_step(iter)) {
if(mt == BLI_ghashIterator_getValue(iter)) {
found= TRUE;
break;
}
}
BLI_ghashIterator_free(iter);
}
return found;
}
void WM_menutype_freelink(MenuType* mt)
{
BLI_ghash_remove(menutypes_hash, mt->idname, NULL, (GHashValFreeFP)MEM_freeN);

@ -852,19 +852,19 @@ static wmKeyMapItem *wm_keymap_item_find_props(const bContext *C, const char *op
return found;
}
static wmKeyMapItem *wm_keymap_item_find(const bContext *C, const char *opname, int opcontext, IDProperty *properties, int hotkey, wmKeyMap **keymap_r)
static wmKeyMapItem *wm_keymap_item_find(const bContext *C, const char *opname, int opcontext, IDProperty *properties, const short hotkey, const short sloppy, wmKeyMap **keymap_r)
{
wmKeyMapItem *found= wm_keymap_item_find_props(C, opname, opcontext, properties, 1, hotkey, keymap_r);
if(!found)
if(!found && sloppy)
found= wm_keymap_item_find_props(C, opname, opcontext, NULL, 0, hotkey, keymap_r);
return found;
}
char *WM_key_event_operator_string(const bContext *C, const char *opname, int opcontext, IDProperty *properties, char *str, int len)
char *WM_key_event_operator_string(const bContext *C, const char *opname, int opcontext, IDProperty *properties, const short sloppy, char *str, int len)
{
wmKeyMapItem *kmi= wm_keymap_item_find(C, opname, opcontext, properties, 0, NULL);
wmKeyMapItem *kmi= wm_keymap_item_find(C, opname, opcontext, properties, 0, sloppy, NULL);
if(kmi) {
WM_keymap_item_to_string(kmi, str, len);
@ -876,7 +876,7 @@ char *WM_key_event_operator_string(const bContext *C, const char *opname, int op
int WM_key_event_operator_id(const bContext *C, const char *opname, int opcontext, IDProperty *properties, int hotkey, wmKeyMap **keymap_r)
{
wmKeyMapItem *kmi= wm_keymap_item_find(C, opname, opcontext, properties, hotkey, keymap_r);
wmKeyMapItem *kmi= wm_keymap_item_find(C, opname, opcontext, properties, hotkey, TRUE, keymap_r);
if(kmi)
return kmi->id;

@ -1362,7 +1362,7 @@ static void operator_search_cb(const struct bContext *C, void *UNUSED(arg), cons
/* 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]= '|';
}