Fix [#20798] - Add/change/remove shortcut options dissapearing from buttons @ Tool...
authorMatt Ebb <matt@mke3.net>
Tue, 26 Jan 2010 01:02:10 +0000 (01:02 +0000)
committerMatt Ebb <matt@mke3.net>
Tue, 26 Jan 2010 01:02:10 +0000 (01:02 +0000)
Made the RMB menus for manipulating shortcuts a bit more robust (only dealing with mouse
clicks/key events, rather than all tweaks/timers/etc) and added ability to add key shortcuts for
transform tools from the RMB menu.

source/blender/editors/interface/interface_handlers.c
source/blender/windowmanager/WM_api.h
source/blender/windowmanager/intern/wm_keymap.c

index dcb2f1810ceaa95c91dc5874df0c7952ef8c5a3e..b4da74b46644f4d84e69a4b00cc85fa081971088 100644 (file)
@@ -3456,7 +3456,7 @@ static uiBlock *menu_change_shortcut(bContext *C, ARegion *ar, void *arg)
        uiLayout *layout;
        uiStyle *style= U.uistyles.first;
        IDProperty *prop= (but->opptr)? but->opptr->data: NULL;
-       int kmi_id = WM_key_event_operator_id(C, but->optype->idname, but->opcontext, prop, &km);
+       int kmi_id = WM_key_event_operator_id(C, but->optype->idname, but->opcontext, prop, 1, &km);
 
        kmi = WM_keymap_item_find_id(km, kmi_id);
        
@@ -3524,7 +3524,7 @@ static void remove_shortcut_func(bContext *C, void *arg1, void *arg2)
        wmKeyMap *km;
        wmKeyMapItem *kmi;
        IDProperty *prop= (but->opptr)? but->opptr->data: NULL;
-       int kmi_id = WM_key_event_operator_id(C, but->optype->idname, but->opcontext, prop, &km);
+       int kmi_id = WM_key_event_operator_id(C, but->optype->idname, but->opcontext, prop, 1, &km);
        
        kmi = WM_keymap_item_find_id(km, kmi_id);
        WM_keymap_remove_item(km, kmi);
@@ -3662,10 +3662,12 @@ static int ui_but_menu(bContext *C, uiBut *but)
                uiBut *but2;
                IDProperty *prop= (but->opptr)? but->opptr->data: NULL;
                int w = uiLayoutGetWidth(layout);
-               char buf[512];
+               wmKeyMap *km;
+               int kmi_id= WM_key_event_operator_id(C, but->optype->idname, but->opcontext, prop, 1, &km);
+               wmKeyMapItem *kmi = WM_keymap_item_find_id(km, kmi_id);
 
                /* keyboard shortcuts */
-               if(WM_key_event_operator_string(C, but->optype->idname, but->opcontext, prop, buf, sizeof(buf))) {
+               if ((kmi) && ISKEYBOARD(kmi->type)) {
 
                        // would rather use a block but, but gets weirdly positioned...
                        //uiDefBlockBut(block, menu_change_shortcut, but, "Change Shortcut", 0, 0, uiLayoutGetWidth(layout), UI_UNIT_Y, "");
index 4defd781db9a1fb22436bf2e122acd71bca4b14a..b4cedf82a50e29f64011ce05be5173878050b68e 100644 (file)
@@ -131,7 +131,7 @@ wmKeyMapItem *WM_modalkeymap_add_item(struct wmKeyMap *km, int type, int val, in
 void           WM_modalkeymap_assign(struct wmKeyMap *km, char *opname);
 
 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, struct wmKeyMap **keymap_r);
+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);
 
                        /* handlers */
index 447a7ecb92fe67c04d8518bd618eaae437414682..ff06005c620d52ec97ca44561614ccf31f8c1997 100644 (file)
@@ -397,7 +397,7 @@ char *WM_keymap_item_to_string(wmKeyMapItem *kmi, char *str, int len)
        return str;
 }
 
-static wmKeyMapItem *wm_keymap_item_find_handlers(const bContext *C, ListBase *handlers, const char *opname, int opcontext, IDProperty *properties, int compare_props, wmKeyMap **keymap_r)
+static wmKeyMapItem *wm_keymap_item_find_handlers(const bContext *C, ListBase *handlers, const char *opname, int opcontext, IDProperty *properties, int compare_props, int hotkey, wmKeyMap **keymap_r)
 {
        wmWindowManager *wm= CTX_wm_manager(C);
        wmEventHandler *handler;
@@ -411,6 +411,10 @@ static wmKeyMapItem *wm_keymap_item_find_handlers(const bContext *C, ListBase *h
                if(keymap && (!keymap->poll || keymap->poll((bContext*)C))) {
                        for(kmi=keymap->items.first; kmi; kmi=kmi->next) {
                                if(strcmp(kmi->idname, opname) == 0 && WM_key_event_string(kmi->type)[0]) {
+                                       if (hotkey)
+                                               if (!ISHOTKEY(kmi->type))
+                                                       continue;
+                                       
                                        if(compare_props) {
                                                if(kmi->ptr && IDP_EqualsProperties(properties, kmi->ptr->data)) {
                                                        if(keymap_r) *keymap_r= keymap;
@@ -429,7 +433,7 @@ static wmKeyMapItem *wm_keymap_item_find_handlers(const bContext *C, ListBase *h
        return NULL;
 }
 
-static wmKeyMapItem *wm_keymap_item_find_props(const bContext *C, const char *opname, int opcontext, IDProperty *properties, int compare_props, wmKeyMap **keymap_r)
+static wmKeyMapItem *wm_keymap_item_find_props(const bContext *C, const char *opname, int opcontext, IDProperty *properties, int compare_props, int hotkey, wmKeyMap **keymap_r)
 {
        wmWindow *win= CTX_wm_window(C);
        ScrArea *sa= CTX_wm_area(C);
@@ -438,11 +442,11 @@ static wmKeyMapItem *wm_keymap_item_find_props(const bContext *C, const char *op
 
        /* look into multiple handler lists to find the item */
        if(win)
-               found= wm_keymap_item_find_handlers(C, &win->handlers, opname, opcontext, properties, compare_props, keymap_r);
+               found= wm_keymap_item_find_handlers(C, &win->handlers, opname, opcontext, properties, compare_props, hotkey, keymap_r);
        
 
        if(sa && found==NULL)
-               found= wm_keymap_item_find_handlers(C, &sa->handlers, opname, opcontext, properties, compare_props, keymap_r);
+               found= wm_keymap_item_find_handlers(C, &sa->handlers, opname, opcontext, properties, compare_props, hotkey, keymap_r);
 
        if(found==NULL) {
                if(ELEM(opcontext, WM_OP_EXEC_REGION_WIN, WM_OP_INVOKE_REGION_WIN)) {
@@ -453,31 +457,31 @@ static wmKeyMapItem *wm_keymap_item_find_props(const bContext *C, const char *op
                                                break;
 
                                if(ar)
-                                       found= wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, compare_props, keymap_r);
+                                       found= wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, hotkey, compare_props, keymap_r);
                        }
                }
                else {
                        if(ar)
-                               found= wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, compare_props, keymap_r);
+                               found= wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, hotkey, compare_props, keymap_r);
                }
        }
        
        return found;
 }
 
-static wmKeyMapItem *wm_keymap_item_find(const bContext *C, const char *opname, int opcontext, IDProperty *properties, wmKeyMap **keymap_r)
+static wmKeyMapItem *wm_keymap_item_find(const bContext *C, const char *opname, int opcontext, IDProperty *properties, int hotkey, wmKeyMap **keymap_r)
 {
-       wmKeyMapItem *found= wm_keymap_item_find_props(C, opname, opcontext, properties, 1, keymap_r);
+       wmKeyMapItem *found= wm_keymap_item_find_props(C, opname, opcontext, properties, 1, hotkey, keymap_r);
 
        if(!found)
-               found= wm_keymap_item_find_props(C, opname, opcontext, properties, 0, keymap_r);
+               found= wm_keymap_item_find_props(C, opname, opcontext, properties, 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)
 {
-       wmKeyMapItem *kmi= wm_keymap_item_find(C, opname, opcontext, properties, NULL);
+       wmKeyMapItem *kmi= wm_keymap_item_find(C, opname, opcontext, properties, 0, NULL);
        
        if(kmi) {
                WM_keymap_item_to_string(kmi, str, len);
@@ -487,9 +491,9 @@ char *WM_key_event_operator_string(const bContext *C, const char *opname, int op
        return NULL;
 }
 
-int WM_key_event_operator_id(const bContext *C, const char *opname, int opcontext, IDProperty *properties, wmKeyMap **keymap_r)
+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, keymap_r);
+       wmKeyMapItem *kmi= wm_keymap_item_find(C, opname, opcontext, properties, hotkey, keymap_r);
        
        if(kmi)
                return kmi->id;
@@ -708,8 +712,9 @@ wmKeyMapItem *WM_keymap_item_find_id(wmKeyMap *keymap, int id)
        wmKeyMapItem *kmi;
        
        for (kmi=keymap->items.first; kmi; kmi=kmi->next) {
-               if (kmi->id == id)
+               if (kmi->id == id) {
                        return kmi;
+               }
        }
        
        return NULL;
@@ -747,6 +752,7 @@ wmKeyMap *WM_keymap_guess_opname(const bContext *C, char *opname)
        else if (strstr(opname, "OBJECT_OT")) {
                km = WM_keymap_find_all(C, "Object Mode", 0, 0);
        }
+
        
        /* Editing Modes */
        else if (strstr(opname, "MESH_OT")) {
@@ -848,5 +854,34 @@ wmKeyMap *WM_keymap_guess_opname(const bContext *C, char *opname)
                km = WM_keymap_find_all(C, "Console", sl->spacetype, 0);
        }
        
+       /* Transform */
+       else if (strstr(opname, "TRANSFORM_OT")) {
+               
+               /* check for relevant editor */
+               switch(sl->spacetype) {
+                       case SPACE_VIEW3D:
+                               km = WM_keymap_find_all(C, "3D View", sl->spacetype, 0);
+                               break;
+                       case SPACE_IPO:
+                               km = WM_keymap_find_all(C, "Graph Editor", sl->spacetype, 0);
+                               break;
+                       case SPACE_ACTION:
+                               km = WM_keymap_find_all(C, "Dopesheet", sl->spacetype, 0);
+                               break;
+                       case SPACE_NLA:
+                               km = WM_keymap_find_all(C, "NLA Editor", sl->spacetype, 0);
+                               break;
+                       case SPACE_IMAGE:
+                               km = WM_keymap_find_all(C, "UV Editor", sl->spacetype, 0);
+                               break;
+                       case SPACE_NODE:
+                               km = WM_keymap_find_all(C, "Node Editor", sl->spacetype, 0);
+                               break;
+                       case SPACE_SEQ:
+                               km = WM_keymap_find_all(C, "Sequencer", sl->spacetype, 0);
+                               break;
+               }
+       }
+       
        return km;
 }