UI: Improved Operator to Delete Custom Keyconfigs #118778
|
@ -375,7 +375,7 @@ def draw_keymaps(context, layout):
|
||||||
|
|
||||||
rowsub.menu("USERPREF_MT_keyconfigs", text=text)
|
rowsub.menu("USERPREF_MT_keyconfigs", text=text)
|
||||||
rowsub.operator("wm.keyconfig_preset_add", text="", icon='ADD')
|
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 = split.row(align=True)
|
||||||
rowsub.operator("preferences.keyconfig_import", text="Import...", icon='IMPORT')
|
rowsub.operator("preferences.keyconfig_import", text="Import...", icon='IMPORT')
|
||||||
|
|
|
@ -598,9 +598,9 @@ class RemovePresetInterfaceTheme(AddPresetBase, Operator):
|
||||||
|
|
||||||
|
|
||||||
class AddPresetKeyconfig(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_idname = "wm.keyconfig_preset_add"
|
||||||
bl_label = "Add Keyconfig Preset"
|
bl_label = "Add Custom Keymap Configuration"
|
||||||
Harley marked this conversation as resolved
Outdated
|
|||||||
preset_menu = "USERPREF_MT_keyconfigs"
|
preset_menu = "USERPREF_MT_keyconfigs"
|
||||||
preset_subdir = "keyconfig"
|
preset_subdir = "keyconfig"
|
||||||
|
|
||||||
|
@ -608,16 +608,42 @@ class AddPresetKeyconfig(AddPresetBase, Operator):
|
||||||
bpy.ops.preferences.keyconfig_export(filepath=filepath)
|
bpy.ops.preferences.keyconfig_export(filepath=filepath)
|
||||||
bpy.utils.keyconfig_set(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):
|
def pre_cb(self, context):
|
||||||
keyconfigs = bpy.context.window_manager.keyconfigs
|
keyconfigs = bpy.context.window_manager.keyconfigs
|
||||||
if self.remove_active:
|
preset_menu_class = getattr(bpy.types, self.preset_menu)
|
||||||
preset_menu_class = getattr(bpy.types, self.preset_menu)
|
preset_menu_class.bl_label = keyconfigs.active.name
|
||||||
preset_menu_class.bl_label = keyconfigs.active.name
|
|
||||||
|
|
||||||
def post_cb(self, context):
|
def post_cb(self, context):
|
||||||
keyconfigs = bpy.context.window_manager.keyconfigs
|
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):
|
class AddPresetOperator(AddPresetBase, Operator):
|
||||||
|
@ -840,6 +866,7 @@ classes = (
|
||||||
AddPresetInterfaceTheme,
|
AddPresetInterfaceTheme,
|
||||||
RemovePresetInterfaceTheme,
|
RemovePresetInterfaceTheme,
|
||||||
AddPresetKeyconfig,
|
AddPresetKeyconfig,
|
||||||
|
RemovePresetKeyconfig,
|
||||||
AddPresetNodeColor,
|
AddPresetNodeColor,
|
||||||
AddPresetOperator,
|
AddPresetOperator,
|
||||||
AddPresetRender,
|
AddPresetRender,
|
||||||
|
|
Loading…
Reference in New Issue
remove_active
is unused now.Also, seems it should be fully removed from the
AddPresetKeyconfig
operator, which seems to mean removingpre_cb
andpost_cb
?