diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-03-27 09:15:12 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-03-27 09:38:13 +0300 |
commit | 3b59c111821b8002020ee76edf25258d7c38b381 (patch) | |
tree | 0800af82af0f1293352de69bdc9fd4c55b214bf4 /release/scripts/startup/bl_ui/space_toolsystem_common.py | |
parent | 95247b4b14ea530a90a920c10b13b8912a9952b6 (diff) |
Fix T66655: Add-on tool keymap not working after restart
- Use addon keyconfig for registered tools so reloading the keymap
doesn't clear them.
- Ensure there is a default keymap, needed for addon keymaps
to be available in the user keyconfig.
Diffstat (limited to 'release/scripts/startup/bl_ui/space_toolsystem_common.py')
-rw-r--r-- | release/scripts/startup/bl_ui/space_toolsystem_common.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_common.py b/release/scripts/startup/bl_ui/space_toolsystem_common.py index 796c089906d..ace39a4cdf3 100644 --- a/release/scripts/startup/bl_ui/space_toolsystem_common.py +++ b/release/scripts/startup/bl_ui/space_toolsystem_common.py @@ -449,19 +449,27 @@ class ToolSelectPanelHelper: return context.button_operator.name @classmethod - def _km_action_simple(cls, kc, context_descr, label, keymap_fn): + def _km_action_simple(cls, kc_default, kc, context_descr, label, keymap_fn): km_idname = f"{cls.keymap_prefix:s} {context_descr:s}, {label:s}" km = kc.keymaps.get(km_idname) + km_kwargs = dict(space_type=cls.bl_space_type, region_type='WINDOW', tool=True) if km is None: - km = kc.keymaps.new(km_idname, space_type=cls.bl_space_type, region_type='WINDOW', tool=True) + km = kc.keymaps.new(km_idname, **km_kwargs) keymap_fn[0](km) + print(len(km.keymap_items)) + if km.keymap_items: + print(km.keymap_items[0].to_string()) keymap_fn[0] = km.name + # Ensure we have a default key map, so the add-ons keymap is properly overlayed. + if kc_default is not kc: + kc_default.keymaps.new(km_idname, **km_kwargs) + @classmethod def register(cls): wm = bpy.context.window_manager # Write into defaults, users may modify in preferences. - kc = wm.keyconfigs.default + kc_default = wm.keyconfigs.default # Track which tool-group was last used for non-active groups. # Blender stores the active tool-group index. @@ -470,7 +478,7 @@ class ToolSelectPanelHelper: cls._tool_group_active = {} # ignore in background mode - if kc is None: + if kc_default is None: return for context_mode, tools in cls.tools_all(): @@ -482,7 +490,7 @@ class ToolSelectPanelHelper: for item in cls._tools_flatten_with_keymap(tools): keymap_data = item.keymap if callable(keymap_data[0]): - cls._km_action_simple(kc, context_descr, item.label, keymap_data) + cls._km_action_simple(kc_default, kc_default, context_descr, item.label, keymap_data) @classmethod def keymap_ui_hierarchy(cls, context_mode): |