UI: Improved Operator to Delete Custom Keyconfigs #118778

Merged
Harley Acheson merged 1 commits from Harley/blender:RemoveCustomKeyconfig into main 2024-03-14 22:40:14 +01:00
2 changed files with 35 additions and 8 deletions

View File

@ -375,7 +375,7 @@ def draw_keymaps(context, layout):
rowsub.menu("USERPREF_MT_keyconfigs", text=text)
rowsub.operator("wm.keyconfig_preset_add", text="", icon='ADD')
rowsub.operator("wm.keyconfig_preset_add", text="", icon='REMOVE').remove_active = True
rowsub.operator("wm.keyconfig_preset_remove", text="", icon='REMOVE')
rowsub = split.row(align=True)
rowsub.operator("preferences.keyconfig_import", text="Import...", icon='IMPORT')

View File

@ -598,9 +598,9 @@ class RemovePresetInterfaceTheme(AddPresetBase, Operator):
class AddPresetKeyconfig(AddPresetBase, Operator):
"""Add or remove a Key-config Preset"""
"""Add a custom keymap configuration to the preset list"""
bl_idname = "wm.keyconfig_preset_add"
bl_label = "Add Keyconfig Preset"
bl_label = "Add Custom Keymap Configuration"
Harley marked this conversation as resolved Outdated

remove_active is unused now.

Also, seems it should be fully removed from the AddPresetKeyconfig operator, which seems to mean removing pre_cb and post_cb?

`remove_active` is unused now. Also, seems it should be fully removed from the `AddPresetKeyconfig` operator, which seems to mean removing `pre_cb` and `post_cb`?
preset_menu = "USERPREF_MT_keyconfigs"
preset_subdir = "keyconfig"
@ -608,16 +608,42 @@ class AddPresetKeyconfig(AddPresetBase, Operator):
bpy.ops.preferences.keyconfig_export(filepath=filepath)
bpy.utils.keyconfig_set(filepath)
class RemovePresetKeyconfig(AddPresetBase, Operator):
"""Remove a custom keymap configuration from the preset list"""
bl_idname = "wm.keyconfig_preset_remove"
bl_label = "Remove Keymap Configuration"
preset_menu = "USERPREF_MT_keyconfigs"
preset_subdir = "keyconfig"
remove_active: BoolProperty(
default=True,
options={'HIDDEN', 'SKIP_SAVE'},
)
@classmethod
def poll(cls, context):
from bpy.utils import is_path_builtin
keyconfigs = bpy.context.window_manager.keyconfigs
preset_menu_class = getattr(bpy.types, cls.preset_menu)
name = keyconfigs.active.name
filepath = bpy.utils.preset_find(name, cls.preset_subdir, ext = ".py")
if not bool(filepath) or is_path_builtin(filepath):
cls.poll_message_set("Built-in keymap configurations cannot be removed")
return False
return True
def pre_cb(self, context):
keyconfigs = bpy.context.window_manager.keyconfigs
if self.remove_active:
preset_menu_class = getattr(bpy.types, self.preset_menu)
preset_menu_class.bl_label = keyconfigs.active.name
preset_menu_class = getattr(bpy.types, self.preset_menu)
preset_menu_class.bl_label = keyconfigs.active.name
def post_cb(self, context):
keyconfigs = bpy.context.window_manager.keyconfigs
if self.remove_active:
keyconfigs.remove(keyconfigs.active)
keyconfigs.remove(keyconfigs.active)
def invoke(self, context, event):
return context.window_manager.invoke_confirm(self, event, title="Remove Keymap Configuration", confirm_text="Delete")
class AddPresetOperator(AddPresetBase, Operator):
@ -840,6 +866,7 @@ classes = (
AddPresetInterfaceTheme,
RemovePresetInterfaceTheme,
AddPresetKeyconfig,
RemovePresetKeyconfig,
AddPresetNodeColor,
AddPresetOperator,
AddPresetRender,