Preferences: don't store preferences in the startup
Simplify preferences by removing the ability to load them from either the startup.blend or userpref.blend. Also simplifies updating default preferences by moving them to a struct definition.
This commit is contained in:
@@ -52,6 +52,7 @@ struct UserDef *BKE_blendfile_userdef_read(const char *filepath, struct ReportLi
|
||||
struct UserDef *BKE_blendfile_userdef_read_from_memory(const void *filebuf,
|
||||
int filelength,
|
||||
struct ReportList *reports);
|
||||
struct UserDef *BKE_blendfile_userdef_from_defaults(void);
|
||||
|
||||
bool BKE_blendfile_userdef_write(const char *filepath, struct ReportList *reports);
|
||||
bool BKE_blendfile_userdef_write_app_template(const char *filepath, struct ReportList *reports);
|
||||
|
||||
@@ -58,6 +58,7 @@ set(INC_SYS
|
||||
)
|
||||
|
||||
set(SRC
|
||||
${CMAKE_SOURCE_DIR}/release/datafiles/userdef/userdef_default.c
|
||||
intern/CCGSubSurf.c
|
||||
intern/CCGSubSurf_legacy.c
|
||||
intern/CCGSubSurf_opensubdiv.c
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
|
||||
#include "IMB_colormanagement.h"
|
||||
|
||||
#include "BKE_addon.h"
|
||||
#include "BKE_appdir.h"
|
||||
#include "BKE_blender.h"
|
||||
#include "BKE_blender_version.h"
|
||||
@@ -552,6 +553,35 @@ UserDef *BKE_blendfile_userdef_read_from_memory(const void *filebuf,
|
||||
return userdef;
|
||||
}
|
||||
|
||||
UserDef *BKE_blendfile_userdef_from_defaults(void)
|
||||
{
|
||||
UserDef *userdef = MEM_mallocN(sizeof(*userdef), __func__);
|
||||
|
||||
memcpy(userdef, &U_default, sizeof(UserDef));
|
||||
|
||||
/* Add-ons. */
|
||||
{
|
||||
const char *addons[] = {
|
||||
"io_anim_bvh",
|
||||
"io_curve_svg",
|
||||
"io_mesh_ply",
|
||||
"io_mesh_stl",
|
||||
"io_mesh_uv_layout",
|
||||
"io_scene_fbx",
|
||||
"io_scene_gltf2",
|
||||
"io_scene_obj",
|
||||
"io_scene_x3d",
|
||||
};
|
||||
for (int i; i < ARRAY_SIZE(addons); i++) {
|
||||
bAddon *addon = BKE_addon_new();
|
||||
STRNCPY(addon->module, addons[i]);
|
||||
BLI_addtail(&userdef->addons, addon);
|
||||
}
|
||||
}
|
||||
|
||||
return userdef;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only write the userdef in a .blend
|
||||
* \return success
|
||||
|
||||
@@ -176,6 +176,7 @@ struct BlendThumbnail *BLO_thumbnail_from_file(const char *filepath);
|
||||
|
||||
/* datafiles (generated theme) */
|
||||
extern const struct bTheme U_theme_default;
|
||||
extern const struct UserDef U_default;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
#include "BLO_readfile.h"
|
||||
|
||||
/**
|
||||
* Override values in in-memory startup.blend, avoids re-saving for small changes.
|
||||
* Update in-memory preferences with system specific values.
|
||||
*/
|
||||
void BLO_update_defaults_userpref_blend(void)
|
||||
{
|
||||
@@ -73,54 +73,17 @@ void BLO_update_defaults_userpref_blend(void)
|
||||
U.flag &= ~USER_SCRIPT_AUTOEXEC_DISABLE;
|
||||
#endif
|
||||
|
||||
/* Transform tweak with single click and drag. */
|
||||
U.flag |= USER_RELEASECONFIRM;
|
||||
|
||||
U.flag &= ~(USER_DEVELOPER_UI | USER_TOOLTIPS_PYTHON);
|
||||
|
||||
/* Clear addon preferences. */
|
||||
for (bAddon *addon = U.addons.first, *addon_next; addon != NULL; addon = addon_next) {
|
||||
addon_next = addon->next;
|
||||
|
||||
if (addon->prop) {
|
||||
IDP_FreeProperty(addon->prop);
|
||||
addon->prop = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Ignore the theme saved in the blend file,
|
||||
* instead use the theme from 'userdef_default_theme.c' */
|
||||
{
|
||||
bTheme *theme = U.themes.first;
|
||||
memcpy(theme, &U_theme_default, sizeof(bTheme));
|
||||
}
|
||||
|
||||
/* Leave temp directory empty, will then get appropriate value per OS. */
|
||||
U.tempdir[0] = '\0';
|
||||
|
||||
/* System-specific fonts directory. */
|
||||
BKE_appdir_font_folder_default(U.fontdir);
|
||||
|
||||
/* Only enable tooltips translation by default,
|
||||
* without actually enabling translation itself, for now. */
|
||||
U.transopts = USER_TR_TOOLTIPS;
|
||||
U.memcachelimit = min_ii(BLI_system_memory_max_in_megabytes_int() / 2, 4096);
|
||||
|
||||
/* Auto perspective. */
|
||||
U.uiflag |= USER_AUTOPERSP;
|
||||
|
||||
/* Init weight paint range. */
|
||||
BKE_colorband_init(&U.coba_weight, true);
|
||||
|
||||
/* Default visible section. */
|
||||
U.userpref = USER_SECTION_INTERFACE;
|
||||
|
||||
/* Default to left click select. */
|
||||
BKE_keyconfig_pref_set_select_mouse(&U, 0, true);
|
||||
|
||||
/* Increase a little for new scrubbing area. */
|
||||
U.v2d_min_gridsize = 45;
|
||||
|
||||
/* Default studio light. */
|
||||
BKE_studiolight_default(U.light_param, U.light_ambient);
|
||||
}
|
||||
|
||||
@@ -936,7 +936,7 @@ void wm_homefile_read(bContext *C,
|
||||
filepath_startup,
|
||||
&(const struct BlendFileReadParams){
|
||||
.is_startup = true,
|
||||
.skip_flags = skip_flags,
|
||||
.skip_flags = skip_flags | BLO_READ_SKIP_USERDEF,
|
||||
},
|
||||
NULL);
|
||||
}
|
||||
@@ -963,6 +963,15 @@ void wm_homefile_read(bContext *C,
|
||||
}
|
||||
|
||||
if (success == false) {
|
||||
if (use_userdef) {
|
||||
if ((skip_flags & BLO_READ_SKIP_USERDEF) == 0) {
|
||||
UserDef *userdef_default = BKE_blendfile_userdef_from_defaults();
|
||||
BKE_blender_userdef_app_template_data_set_and_free(userdef_default);
|
||||
skip_flags &= ~BLO_READ_SKIP_USERDEF;
|
||||
read_userdef_from_memory = true;
|
||||
}
|
||||
}
|
||||
|
||||
success = BKE_blendfile_read_from_memory(C,
|
||||
datatoc_startup_blend,
|
||||
datatoc_startup_blend_size,
|
||||
@@ -972,13 +981,7 @@ void wm_homefile_read(bContext *C,
|
||||
.skip_flags = skip_flags,
|
||||
},
|
||||
NULL);
|
||||
if (success) {
|
||||
if (use_userdef) {
|
||||
if ((skip_flags & BLO_READ_SKIP_USERDEF) == 0) {
|
||||
read_userdef_from_memory = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (use_data && BLI_listbase_is_empty(&wmbase)) {
|
||||
wm_clear_default_size(C);
|
||||
}
|
||||
@@ -1015,8 +1018,7 @@ void wm_homefile_read(bContext *C,
|
||||
}
|
||||
if (userdef_template == NULL) {
|
||||
/* we need to have preferences load to overwrite preferences from previous template */
|
||||
userdef_template = BKE_blendfile_userdef_read_from_memory(
|
||||
datatoc_startup_blend, datatoc_startup_blend_size, NULL);
|
||||
userdef_template = BKE_blendfile_userdef_from_defaults();
|
||||
read_userdef_from_memory = true;
|
||||
}
|
||||
if (userdef_template) {
|
||||
@@ -1650,7 +1652,7 @@ static int wm_homefile_write_exec(bContext *C, wmOperator *op)
|
||||
/* force save as regular blend file */
|
||||
fileflags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_HISTORY);
|
||||
|
||||
if (BLO_write_file(bmain, filepath, fileflags | G_FILE_USERPREFS, op->reports, NULL) == 0) {
|
||||
if (BLO_write_file(bmain, filepath, fileflags, op->reports, NULL) == 0) {
|
||||
printf("fail\n");
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
@@ -1734,7 +1736,7 @@ void WM_OT_save_userpref(wmOperatorType *ot)
|
||||
{
|
||||
ot->name = "Save Preferences";
|
||||
ot->idname = "WM_OT_save_userpref";
|
||||
ot->description = "Save preferences separately, overrides startup file preferences";
|
||||
ot->description = "Make the current preferences default";
|
||||
|
||||
ot->invoke = WM_operator_confirm;
|
||||
ot->exec = wm_userpref_write_exec;
|
||||
|
||||
Reference in New Issue
Block a user