UI: Improved Operator to Delete Custom Themes
Changes to python operators that add and remove custom themes. Removal gets poll function, separate name and description, and confirmation. Pull Request: https://projects.blender.org/blender/blender/pulls/118775
This commit is contained in:
committed by
Harley Acheson
parent
a9d5833f29
commit
a0a2e7e0dd
@@ -563,13 +563,40 @@ class AddPresetNodeColor(AddPresetBase, Operator):
|
||||
|
||||
|
||||
class AddPresetInterfaceTheme(AddPresetBase, Operator):
|
||||
"""Add or remove a theme preset"""
|
||||
"""Add a custom theme to the preset list"""
|
||||
bl_idname = "wm.interface_theme_preset_add"
|
||||
bl_label = "Add Theme Preset"
|
||||
bl_label = "Add Theme"
|
||||
preset_menu = "USERPREF_MT_interface_theme_presets"
|
||||
preset_subdir = "interface_theme"
|
||||
|
||||
|
||||
class RemovePresetInterfaceTheme(AddPresetBase, Operator):
|
||||
"""Remove a custom theme from the preset list"""
|
||||
bl_idname = "wm.interface_theme_preset_remove"
|
||||
bl_label = "Remove Theme"
|
||||
preset_menu = "USERPREF_MT_interface_theme_presets"
|
||||
preset_subdir = "interface_theme"
|
||||
|
||||
remove_active: BoolProperty(
|
||||
default=True,
|
||||
options={'HIDDEN', 'SKIP_SAVE'},
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
from bpy.utils import is_path_builtin
|
||||
preset_menu_class = getattr(bpy.types, cls.preset_menu)
|
||||
name = preset_menu_class.bl_label
|
||||
filepath = bpy.utils.preset_find(name, cls.preset_subdir, ext = ".xml")
|
||||
if not bool(filepath) or is_path_builtin(filepath):
|
||||
cls.poll_message_set("Built-in themes cannot be removed")
|
||||
return False
|
||||
return True
|
||||
|
||||
def invoke(self, context, event):
|
||||
return context.window_manager.invoke_confirm(self, event, title="Remove Custom Theme", confirm_text="Delete")
|
||||
|
||||
|
||||
class AddPresetKeyconfig(AddPresetBase, Operator):
|
||||
"""Add or remove a Key-config Preset"""
|
||||
bl_idname = "wm.keyconfig_preset_add"
|
||||
@@ -811,6 +838,7 @@ classes = (
|
||||
AddPresetFluid,
|
||||
AddPresetHairDynamics,
|
||||
AddPresetInterfaceTheme,
|
||||
RemovePresetInterfaceTheme,
|
||||
AddPresetKeyconfig,
|
||||
AddPresetNodeColor,
|
||||
AddPresetOperator,
|
||||
|
||||
@@ -876,7 +876,7 @@ class USERPREF_PT_theme(ThemePanel, Panel):
|
||||
row = split.row(align=True)
|
||||
row.menu("USERPREF_MT_interface_theme_presets", text=USERPREF_MT_interface_theme_presets.bl_label)
|
||||
row.operator("wm.interface_theme_preset_add", text="", icon='ADD')
|
||||
row.operator("wm.interface_theme_preset_add", text="", icon='REMOVE').remove_active = True
|
||||
row.operator("wm.interface_theme_preset_remove", text="", icon='REMOVE')
|
||||
|
||||
row = split.row(align=True)
|
||||
row.operator("preferences.theme_install", text="Install...", icon='IMPORT')
|
||||
|
||||
Reference in New Issue
Block a user