diff options
-rw-r--r-- | release/scripts/ui/space_userpref.py | 21 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_windowmanager_types.h | 6 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_wm.c | 5 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_wm_api.c | 12 | ||||
-rw-r--r-- | source/blender/windowmanager/WM_api.h | 1 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_keymap.c | 60 |
6 files changed, 101 insertions, 4 deletions
diff --git a/release/scripts/ui/space_userpref.py b/release/scripts/ui/space_userpref.py index ed4d02cd919..d50c38f0e20 100644 --- a/release/scripts/ui/space_userpref.py +++ b/release/scripts/ui/space_userpref.py @@ -1365,6 +1365,7 @@ class USERPREF_PT_input(bpy.types.Panel): else: row.label() + row.operator("wm.keyitem_restore", text="", icon='BACK') row.operator("wm.keyitem_remove", text="", icon='X') # Expanded, additional event settings @@ -1666,7 +1667,25 @@ class WM_OT_keymap_restore(bpy.types.Operator): return ('FINISHED',) +class WM_OT_keyitem_restore(bpy.types.Operator): + "Restore key map item." + bl_idname = "wm.keyitem_restore" + bl_label = "Restore Key Map Item" + def poll(self, context): + kmi = context.keyitem + km = context.keymap + return km and kmi and kmi.id != 0 + + def execute(self, context): + wm = context.manager + kmi = context.keyitem + km = context.keymap + + km.restore_item_to_default(kmi) + + return ('FINISHED',) + class WM_OT_keyitem_add(bpy.types.Operator): "Add key map item." bl_idname = "wm.keyitem_add" @@ -1699,4 +1718,4 @@ bpy.ops.add(WM_OT_keymap_edit) bpy.ops.add(WM_OT_keymap_restore) bpy.ops.add(WM_OT_keyitem_add) bpy.ops.add(WM_OT_keyitem_remove) - +bpy.ops.add(WM_OT_keyitem_restore) diff --git a/source/blender/makesdna/DNA_windowmanager_types.h b/source/blender/makesdna/DNA_windowmanager_types.h index c17ae1c53c8..9e47a6f1d89 100644 --- a/source/blender/makesdna/DNA_windowmanager_types.h +++ b/source/blender/makesdna/DNA_windowmanager_types.h @@ -262,7 +262,9 @@ typedef struct wmKeyMapItem { short flag; /* runtime */ - short maptype, pad[2]; /* keymap editor */ + short maptype; /* keymap editor */ + short id; /* unique identifier */ + short pad; struct PointerRNA *ptr; /* rna pointer to access properties */ } wmKeyMapItem; @@ -281,7 +283,7 @@ typedef struct wmKeyMap { short regionid; /* see above */ short flag; /* general flags */ - short pad; + short kmi_id; /* last kmi id */ /* runtime */ int (*poll)(struct bContext *); /* verify if enabled in the current context */ diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c index 7809c3a8c34..09adb642e58 100644 --- a/source/blender/makesrna/intern/rna_wm.c +++ b/source/blender/makesrna/intern/rna_wm.c @@ -944,6 +944,11 @@ static void rna_def_keyconfig(BlenderRNA *brna) RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_KeyMapItem_value_itemf"); RNA_def_property_ui_text(prop, "Value", ""); + prop= RNA_def_property(srna, "id", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "id"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "id", "ID of the item."); + prop= RNA_def_property(srna, "any", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_funcs(prop, "rna_KeyMapItem_any_getf", "rna_KeyMapItem_any_setf"); RNA_def_property_ui_text(prop, "Any", "Any modifier keys pressed."); diff --git a/source/blender/makesrna/intern/rna_wm_api.c b/source/blender/makesrna/intern/rna_wm_api.c index 47d15c87596..94a689c9f1c 100644 --- a/source/blender/makesrna/intern/rna_wm_api.c +++ b/source/blender/makesrna/intern/rna_wm_api.c @@ -113,7 +113,12 @@ static wmKeyMapItem *rna_KeyMap_add_modal_item(wmKeyMap *km, bContext *C, Report return WM_modalkeymap_add_item(km, type, value, modifier, keymodifier, propvalue); } -static wmKeyMapItem *rna_KeyMap_add_item(wmKeyMap *km, ReportList *reports, char *idname, int type, int any, int value, int shift, int ctrl, int alt, int oskey, int keymodifier) +static void rna_keymap_restore_item_to_default(wmKeyMap *km, bContext *C, wmKeyMapItem *kmi) +{ + WM_keymap_restore_item_to_default(C, km, kmi); +} + +static wmKeyMapItem *rna_KeyMap_add_item(wmKeyMap *km, ReportList *reports, char *idname, int type, int value, int any, int shift, int ctrl, int alt, int oskey, int keymodifier) { // wmWindowManager *wm = CTX_wm_manager(C); int modifier= 0; @@ -276,6 +281,11 @@ void RNA_api_keymap(StructRNA *srna) RNA_def_function_return(func, parm); func= RNA_def_function(srna, "restore_to_default", "WM_keymap_restore_to_default"); + + func= RNA_def_function(srna, "restore_item_to_default", "rna_keymap_restore_item_to_default"); + RNA_def_function_flag(func, FUNC_USE_CONTEXT); + parm= RNA_def_pointer(func, "item", "KeyMapItem", "Item", ""); + RNA_def_property_flag(parm, PROP_REQUIRED); } #endif diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 66ede3f6ba6..e90360fde45 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -114,6 +114,7 @@ int WM_keymap_user_init(struct wmWindowManager *wm, struct wmKeyMap *keymap); wmKeyMap *WM_keymap_copy_to_user(struct wmKeyMap *keymap); void WM_keymap_restore_to_default(struct wmKeyMap *keymap); void WM_keymap_properties_reset(struct wmKeyMapItem *kmi); +void WM_keymap_restore_item_to_default(struct bContext *C, struct wmKeyMap *keymap, struct wmKeyMapItem *kmi); wmKeyMap *WM_modalkeymap_add(struct wmKeyConfig *keyconf, char *idname, struct EnumPropertyItem *items); wmKeyMap *WM_modalkeymap_get(struct wmKeyConfig *keyconf, char *idname); 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; |