fix [#29242] menus have no keyboard shortcuts
authorCampbell Barton <ideasman42@gmail.com>
Mon, 14 Nov 2011 14:42:47 +0000 (14:42 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 14 Nov 2011 14:42:47 +0000 (14:42 +0000)
14 files changed:
release/scripts/startup/bl_ui/properties_object_constraint.py
source/blender/blenkernel/intern/tracking.c
source/blender/editors/include/UI_interface.h
source/blender/editors/interface/interface.c
source/blender/editors/interface/interface_handlers.c
source/blender/editors/interface/interface_layout.c
source/blender/editors/interface/interface_regions.c
source/blender/editors/interface/interface_templates.c
source/blender/editors/interface/interface_widgets.c
source/blender/windowmanager/WM_api.h
source/blender/windowmanager/WM_keymap.h
source/blender/windowmanager/intern/wm.c
source/blender/windowmanager/intern/wm_keymap.c
source/blender/windowmanager/intern/wm_operators.c

index 8cdb07461bbf25d0c175c8782e520be41849933d..1ff9a8a0449a05d9cc7147aec461b8f2f1a8a8d1 100644 (file)
@@ -763,7 +763,6 @@ class ConstraintButtonsPanel():
 
         layout.prop(con, "track")
 
-
         layout.operator("clip.constraint_to_fcurve")
 
     def CAMERA_SOLVER(self, context, layout, con):
index d236c053058765b76aa299761a182f710c26de78..d582ad7c4d8d062e8bbf8a97a22ba7ce33631d04 100644 (file)
@@ -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
index 35fabb3b80e90d4a3e7dc7362dbdeb4bada30563..01273b291a268219ba15436cfb00239bfe4ce55c 100644 (file)
@@ -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);
index 81b42277055233344075ce1b675f767434092756..ce4e052bd53e9d6815f86745812811c0c428c197 100644 (file)
@@ -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)
index 7338aa1983f564927da30aeea5fec84fdea752ce..ee1f96178137023ea56bf24fa58ee0a25a9aa62b 100644 (file)
@@ -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
index 32bcfe51afcfa2722ea0ae0c4553e3c8cba2dee1..a6f93101fdc88c372c516259ae306c83600a2f7f 100644 (file)
@@ -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;
+       }
+}
index 34b62155314dcff5a74fb029e35e6c089a73c160..837a9d12af158ea45ffd84f8c509f65c448abcde 100644 (file)
@@ -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++;
index 795446e76efa18bc907a197d0e8f61da2a84e19b..eb7e06623f7cfa726b1d6b9fbcd461d8845dfb4a 100644 (file)
@@ -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]= '|';
                                }
                                
index aa407bbf6d4f780cbd0bca015f76317834967a0f..c9fcb7f1d24ed5ab2a2a5a4ef7976d0bc740f2d4 100644 (file)
@@ -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= '|';
        }
index 8b55db27761e21f2191809a6a28945dc3e178137..fcdb6d25083036ccd638a0c8ec1bc09a094e7af1 100644 (file)
@@ -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);
 
index 250752e661af87f97c5a883a30bef7f8ab0d3763..f254358e3cf06380f33a1b177ff669a7a393283f 100644 (file)
@@ -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
 }
index 10c3735685c93c4fc2e2f21ffae46f77146693f1..c6c67e22bfd9d1b9b00a0a9ba42ca6f39c8dc43e 100644 (file)
@@ -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);
index 9957d24c7ab03b536a84de342b62db38de30b06c..2e191a5ab6d005769315d9fbce78de66b391554e 100644 (file)
@@ -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;
index 4367a8b03ef99d0512755442f19a28aa4931463d..7fb6ba6e26b553343e496730cbee3aca3168c40f 100644 (file)
@@ -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]= '|';
                                }