diff options
Diffstat (limited to 'source/blender/windowmanager/intern/wm_keymap.c')
-rw-r--r-- | source/blender/windowmanager/intern/wm_keymap.c | 75 |
1 files changed, 49 insertions, 26 deletions
diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c index 1d959665f40..ad0dd786791 100644 --- a/source/blender/windowmanager/intern/wm_keymap.c +++ b/source/blender/windowmanager/intern/wm_keymap.c @@ -65,6 +65,8 @@ static void keymap_event_set(wmKeymapItem *kmi, short type, short val, int modif } else { + kmi->shift= kmi->ctrl= kmi->alt= kmi->oskey= 0; + /* defines? */ if(modifier & KM_SHIFT) kmi->shift= 1; @@ -232,7 +234,7 @@ static char *wm_keymap_item_to_string(wmKeymapItem *kmi, char *str, int len) strcat(buf, "Alt "); if(kmi->oskey) - strcat(buf, "OS "); + strcat(buf, "Cmd "); strcat(buf, WM_key_event_string(kmi->type)); BLI_strncpy(str, buf, len); @@ -240,7 +242,7 @@ static char *wm_keymap_item_to_string(wmKeymapItem *kmi, char *str, int len) return str; } -static char *wm_keymap_item_find(ListBase *handlers, const char *opname, int opcontext, IDProperty *properties, char *str, int len) +static wmKeymapItem *wm_keymap_item_find_handlers(ListBase *handlers, const char *opname, int opcontext, IDProperty *properties) { wmEventHandler *handler; wmKeymapItem *kmi; @@ -251,45 +253,66 @@ static char *wm_keymap_item_find(ListBase *handlers, const char *opname, int opc for(kmi=handler->keymap->first; kmi; kmi=kmi->next) if(strcmp(kmi->idname, opname) == 0 && WM_key_event_string(kmi->type)[0]) if(kmi->ptr && IDP_EqualsProperties(properties, kmi->ptr->data)) - return wm_keymap_item_to_string(kmi, str, len); + return kmi; return NULL; } -char *WM_key_event_operator_string(const bContext *C, const char *opname, int opcontext, IDProperty *properties, char *str, int len) +static wmKeymapItem *wm_keymap_item_find(const bContext *C, const char *opname, int opcontext, IDProperty *properties) { - char *found= NULL; + wmKeymapItem *found= NULL; /* look into multiple handler lists to find the item */ if(CTX_wm_window(C)) - if((found= wm_keymap_item_find(&CTX_wm_window(C)->handlers, opname, opcontext, properties, str, len))) - return found; - - if(CTX_wm_area(C)) - if((found= wm_keymap_item_find(&CTX_wm_area(C)->handlers, opname, opcontext, properties, str, len))) - return found; - - if(ELEM(opcontext, WM_OP_EXEC_REGION_WIN, WM_OP_INVOKE_REGION_WIN)) { - if(CTX_wm_area(C)) { - ARegion *ar= CTX_wm_area(C)->regionbase.first; - for(; ar; ar= ar->next) - if(ar->regiontype==RGN_TYPE_WINDOW) - break; - - if(ar) - if((found= wm_keymap_item_find(&ar->handlers, opname, opcontext, properties, str, len))) - return found; + found= wm_keymap_item_find_handlers(&CTX_wm_window(C)->handlers, opname, opcontext, properties); + + + if(CTX_wm_area(C) && found==NULL) + found= wm_keymap_item_find_handlers(&CTX_wm_area(C)->handlers, opname, opcontext, properties); + + if(found==NULL) { + if(ELEM(opcontext, WM_OP_EXEC_REGION_WIN, WM_OP_INVOKE_REGION_WIN)) { + if(CTX_wm_area(C)) { + ARegion *ar= CTX_wm_area(C)->regionbase.first; + for(; ar; ar= ar->next) + if(ar->regiontype==RGN_TYPE_WINDOW) + break; + + if(ar) + found= wm_keymap_item_find_handlers(&ar->handlers, opname, opcontext, properties); + } + } + else { + if(CTX_wm_region(C)) + found= wm_keymap_item_find_handlers(&CTX_wm_region(C)->handlers, opname, opcontext, properties); } } - else { - if(CTX_wm_region(C)) - if((found= wm_keymap_item_find(&CTX_wm_region(C)->handlers, opname, opcontext, properties, str, len))) - return found; + + return found; +} + +char *WM_key_event_operator_string(const bContext *C, const char *opname, int opcontext, IDProperty *properties, char *str, int len) +{ + wmKeymapItem *found= wm_keymap_item_find(C, opname, opcontext, properties); + + if(found) { + wm_keymap_item_to_string(found, str, len); + return str; } return NULL; } +/* searches context and changes keymap item, if found */ +void WM_key_event_operator_change(const bContext *C, const char *opname, int opcontext, IDProperty *properties, short key, short modifier) +{ + wmKeymapItem *found= wm_keymap_item_find(C, opname, opcontext, properties); + + if(found) { + keymap_event_set(found, key, KM_PRESS, modifier, 0); + } +} + /* ********************* */ int WM_key_event_is_tweak(short type) |