diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-09-22 05:50:41 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-09-22 05:50:41 +0300 |
commit | 28fa49f16808a8e1a143bbb88073a614c8eda27b (patch) | |
tree | 387f8ef356060fe1b80299037ec09e7b82ebdad9 /source/blender/windowmanager/intern/wm_files.c | |
parent | 12ea90b707d2ccac5960874eac83af057911320c (diff) |
Cleanup: de-duplicate post file read update calls
Diffstat (limited to 'source/blender/windowmanager/intern/wm_files.c')
-rw-r--r-- | source/blender/windowmanager/intern/wm_files.c | 110 |
1 files changed, 49 insertions, 61 deletions
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 41827ad0925..7c4412661b6 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -401,6 +401,53 @@ void WM_file_autoexec_init(const char *filepath) } } +/** + * Logic shared between #WM_file_read & #wm_homefile_read, + * updates to make after reading a file. + */ +static void wm_file_read_post(bContext *C, bool is_startup_file) +{ + CTX_wm_window_set(C, CTX_wm_manager(C)->windows.first); + + ED_editors_init(C); + DAG_on_visible_update(CTX_data_main(C), true); + +#ifdef WITH_PYTHON + if (is_startup_file) { + /* possible python hasn't been initialized */ + if (CTX_py_init_get(C)) { + /* sync addons, these may have changed from the defaults */ + BPY_string_exec(C, "__import__('addon_utils').reset_all()"); + + BPY_python_reset(C); + } + } + else { + /* run any texts that were loaded in and flagged as modules */ + BPY_python_reset(C); + } +#endif /* WITH_PYTHON */ + + WM_operatortype_last_properties_clear_all(); + + /* important to do before NULL'ing the context */ + BLI_callback_exec(CTX_data_main(C), NULL, BLI_CB_EVT_VERSION_UPDATE); + BLI_callback_exec(CTX_data_main(C), NULL, BLI_CB_EVT_LOAD_POST); + + WM_event_add_notifier(C, NC_WM | ND_FILEREAD, NULL); + + if (!G.background) { + /* in background mode this makes it hard to load + * a blend file and do anything since the screen + * won't be set to a valid value again */ + CTX_wm_window_set(C, NULL); /* exits queues */ + } + +// undo_editmode_clear(); + BKE_undo_reset(); + BKE_undo_write(C, "original"); /* save current state */ +} + bool WM_file_read(bContext *C, const char *filepath, ReportList *reports) { /* assume automated tasks with background, don't write recent file list */ @@ -465,32 +512,7 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports) } } - - WM_event_add_notifier(C, NC_WM | ND_FILEREAD, NULL); -// refresh_interface_font(); - - CTX_wm_window_set(C, CTX_wm_manager(C)->windows.first); - - ED_editors_init(C); - DAG_on_visible_update(CTX_data_main(C), true); - -#ifdef WITH_PYTHON - /* run any texts that were loaded in and flagged as modules */ - BPY_python_reset(C); -#endif - - WM_operatortype_last_properties_clear_all(); - - /* important to do before NULL'ing the context */ - BLI_callback_exec(CTX_data_main(C), NULL, BLI_CB_EVT_VERSION_UPDATE); - BLI_callback_exec(CTX_data_main(C), NULL, BLI_CB_EVT_LOAD_POST); - - if (!G.background) { - /* in background mode this makes it hard to load - * a blend file and do anything since the screen - * won't be set to a valid value again */ - CTX_wm_window_set(C, NULL); /* exits queues */ - } + wm_file_read_post(C, false); #if 0 /* gives popups on windows but not linux, bug in report API @@ -510,9 +532,6 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports) } #endif - BKE_undo_reset(); - BKE_undo_write(C, "original"); /* save current state */ - success = true; } else if (retval == BKE_READ_EXOTIC_OK_OTHER) @@ -673,38 +692,7 @@ int wm_homefile_read(bContext *C, ReportList *reports, bool from_memory, const c G.save_over = 0; // start with save preference untitled.blend G.fileflags &= ~G_FILE_AUTOPLAY; /* disable autoplay in startup.blend... */ -// refresh_interface_font(); - -// undo_editmode_clear(); - BKE_undo_reset(); - BKE_undo_write(C, "original"); /* save current state */ - - CTX_wm_window_set(C, CTX_wm_manager(C)->windows.first); - - ED_editors_init(C); - DAG_on_visible_update(CTX_data_main(C), true); - -#ifdef WITH_PYTHON - if (CTX_py_init_get(C)) { - /* sync addons, these may have changed from the defaults */ - BPY_string_exec(C, "__import__('addon_utils').reset_all()"); - - BPY_python_reset(C); - } -#endif - - WM_operatortype_last_properties_clear_all(); - - /* important to do before NULL'ing the context */ - BLI_callback_exec(CTX_data_main(C), NULL, BLI_CB_EVT_VERSION_UPDATE); - BLI_callback_exec(CTX_data_main(C), NULL, BLI_CB_EVT_LOAD_POST); - - WM_event_add_notifier(C, NC_WM | ND_FILEREAD, NULL); - - /* in background mode the scene will stay NULL */ - if (!G.background) { - CTX_wm_window_set(C, NULL); /* exits queues */ - } + wm_file_read_post(C, true); return true; } |