forked from bartvdbraak/blender
Preferences: file menu item to temporarily load factory settings
It's common to load factory settings as a test without wanting to overwrite your own settings on exit.
This commit is contained in:
parent
34da7f8fdd
commit
9c9081d9ef
@ -172,6 +172,7 @@ class TOPBAR_MT_file(Menu):
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
prefs = context.preferences
|
||||
|
||||
layout.operator_context = 'INVOKE_AREA'
|
||||
layout.menu("TOPBAR_MT_file_new", text="New", icon='FILE_NEW')
|
||||
@ -195,20 +196,26 @@ class TOPBAR_MT_file(Menu):
|
||||
layout.operator_context = 'INVOKE_AREA'
|
||||
|
||||
if any(bpy.utils.app_template_paths()):
|
||||
app_template = context.preferences.app_template
|
||||
app_template = prefs.app_template
|
||||
else:
|
||||
app_template = None
|
||||
|
||||
if app_template:
|
||||
layout.label(text=bpy.path.display_name(app_template, has_ext=False))
|
||||
layout.operator("wm.save_homefile")
|
||||
layout.operator(
|
||||
|
||||
layout.operator("wm.save_homefile")
|
||||
props = layout.operator("wm.read_factory_settings")
|
||||
if app_template:
|
||||
props.app_template = app_template
|
||||
|
||||
if prefs.use_preferences_save:
|
||||
props = layout.operator(
|
||||
"wm.read_factory_settings",
|
||||
text="Load Factory Settings",
|
||||
).app_template = app_template
|
||||
else:
|
||||
layout.operator("wm.save_homefile")
|
||||
layout.operator("wm.read_factory_settings")
|
||||
text="Load Factory Settings (Temporary)"
|
||||
)
|
||||
if app_template:
|
||||
props.app_template = app_template
|
||||
props.use_temporary_preferences = True
|
||||
|
||||
layout.separator()
|
||||
|
||||
|
@ -111,6 +111,7 @@ enum {
|
||||
G_FLAG_PICKSEL = (1 << 2),
|
||||
/** Support simulating events (for testing). */
|
||||
G_FLAG_EVENT_SIMULATE = (1 << 3),
|
||||
G_FLAG_USERPREF_NO_SAVE_ON_EXIT = (1 << 4),
|
||||
|
||||
G_FLAG_SCRIPT_AUTOEXEC = (1 << 13),
|
||||
/** When this flag is set ignore the prefs #USER_SCRIPT_AUTOEXEC_DISABLE. */
|
||||
@ -121,7 +122,8 @@ enum {
|
||||
|
||||
/** Don't overwrite these flags when reading a file. */
|
||||
#define G_FLAG_ALL_RUNTIME \
|
||||
(G_FLAG_SCRIPT_AUTOEXEC | G_FLAG_SCRIPT_OVERRIDE_PREF | G_FLAG_EVENT_SIMULATE)
|
||||
(G_FLAG_SCRIPT_AUTOEXEC | G_FLAG_SCRIPT_OVERRIDE_PREF | G_FLAG_EVENT_SIMULATE | \
|
||||
G_FLAG_USERPREF_NO_SAVE_ON_EXIT)
|
||||
|
||||
/** Flags to read from blend file. */
|
||||
#define G_FLAG_ALL_READFILE 0
|
||||
|
@ -1882,6 +1882,7 @@ static int wm_homefile_read_exec(bContext *C, wmOperator *op)
|
||||
PropertyRNA *prop_app_template = RNA_struct_find_property(op->ptr, "app_template");
|
||||
const bool use_splash = !use_factory_settings && RNA_boolean_get(op->ptr, "use_splash");
|
||||
const bool use_empty_data = RNA_boolean_get(op->ptr, "use_empty");
|
||||
const bool use_temporary_preferences = RNA_boolean_get(op->ptr, "use_temporary_preferences");
|
||||
|
||||
if (prop_app_template && RNA_property_is_set(op->ptr, prop_app_template)) {
|
||||
RNA_property_string_get(op->ptr, prop_app_template, app_template_buf);
|
||||
@ -1912,6 +1913,8 @@ static int wm_homefile_read_exec(bContext *C, wmOperator *op)
|
||||
if (use_splash) {
|
||||
WM_init_splash(C);
|
||||
}
|
||||
SET_FLAG_FROM_TEST(G.f, use_temporary_preferences, G_FLAG_USERPREF_NO_SAVE_ON_EXIT);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
@ -1926,6 +1929,24 @@ static int wm_homefile_read_invoke(bContext *C, wmOperator *op, const wmEvent *U
|
||||
}
|
||||
}
|
||||
|
||||
static void read_homefile_props(wmOperatorType *ot)
|
||||
{
|
||||
PropertyRNA *prop;
|
||||
|
||||
prop = RNA_def_string(ot->srna, "app_template", "Template", sizeof(U.app_template), "", "");
|
||||
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
|
||||
|
||||
prop = RNA_def_boolean(ot->srna, "use_empty", false, "Empty", "");
|
||||
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
|
||||
|
||||
prop = RNA_def_boolean(ot->srna,
|
||||
"use_temporary_preferences",
|
||||
false,
|
||||
"Temporary Preferences",
|
||||
"Don't save preferences on exit");
|
||||
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
|
||||
}
|
||||
|
||||
void WM_OT_read_homefile(wmOperatorType *ot)
|
||||
{
|
||||
PropertyRNA *prop;
|
||||
@ -1945,23 +1966,17 @@ void WM_OT_read_homefile(wmOperatorType *ot)
|
||||
ot->srna, "load_ui", true, "Load UI", "Load user interface setup from the .blend file");
|
||||
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
|
||||
|
||||
prop = RNA_def_boolean(ot->srna, "use_empty", false, "Empty", "");
|
||||
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
|
||||
|
||||
/* So the splash can be kept open after loading a file (for templates). */
|
||||
prop = RNA_def_boolean(ot->srna, "use_splash", false, "Splash", "");
|
||||
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
|
||||
|
||||
prop = RNA_def_string(ot->srna, "app_template", "Template", sizeof(U.app_template), "", "");
|
||||
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
|
||||
read_homefile_props(ot);
|
||||
|
||||
/* omit poll to run in background mode */
|
||||
}
|
||||
|
||||
void WM_OT_read_factory_settings(wmOperatorType *ot)
|
||||
{
|
||||
PropertyRNA *prop;
|
||||
|
||||
ot->name = "Load Factory Settings";
|
||||
ot->idname = "WM_OT_read_factory_settings";
|
||||
ot->description = "Load default file and preferences";
|
||||
@ -1969,12 +1984,7 @@ void WM_OT_read_factory_settings(wmOperatorType *ot)
|
||||
ot->invoke = WM_operator_confirm;
|
||||
ot->exec = wm_homefile_read_exec;
|
||||
|
||||
prop = RNA_def_string(ot->srna, "app_template", "Template", sizeof(U.app_template), "", "");
|
||||
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
|
||||
|
||||
prop = RNA_def_boolean(ot->srna, "use_empty", false, "Empty", "");
|
||||
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
|
||||
|
||||
read_homefile_props(ot);
|
||||
/* omit poll to run in background mode */
|
||||
}
|
||||
|
||||
|
@ -475,9 +475,11 @@ void WM_exit_ext(bContext *C, const bool do_python)
|
||||
ED_screen_exit(C, win, WM_window_get_active_screen(win));
|
||||
}
|
||||
|
||||
if (U.runtime.is_dirty && !G.background) {
|
||||
if (U.pref_flag & USER_PREF_FLAG_SAVE) {
|
||||
BKE_blendfile_userdef_write_all(NULL);
|
||||
if (!G.background) {
|
||||
if ((U.pref_flag & USER_PREF_FLAG_SAVE) && ((G.f & G_FLAG_USERPREF_NO_SAVE_ON_EXIT) == 0)) {
|
||||
if (U.runtime.is_dirty) {
|
||||
BKE_blendfile_userdef_write_all(NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user