From cf67ba848f2f42e0b7320aa0654ba89bd14a1416 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 2 Sep 2020 17:44:08 +1000 Subject: WM: add use_factory_startup option to read homefile operator There was no way to reset the current file to factory settings without reloading the preferences (which disables & re-enables add-ons), this slows down resetting files and can complicate tests. --- source/blender/windowmanager/intern/wm_files.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'source/blender/windowmanager/intern/wm_files.c') diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index f53a3d6bf35..561e27f933d 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -1982,7 +1982,10 @@ void WM_OT_read_history(wmOperatorType *ot) static int wm_homefile_read_exec(bContext *C, wmOperator *op) { - const bool use_factory_settings = (STREQ(op->type->idname, "WM_OT_read_factory_settings")); + const bool use_factory_startup_and_userdef = STREQ(op->type->idname, + "WM_OT_read_factory_settings"); + const bool use_factory_settings = use_factory_startup_and_userdef || + RNA_boolean_get(op->ptr, "use_factory_startup"); bool use_userdef = false; char filepath_buf[FILE_MAX]; const char *filepath = NULL; @@ -2007,10 +2010,12 @@ static int wm_homefile_read_exec(bContext *C, wmOperator *op) } } else { - /* always load UI for factory settings (prefs will re-init) */ - G.fileflags &= ~G_FILE_NO_UI; - /* Always load preferences with factory settings. */ - use_userdef = true; + if (use_factory_startup_and_userdef) { + /* always load UI for factory settings (prefs will re-init) */ + G.fileflags &= ~G_FILE_NO_UI; + /* Always load preferences with factory settings. */ + use_userdef = true; + } } char app_template_buf[sizeof(U.app_template)]; @@ -2127,6 +2132,12 @@ void WM_OT_read_homefile(wmOperatorType *ot) prop = RNA_def_boolean(ot->srna, "use_splash", false, "Splash", ""); RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); + /* So scripts can load factory-startup without resetting preferences + * (which has other implications such as reloading all add-ons). + * Match naming for `--factory-startup` command line argument. */ + prop = RNA_def_boolean(ot->srna, "use_factory_startup", false, "Factory Startup", ""); + RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); + read_homefile_props(ot); /* omit poll to run in background mode */ -- cgit v1.2.3