diff --git a/scripts/startup/bl_operators/presets.py b/scripts/startup/bl_operators/presets.py index 66f0788beb5..9f16ee259b6 100644 --- a/scripts/startup/bl_operators/presets.py +++ b/scripts/startup/bl_operators/presets.py @@ -653,6 +653,8 @@ class SavePresetInterfaceTheme(AddPresetBase, Operator): traceback.print_exc() return {'CANCELLED'} + context.preferences.themes[0].filepath = filepath + return {'FINISHED'} def invoke(self, context, event): diff --git a/scripts/startup/bl_ui/space_userpref.py b/scripts/startup/bl_ui/space_userpref.py index d8074369052..3af47e8e58e 100644 --- a/scripts/startup/bl_ui/space_userpref.py +++ b/scripts/startup/bl_ui/space_userpref.py @@ -863,18 +863,34 @@ class USERPREF_MT_interface_theme_presets(Menu): def reset_cb(context): bpy.ops.preferences.reset_default_theme() + @staticmethod + def post_cb(context, filepath): + context.preferences.themes[0].filepath = filepath + class USERPREF_PT_theme(ThemePanel, Panel): bl_label = "Themes" bl_options = {'HIDE_HEADER'} - def draw(self, _context): + def draw(self, context): + import os + layout = self.layout split = layout.split(factor=0.6) row = split.row(align=True) - row.menu("USERPREF_MT_interface_theme_presets", text=USERPREF_MT_interface_theme_presets.bl_label) + + # Unlike most presets (which use the classes bl_label), + # themes store the path, use this when set. + if filepath := context.preferences.themes[0].filepath: + preset_label = bpy.path.display_name(os.path.basename(filepath)) + else: + preset_label = USERPREF_MT_interface_theme_presets.bl_label + + row.menu("USERPREF_MT_interface_theme_presets", text=preset_label) + del filepath, preset_label + row.operator("wm.interface_theme_preset_add", text="", icon='ADD') row.operator("wm.interface_theme_preset_remove", text="", icon='REMOVE') row.operator("wm.interface_theme_preset_save", text="", icon='FILE_TICK') diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h index db0d6fa5cee..a90a5d81974 100644 --- a/source/blender/makesdna/DNA_userdef_types.h +++ b/source/blender/makesdna/DNA_userdef_types.h @@ -493,6 +493,16 @@ typedef struct bTheme { /* NOTE: Values after `name` are copied when resetting the default theme. */ + /** + * The file-path for the preset that was loaded into this theme. + * + * This is needed so it's possible to know if updating or removing a theme preset + * should apply changes to the current theme. + * + * #FILE_MAX. + */ + char filepath[1024]; + ThemeUI tui; /** diff --git a/source/blender/makesrna/intern/rna_userdef.cc b/source/blender/makesrna/intern/rna_userdef.cc index 3dfafa43dea..ae2c1ad3c27 100644 --- a/source/blender/makesrna/intern/rna_userdef.cc +++ b/source/blender/makesrna/intern/rna_userdef.cc @@ -4301,6 +4301,11 @@ static void rna_def_userdef_themes(BlenderRNA *brna) /* XXX: for now putting this in presets is silly - its just Default */ RNA_def_property_flag(prop, PROP_SKIP_SAVE); + prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH); + RNA_def_property_string_sdna(prop, nullptr, "filepath"); + RNA_def_property_ui_text( + prop, "File Path", "The path to the preset loaded into this theme (if any)"); + prop = RNA_def_property(srna, "theme_area", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, nullptr, "active_theme_area"); RNA_def_property_flag(prop, PROP_SKIP_SAVE);