From 7e21c99d05066a8f88453016c2f69a0607b5c2e0 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 30 Nov 2018 13:33:13 +1100 Subject: PyAPI: add load_factory_startup_post handler Needed so we can apply changes to the startup file, only in the case when it's load loaded from a user-saved startup. --- source/blender/blenlib/BLI_callbacks.h | 1 + source/blender/python/intern/bpy_app_handlers.c | 1 + source/blender/windowmanager/intern/wm_files.c | 38 +++++++++++++++++----- source/blender/windowmanager/intern/wm_init_exit.c | 8 ++++- source/blender/windowmanager/wm_files.h | 3 +- 5 files changed, 41 insertions(+), 10 deletions(-) (limited to 'source') diff --git a/source/blender/blenlib/BLI_callbacks.h b/source/blender/blenlib/BLI_callbacks.h index c888152001e..2bbd82f6db8 100644 --- a/source/blender/blenlib/BLI_callbacks.h +++ b/source/blender/blenlib/BLI_callbacks.h @@ -56,6 +56,7 @@ typedef enum { BLI_CB_EVT_DEPSGRAPH_UPDATE_PRE, BLI_CB_EVT_DEPSGRAPH_UPDATE_POST, BLI_CB_EVT_VERSION_UPDATE, + BLI_CB_EVT_LOAD_FACTORY_STARTUP_POST, BLI_CB_EVT_TOT } eCbEvent; diff --git a/source/blender/python/intern/bpy_app_handlers.c b/source/blender/python/intern/bpy_app_handlers.c index 44647eb21a0..a251bdeb15b 100644 --- a/source/blender/python/intern/bpy_app_handlers.c +++ b/source/blender/python/intern/bpy_app_handlers.c @@ -66,6 +66,7 @@ static PyStructSequence_Field app_cb_info_fields[] = { {(char *)"depsgraph_update_pre", (char *)"on depsgraph update (pre)"}, {(char *)"depsgraph_update_post", (char *)"on depsgraph update (post)"}, {(char *)"version_update", (char *)"on ending the versioning code"}, + {(char *)"load_factory_startup_post", (char *)"on loading factory startup (after)"}, /* sets the permanent tag */ # define APP_CB_OTHER_FIELDS 1 diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 8c263461af6..73254678c6d 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -475,7 +475,8 @@ void wm_file_read_report(bContext *C, Main *bmain) * Logic shared between #WM_file_read & #wm_homefile_read, * updates to make after reading a file. */ -static void wm_file_read_post(bContext *C, const bool is_startup_file, const bool reset_app_template) +static void wm_file_read_post( + bContext *C, const bool is_startup_file, const bool is_factory_startup, const bool reset_app_template) { bool addons_loaded = false; wmWindowManager *wm = CTX_wm_manager(C); @@ -527,6 +528,9 @@ static void wm_file_read_post(bContext *C, const bool is_startup_file, const boo /* important to do before NULL'ing the context */ BLI_callback_exec(bmain, NULL, BLI_CB_EVT_VERSION_UPDATE); BLI_callback_exec(bmain, NULL, BLI_CB_EVT_LOAD_POST); + if (is_factory_startup) { + BLI_callback_exec(bmain, NULL, BLI_CB_EVT_LOAD_FACTORY_STARTUP_POST); + } #if 1 WM_event_add_notifier(C, NC_WM | ND_FILEREAD, NULL); @@ -633,7 +637,7 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports) } } - wm_file_read_post(C, false, false); + wm_file_read_post(C, false, false, false); success = true; } @@ -736,12 +740,14 @@ static bool wm_app_template_has_userpref(const char *app_template) void wm_homefile_read( bContext *C, ReportList *reports, bool use_factory_settings, bool use_empty_data, bool use_userdef, - const char *filepath_startup_override, const char *app_template_override) + const char *filepath_startup_override, const char *app_template_override, + bool *r_is_factory_startup) { Main *bmain = G_MAIN; /* Context does not always have valid main pointer here... */ ListBase wmbase; bool success = false; + bool filepath_startup_is_factory = true; char filepath_startup[FILE_MAX]; char filepath_userdef[FILE_MAX]; @@ -762,6 +768,9 @@ void wm_homefile_read( bool read_userdef_from_memory = false; eBLOReadSkip skip_flags = use_userdef ? 0 : BLO_READ_SKIP_USERDEF; + /* True if we load startup.blend from memory or use app-template startup.blend which the user hasn't saved. */ + bool is_factory_startup = true; + /* options exclude eachother */ BLI_assert((use_factory_settings && filepath_startup_override) == 0); @@ -787,6 +796,7 @@ void wm_homefile_read( if (!use_factory_settings) { if (cfgdir) { BLI_path_join(filepath_startup, sizeof(filepath_startup), cfgdir, BLENDER_STARTUP_FILE, NULL); + filepath_startup_is_factory = false; if (use_userdef) { BLI_path_join(filepath_userdef, sizeof(filepath_startup), cfgdir, BLENDER_USERPREF_FILE, NULL); } @@ -797,6 +807,7 @@ void wm_homefile_read( if (filepath_startup_override) { BLI_strncpy(filepath_startup, filepath_startup_override, FILE_MAX); + filepath_startup_is_factory = false; } } @@ -838,7 +849,9 @@ void wm_homefile_read( } if ((app_template != NULL) && (app_template[0] != '\0')) { - if (!BKE_appdir_app_template_id_search(app_template, app_template_system, sizeof(app_template_system))) { + if (!BKE_appdir_app_template_id_search( + app_template, app_template_system, sizeof(app_template_system))) + { /* Can safely continue with code below, just warn it's not found. */ BKE_reportf(reports, RPT_WARNING, "Application Template '%s' not found.", app_template); } @@ -850,6 +863,7 @@ void wm_homefile_read( if (!use_factory_settings) { BLI_path_join(app_template_config, sizeof(app_template_config), cfgdir, app_template, NULL); BLI_path_join(filepath_startup, sizeof(filepath_startup), app_template_config, BLENDER_STARTUP_FILE, NULL); + filepath_startup_is_factory = false; if (BLI_access(filepath_startup, R_OK) != 0) { filepath_startup[0] = '\0'; } @@ -860,6 +874,7 @@ void wm_homefile_read( if (filepath_startup[0] == '\0') { BLI_path_join(filepath_startup, sizeof(filepath_startup), app_template_system, BLENDER_STARTUP_FILE, NULL); + filepath_startup_is_factory = true; /* Update defaults only for system templates. */ update_defaults = true; @@ -881,8 +896,11 @@ void wm_homefile_read( printf("\nNote: No (valid) '%s' found, fall back to built-in default.\n\n", filepath_startup); success = false; } - if (success && update_defaults) { - BLO_update_defaults_startup_blend(CTX_data_main(C), app_template); + if (success) { + if (update_defaults) { + BLO_update_defaults_startup_blend(CTX_data_main(C), app_template); + } + is_factory_startup = filepath_startup_is_factory; } } @@ -987,7 +1005,11 @@ void wm_homefile_read( /* start with save preference untitled.blend */ G.save_over = 0; - wm_file_read_post(C, true, 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; + } } /** \name WM History File API @@ -1741,7 +1763,7 @@ static int wm_homefile_read_exec(bContext *C, wmOperator *op) app_template = WM_init_state_app_template_get(); } - wm_homefile_read(C, op->reports, use_factory_settings, use_empty_data, use_userdef, filepath, app_template); + wm_homefile_read(C, op->reports, use_factory_settings, use_empty_data, use_userdef, filepath, app_template, NULL); if (use_splash) { WM_init_splash(C); } diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index 9fca91d2f3f..e4ae9495c61 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -255,7 +255,10 @@ void WM_init(bContext *C, int argc, const char **argv) WM_msgbus_types_init(); /* get the default database, plus a wm */ - wm_homefile_read(C, NULL, G.factory_startup, false, true, NULL, WM_init_state_app_template_get()); + bool is_factory_startup = true; + wm_homefile_read( + C, NULL, G.factory_startup, false, true, NULL, WM_init_state_app_template_get(), + &is_factory_startup); /* Call again to set from userpreferences... */ BLT_lang_set(NULL); @@ -336,6 +339,9 @@ void WM_init(bContext *C, int argc, const char **argv) BLI_callback_exec(bmain, NULL, BLI_CB_EVT_VERSION_UPDATE); BLI_callback_exec(bmain, NULL, BLI_CB_EVT_LOAD_POST); + if (is_factory_startup) { + BLI_callback_exec(bmain, NULL, BLI_CB_EVT_LOAD_FACTORY_STARTUP_POST); + } wm_file_read_report(C, bmain); diff --git a/source/blender/windowmanager/wm_files.h b/source/blender/windowmanager/wm_files.h index 465abf011fa..f6f43c3d856 100644 --- a/source/blender/windowmanager/wm_files.h +++ b/source/blender/windowmanager/wm_files.h @@ -39,7 +39,8 @@ void wm_history_file_read(void); void wm_homefile_read( struct bContext *C, struct ReportList *reports, bool use_factory_settings, bool use_empty_data, bool use_userdef, - const char *filepath_startup_override, const char *app_template_override); + const char *filepath_startup_override, const char *app_template_override, + bool *r_is_factory_startup); void wm_file_read_report(bContext *C, struct Main *bmain); void WM_OT_save_homefile(struct wmOperatorType *ot); -- cgit v1.2.3