Theme: store the last loaded preset as a filepath
This is needed so we can reliably know which extension is associated with a theme, so a theme can be refreshed on update and cleared when uninstalled, needed to resolve !120289.
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user