diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2011-08-06 00:45:26 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2011-08-06 00:45:26 +0400 |
commit | e6e4c7ef8bd53b06c879302bbfd3d6a00c6c48af (patch) | |
tree | 4147f9502e965705092d773380d70792633daffa /release/scripts | |
parent | 7368298a45f96667a548e10cfe9d227fcf18e114 (diff) |
KEYMAP REFACTORING
Diff Keymaps
User edited keymaps now no longer override the builtin keymaps entirely, but
rather save only the difference and reapply those changes. This means they can
stay better in sync when the builtin keymaps change. The diff/patch algorithm
is not perfect, but better for the common case where only a few items are changed
rather than entire keymaps The main weakness is that if a builtin keymap item
changes, user modification of that item may need to be redone in some cases.
Keymap Editor
The most noticeable change here is that there is no longer an "Edit" button for
keymaps, all are editable immediately, but a "Restore" buttons shows for keymaps
and items that have been edited. Shortcuts for addons can also be edited in the
keymap editor.
Addons
Addons now should only modify the new addon keyconfiguration, the keymap items
there will be added to the builtin ones for handling events, and not get lost
when starting new files. Example code of register/unregister:
km = wm.keyconfigs.addon.keymaps.new("3D View", space_type="VIEW_3D")
km.keymap_items.new('my.operator', 'ESC', 'PRESS')
km = wm.keyconfigs.addon.keymaps["3D View"]
km.keymap_items.remove(km.keymap_items["my.operator"])
Compatibility
The changes made are not forward compatible, i.e. if you save user preferences
with newer versions, older versions will not have key configuration changes that
were made.
Diffstat (limited to 'release/scripts')
-rw-r--r-- | release/scripts/startup/bl_ui/space_userpref_keymap.py | 53 |
1 files changed, 19 insertions, 34 deletions
diff --git a/release/scripts/startup/bl_ui/space_userpref_keymap.py b/release/scripts/startup/bl_ui/space_userpref_keymap.py index 585c3cffcb9..5658cc96281 100644 --- a/release/scripts/startup/bl_ui/space_userpref_keymap.py +++ b/release/scripts/startup/bl_ui/space_userpref_keymap.py @@ -188,10 +188,10 @@ class InputKeyMapPanel: if km.is_modal: row.label(text="", icon='LINKED') - if km.is_user_defined: + if km.is_user_modified: row.operator("wm.keymap_restore", text="Restore") else: - row.operator("wm.keymap_edit", text="Edit") + row.label() if km.show_expanded_children: if children: @@ -212,7 +212,6 @@ class InputKeyMapPanel: # "Add New" at end of keymap item list col = self.indented_layout(col, level + 1) subcol = col.split(percentage=0.2).column() - subcol.enabled = km.is_user_defined subcol.operator("wm.keyitem_add", text="Add New", icon='ZOOMIN') col.separator() @@ -243,7 +242,7 @@ class InputKeyMapPanel: col = self.indented_layout(layout, level) - if km.is_user_defined: + if kmi.show_expanded: col = col.column(align=True) box = col.box() else: @@ -256,7 +255,6 @@ class InputKeyMapPanel: row.prop(kmi, "show_expanded", text="", emboss=False) row = split.row() - row.enabled = km.is_user_defined row.prop(kmi, "active", text="", emboss=False) if km.is_modal: @@ -265,7 +263,6 @@ class InputKeyMapPanel: row.label(text=kmi.name) row = split.row() - row.enabled = km.is_user_defined row.prop(kmi, "map_type", text="") if map_type == 'KEYBOARD': row.prop(kmi, "type", text="", full_event=True) @@ -282,18 +279,17 @@ class InputKeyMapPanel: else: row.label() - if not kmi.is_user_defined: + if (not kmi.is_user_defined) and kmi.is_user_modified: op = row.operator("wm.keyitem_restore", text="", icon='BACK') op.item_id = kmi.id - op = row.operator("wm.keyitem_remove", text="", icon='X') - op.item_id = kmi.id + else: + op = row.operator("wm.keyitem_remove", text="", icon='X') + op.item_id = kmi.id # Expanded, additional event settings if kmi.show_expanded: box = col.box() - box.enabled = km.is_user_defined - if map_type not in {'TEXTINPUT', 'TIMER'}: split = box.split(percentage=0.4) sub = split.row() @@ -352,10 +348,10 @@ class InputKeyMapPanel: row.label() row.label() - if km.is_user_defined: + if km.is_user_modified: row.operator("wm.keymap_restore", text="Restore") else: - row.operator("wm.keymap_edit", text="Edit") + row.label() for kmi in filtered_items: self.draw_kmi(display_keymaps, kc, km, kmi, col, 1) @@ -363,7 +359,6 @@ class InputKeyMapPanel: # "Add New" at end of keymap item list col = self.indented_layout(layout, 1) subcol = col.split(percentage=0.2).column() - subcol.enabled = km.is_user_defined subcol.operator("wm.keyitem_add", text="Add New", icon='ZOOMIN') def draw_hierarchy(self, display_keymaps, layout): @@ -372,8 +367,7 @@ class InputKeyMapPanel: def draw_keymaps(self, context, layout): wm = context.window_manager - kc = wm.keyconfigs.active - defkc = wm.keyconfigs.default + kc = wm.keyconfigs.user col = layout.column() sub = col.column() @@ -398,7 +392,7 @@ class InputKeyMapPanel: col.separator() - display_keymaps = _merge_keymaps(kc, defkc) + display_keymaps = _merge_keymaps(kc, kc) if context.space_data.filter_text != "": filter_text = context.space_data.filter_text.lower() self.draw_filtered(display_keymaps, filter_text, col) @@ -609,7 +603,7 @@ class WM_OT_keyconfig_export(bpy.types.Operator): # Generate a list of keymaps to export: # - # First add all user_defined keymaps (found in inputs.edited_keymaps list), + # First add all user_modified keymaps (found in keyconfigs.user.keymaps list), # then add all remaining keymaps from the currently active custom keyconfig. # # This will create a final list of keymaps that can be used as a 'diff' against @@ -619,7 +613,9 @@ class WM_OT_keyconfig_export(bpy.types.Operator): class FakeKeyConfig(): keymaps = [] edited_kc = FakeKeyConfig() - edited_kc.keymaps.extend(context.user_preferences.inputs.edited_keymaps) + for km in wm.keyconfigs.user.keymaps: + if km.is_user_modified: + edited_kc.keymaps.append(km) # merge edited keymaps with non-default keyconfig, if it exists if kc != wm.keyconfigs.default: export_keymaps = _merge_keymaps(edited_kc, kc) @@ -669,17 +665,6 @@ class WM_OT_keyconfig_export(bpy.types.Operator): return {'RUNNING_MODAL'} -class WM_OT_keymap_edit(bpy.types.Operator): - "Edit stored key map" - bl_idname = "wm.keymap_edit" - bl_label = "Edit Key Map" - - def execute(self, context): - km = context.keymap - km.copy_to_user() - return {'FINISHED'} - - class WM_OT_keymap_restore(bpy.types.Operator): "Restore key map(s)" bl_idname = "wm.keymap_restore" @@ -691,7 +676,7 @@ class WM_OT_keymap_restore(bpy.types.Operator): wm = context.window_manager if self.all: - for km in wm.keyconfigs.default.keymaps: + for km in wm.keyconfigs.user.keymaps: km.restore_to_default() else: km = context.keymap @@ -710,13 +695,13 @@ class WM_OT_keyitem_restore(bpy.types.Operator): @classmethod def poll(cls, context): keymap = getattr(context, "keymap", None) - return keymap and keymap.is_user_defined + return keymap def execute(self, context): km = context.keymap kmi = km.keymap_items.from_id(self.item_id) - if not kmi.is_user_defined: + if (not kmi.is_user_defined) and kmi.is_user_modified: km.restore_item_to_default(kmi) return {'FINISHED'} @@ -753,7 +738,7 @@ class WM_OT_keyitem_remove(bpy.types.Operator): @classmethod def poll(cls, context): - return hasattr(context, "keymap") and context.keymap.is_user_defined + return hasattr(context, "keymap") def execute(self, context): km = context.keymap |