Theme: ensure unique theme names, increase name size to 64

Ensure unique names when setting the name and with versioning.
This commit is contained in:
Campbell Barton
2024-04-11 17:43:46 +10:00
parent adbec9eea9
commit 793b99ca7c
4 changed files with 23 additions and 3 deletions

View File

@@ -29,7 +29,7 @@ extern "C" {
/* Blender file format version. */
#define BLENDER_FILE_VERSION BLENDER_VERSION
#define BLENDER_FILE_SUBVERSION 13
#define BLENDER_FILE_SUBVERSION 14
/* Minimum Blender version that supports reading file written with the current
* version. Older Blender versions will test this and cancel loading the file, showing a warning to

View File

@@ -145,6 +145,11 @@ static void do_versions_theme(const UserDef *userdef, bTheme *btheme)
FROM_DEFAULT_V4_UCHAR(space_console.console_cursor);
}
if (!USER_VERSION_ATLEAST(402, 14)) {
BLI_uniquename(
&userdef->themes, btheme, "Theme", '.', offsetof(bTheme, name), sizeof(btheme->name));
}
/**
* Always bump subversion in BKE_blender_version.h when adding versioning
* code here, and wrap it inside a USER_VERSION_ATLEAST check.

View File

@@ -483,12 +483,15 @@ typedef struct ThemeStripColor {
/**
* A theme.
*
* \note Currently only a single theme is ever used at once.
* \note Currently only the first theme is used at once.
* Different theme presets are stored as external files now.
*/
typedef struct bTheme {
struct bTheme *next, *prev;
char name[32];
/** #MAX_NAME. */
char name[64];
/* NOTE: Values after `name` are copied when resetting the default theme. */
ThemeUI tui;
@@ -840,6 +843,10 @@ typedef struct UserDef {
/** Startup application template. */
char app_template[64];
/**
* A list of themes (#bTheme), the first is only used currently.
* But there may be multiple themes in the list.
*/
struct ListBase themes;
struct ListBase uifonts;
struct ListBase uistyles;

View File

@@ -1021,6 +1021,13 @@ static int rna_lang_enum_properties_get_no_international(PointerRNA * /*ptr*/)
}
# endif
static void rna_Theme_name_set(PointerRNA *ptr, const char *value)
{
bTheme *btheme = static_cast<bTheme *>(ptr->data);
STRNCPY_UTF8(btheme->name, value);
BLI_uniquename(&U.themes, btheme, "Theme", '.', offsetof(bTheme, name), sizeof(btheme->name));
}
static void rna_Addon_module_set(PointerRNA *ptr, const char *value)
{
bAddon *addon = (bAddon *)ptr->data;
@@ -4287,6 +4294,7 @@ static void rna_def_userdef_themes(BlenderRNA *brna)
prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
RNA_def_property_ui_text(prop, "Name", "Name of the theme");
RNA_def_property_string_funcs(prop, nullptr, nullptr, "rna_Theme_name_set");
RNA_def_struct_name_property(srna, prop);
/* XXX: for now putting this in presets is silly - its just Default */
RNA_def_property_flag(prop, PROP_SKIP_SAVE);