diff options
author | Martin Poirier <theeth@yahoo.com> | 2009-12-17 06:32:33 +0300 |
---|---|---|
committer | Martin Poirier <theeth@yahoo.com> | 2009-12-17 06:32:33 +0300 |
commit | fd18f555103efe8ac148ab763965d5595632da3d (patch) | |
tree | de257068c03ac20500c55568c40214c61716caf7 /source/blender/windowmanager/intern/wm_keymap.c | |
parent | c3b978828cc47aca064d8e3e5349ec76e802c844 (diff) |
keymap editor
New unique ID per keymap item (unique inside their keymap) for default and configuration keymaps.
This allows restoring a single user defined kmi to its previous (default or config) values instead of having to restore the whole keymap.
The restore item button is disabled for kmi added by the users (they don't have an ID).
Also fixes a bug in the rna function for add keymap item (parameter order was incorrect, messing adding back saved configurations).
Diffstat (limited to 'source/blender/windowmanager/intern/wm_keymap.c')
-rw-r--r-- | source/blender/windowmanager/intern/wm_keymap.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c index fe5b42a1841..e1f812ee45f 100644 --- a/source/blender/windowmanager/intern/wm_keymap.c +++ b/source/blender/windowmanager/intern/wm_keymap.c @@ -201,6 +201,12 @@ wmKeyMapItem *WM_keymap_add_item(wmKeyMap *keymap, char *idname, int type, int v keymap_event_set(kmi, type, val, modifier, keymodifier); keymap_properties_set(kmi); + + if ((keymap->flag & KEYMAP_USER) == 0) { + keymap->kmi_id++; + kmi->id = keymap->kmi_id; + } + return kmi; } @@ -291,6 +297,11 @@ wmKeyMapItem *WM_modalkeymap_add_item(wmKeyMap *km, int type, int val, int modif keymap_event_set(kmi, type, val, modifier, keymodifier); + if ((km->flag & KEYMAP_USER) == 0) { + km->kmi_id++; + kmi->id = km->kmi_id; + } + return kmi; } @@ -545,6 +556,55 @@ wmKeyMap *WM_keymap_copy_to_user(wmKeyMap *keymap) return usermap; } +void WM_keymap_restore_item_to_default(bContext *C, wmKeyMap *keymap, wmKeyMapItem *kmi) +{ + wmWindowManager *wm = CTX_wm_manager(C); + wmKeyConfig *keyconf; + wmKeyMap *km = NULL; + + /* look in user key config */ + keyconf= wm_keyconfig_list_find(&wm->keyconfigs, U.keyconfigstr); + if(keyconf) { + km= WM_keymap_list_find(&keyconf->keymaps, keymap->idname, keymap->spaceid, keymap->regionid); + } + + if (!km) { + /* or from default */ + km= WM_keymap_list_find(&wm->defaultconf->keymaps, keymap->idname, keymap->spaceid, keymap->regionid); + } + + if (km) { + wmKeyMapItem *orig; + + for (orig = km->items.first; orig; orig = orig->next) { + if (orig->id == kmi->id) + break; + } + + if (orig) { + if(strcmp(orig->idname, kmi->idname) != 0) { + BLI_strncpy(kmi->idname, orig->idname, sizeof(kmi->idname)); + + WM_keymap_properties_reset(kmi); + } + kmi->properties= IDP_CopyProperty(orig->properties); + kmi->ptr->data= kmi->properties; + + kmi->propvalue = orig->propvalue; + kmi->type = orig->type; + kmi->val = orig->val; + kmi->shift = orig->shift; + kmi->ctrl = orig->ctrl; + kmi->alt = orig->alt; + kmi->oskey = orig->oskey; + kmi->keymodifier = orig->keymodifier; + kmi->maptype = orig->maptype; + + } + + } +} + void WM_keymap_restore_to_default(wmKeyMap *keymap) { wmKeyMap *usermap; |