[Bf-blender-cvs] [614c15140fb] temp-prefs-read: Initial support for reading only preferences
Campbell Barton
noreply at git.blender.org
Fri May 10 15:15:01 CEST 2019
Commit: 614c15140fb16a3a577e9f685861306e90ec9a53
Author: Campbell Barton
Date: Fri May 10 23:14:12 2019 +1000
Branches: temp-prefs-read
https://developer.blender.org/rB614c15140fb16a3a577e9f685861306e90ec9a53
Initial support for reading only preferences
===================================================================
M release/scripts/startup/bl_ui/space_userpref.py
M source/blender/blenloader/intern/readfile.c
M source/blender/windowmanager/intern/wm_files.c
M source/blender/windowmanager/intern/wm_init_exit.c
M source/blender/windowmanager/intern/wm_operators.c
M source/blender/windowmanager/wm_files.h
===================================================================
diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index 46cd4bfa904..5c703a3ffbc 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -81,7 +81,13 @@ class USERPREF_PT_save_preferences(Panel):
layout.scale_x = 1.3
layout.scale_y = 1.3
- layout.operator("wm.save_userpref")
+ col = layout.column(align=True)
+ col.operator("wm.save_userpref")
+ col.operator("wm.read_userpref")
+ col.operator(
+ "wm.read_userpref",
+ text="Load Factory Preferences",
+ ).use_factory_settings = True
# Panel mix-in.
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 227aa6a2ec6..288fa92da38 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -9629,14 +9629,17 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath)
ListBase mainlist = {NULL, NULL};
bfd = MEM_callocN(sizeof(BlendFileData), "blendfiledata");
- bfd->main = BKE_main_new();
- BLI_addtail(&mainlist, bfd->main);
- fd->mainlist = &mainlist;
+ bfd->main = BKE_main_new();
bfd->main->versionfile = fd->fileversion;
bfd->type = BLENFILETYPE_BLEND;
- BLI_strncpy(bfd->main->name, filepath, sizeof(bfd->main->name));
+
+ if ((fd->skip_flags & BLO_READ_SKIP_DATA) == 0) {
+ BLI_addtail(&mainlist, bfd->main);
+ fd->mainlist = &mainlist;
+ BLI_strncpy(bfd->main->name, filepath, sizeof(bfd->main->name));
+ }
if (G.background) {
/* We only read & store .blend thumbnail in background mode
@@ -9714,45 +9717,52 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath)
/* do before read_libraries, but skip undo case */
if (fd->memfile == NULL) {
- do_versions(fd, NULL, bfd->main);
- do_versions_userdef(fd, bfd);
+ if ((fd->skip_flags & BLO_READ_SKIP_DATA) == 0) {
+ do_versions(fd, NULL, bfd->main);
+ }
+
+ if ((fd->skip_flags & BLO_READ_SKIP_USERDEF) == 0) {
+ do_versions_userdef(fd, bfd);
+ }
}
- read_libraries(fd, &mainlist);
+ if ((fd->skip_flags & BLO_READ_SKIP_DATA) == 0) {
+ read_libraries(fd, &mainlist);
- blo_join_main(&mainlist);
+ blo_join_main(&mainlist);
- lib_link_all(fd, bfd->main);
+ lib_link_all(fd, bfd->main);
- /* Skip in undo case. */
- if (fd->memfile == NULL) {
- /* Yep, second splitting... but this is a very cheap operation, so no big deal. */
- blo_split_main(&mainlist, bfd->main);
- for (Main *mainvar = mainlist.first; mainvar; mainvar = mainvar->next) {
- BLI_assert(mainvar->versionfile != 0);
- do_versions_after_linking(mainvar);
- }
- blo_join_main(&mainlist);
+ /* Skip in undo case. */
+ if (fd->memfile == NULL) {
+ /* Yep, second splitting... but this is a very cheap operation, so no big deal. */
+ blo_split_main(&mainlist, bfd->main);
+ for (Main *mainvar = mainlist.first; mainvar; mainvar = mainvar->next) {
+ BLI_assert(mainvar->versionfile != 0);
+ do_versions_after_linking(mainvar);
+ }
+ blo_join_main(&mainlist);
- /* After all data has been read and versioned, uses LIB_TAG_NEW. */
- ntreeUpdateAllNew(bfd->main);
- }
+ /* After all data has been read and versioned, uses LIB_TAG_NEW. */
+ ntreeUpdateAllNew(bfd->main);
+ }
- BKE_main_id_tag_all(bfd->main, LIB_TAG_NEW, false);
+ BKE_main_id_tag_all(bfd->main, LIB_TAG_NEW, false);
- /* Now that all our data-blocks are loaded,
- * we can re-generate overrides from their references. */
- if (fd->memfile == NULL) {
- /* Do not apply in undo case! */
- BKE_main_override_static_update(bfd->main);
- }
+ /* Now that all our data-blocks are loaded,
+ * we can re-generate overrides from their references. */
+ if (fd->memfile == NULL) {
+ /* Do not apply in undo case! */
+ BKE_main_override_static_update(bfd->main);
+ }
- BKE_collections_after_lib_link(bfd->main);
+ BKE_collections_after_lib_link(bfd->main);
- fix_relpaths_library(fd->relabase,
- bfd->main); /* make all relative paths, relative to the open blend file */
+ /* Make all relative paths, relative to the open blend file. */
+ fix_relpaths_library(fd->relabase, bfd->main);
- link_global(fd, bfd); /* as last */
+ link_global(fd, bfd); /* as last */
+ }
fd->mainlist = NULL; /* Safety, this is local variable, shall not be used afterward. */
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index 1308af2659a..20cfafbe5d9 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -738,6 +738,7 @@ void wm_homefile_read(bContext *C,
ReportList *reports,
bool use_factory_settings,
bool use_empty_data,
+ bool use_data,
bool use_userdef,
const char *filepath_startup_override,
const char *app_template_override,
@@ -768,7 +769,14 @@ void wm_homefile_read(bContext *C,
* And in this case versioning code is to be run.
*/
bool read_userdef_from_memory = false;
- eBLOReadSkip skip_flags = use_userdef ? 0 : BLO_READ_SKIP_USERDEF;
+ eBLOReadSkip skip_flags = 0;
+
+ if (use_data == false) {
+ skip_flags |= BLO_READ_SKIP_DATA;
+ }
+ if (use_userdef == false) {
+ skip_flags |= BLO_READ_SKIP_USERDEF;
+ }
/* True if we load startup.blend from memory
* or use app-template startup.blend which the user hasn't saved. */
@@ -781,14 +789,16 @@ void wm_homefile_read(bContext *C,
SET_FLAG_FROM_TEST(G.f, (U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0, G_FLAG_SCRIPT_AUTOEXEC);
}
- BLI_callback_exec(CTX_data_main(C), NULL, BLI_CB_EVT_LOAD_PRE);
+ if (use_data) {
+ BLI_callback_exec(CTX_data_main(C), NULL, BLI_CB_EVT_LOAD_PRE);
- UI_view2d_zoom_cache_reset();
+ G.relbase_valid = 0;
- G.relbase_valid = 0;
+ /* put aside screens to match with persistent windows later */
+ wm_window_match_init(C, &wmbase);
+ }
- /* put aside screens to match with persistent windows later */
- wm_window_match_init(C, &wmbase);
+ UI_view2d_zoom_cache_reset();
filepath_startup[0] = '\0';
filepath_userdef[0] = '\0';
@@ -911,7 +921,9 @@ void wm_homefile_read(bContext *C,
}
if (success) {
if (update_defaults) {
- BLO_update_defaults_startup_blend(CTX_data_main(C), app_template);
+ if (use_data) {
+ BLO_update_defaults_startup_blend(CTX_data_main(C), app_template);
+ }
}
is_factory_startup = filepath_startup_is_factory;
}
@@ -990,10 +1002,12 @@ void wm_homefile_read(bContext *C,
BLI_strncpy(U.app_template, app_template_override, sizeof(U.app_template));
}
- /* Prevent buggy files that had G_FILE_RELATIVE_REMAP written out by mistake.
- * Screws up autosaves otherwise can remove this eventually,
- * only in a 2.53 and older, now its not written. */
- G.fileflags &= ~G_FILE_RELATIVE_REMAP;
+ if (use_data) {
+ /* Prevent buggy files that had G_FILE_RELATIVE_REMAP written out by mistake.
+ * Screws up autosaves otherwise can remove this eventually,
+ * only in a 2.53 and older, now its not written. */
+ G.fileflags &= ~G_FILE_RELATIVE_REMAP;
+ }
bmain = CTX_data_main(C);
@@ -1003,8 +1017,10 @@ void wm_homefile_read(bContext *C,
reset_app_template = true;
}
- /* match the read WM with current WM */
- wm_window_match_do(C, &wmbase, &bmain->wm, &bmain->wm);
+ if (use_data) {
+ /* match the read WM with current WM */
+ wm_window_match_do(C, &wmbase, &bmain->wm, &bmain->wm);
+ }
if (use_factory_settings) {
/* Clear keymaps because the current default keymap may have been initialized
@@ -1016,14 +1032,16 @@ void wm_homefile_read(bContext *C,
}
}
- WM_check(C); /* opens window(s), checks keymaps */
+ if (use_data) {
+ WM_check(C); /* opens window(s), checks keymaps */
- bmain->name[0] = '\0';
+ bmain->name[0] = '\0';
- /* start with save preference untitled.blend */
- G.save_over = 0;
+ /* start with save preference untitled.blend */
+ G.save_over = 0;
- wm_file_read_post(C, true, is_factory_startup, reset_app_template);
+ wm_file_read_post(C, true, is_factory_startup, reset_app_template);
+ }
if (r_is_factory_startup) {
*r_is_factory_startup = is_factory_startup;
@@ -1693,6 +1711,53 @@ void WM_OT_save_userpref(wmOperatorType *ot)
ot->exec = wm_userpref_write_exec;
}
+static int wm_userpref_read_exec(bContext *C, wmOperator *op)
+{
+ const bool use_data = false;
+ const bool use_userdef = true;
+ const bool use_factory_settings = RNA_boolean_get(op->ptr, "use_factory_settings");
+
+ UserDef U_backup = U;
+
+ wm_homefile_read(C,
+ op->reports,
+ use_factory_settings,
+ false,
+ use_data,
+ use_userdef,
+ NULL,
+ WM_init_state_app_template_get(),
+ NULL);
+
+#define USERDEF_RESTORE(member) \
+ { \
+ U.member = U_backup.member; \
+ } \
+ ((void)0)
+
+ USERDEF_RESTORE(userpref);
+
+#undef USERDEF_RESTORE
+
+ WM_event_add_notifier(C, NC_WINDOW, NULL);
+
+ return OPERATOR_FINISHED;
+}
+
+void WM_OT_read_userpref(wmOperatorType *ot)
+{
+ ot->name = "Load Preferences";
+ ot->idname = "WM_OT_read_userpref";
+ ot->description = "Load last saved preferences";
+
+ ot->invoke = WM_operator_confirm;
+ ot->exec = wm_userpref_read_exec;
+
+ PropertyRNA *prop = RNA_def_boolean(
+ ot->srna, "use_factory_settings", false, "Factory Settings", "");
+ RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
+}
+
static int wm_history_file_read_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
{
ED_file_read_bookmarks();
@@ -1767,10 +1832,12 @@ static int wm_homefile_read_exec(bContext *C, wmOperator *op)
app_template = WM_init_state_app_
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list