UI: File Loading Dialog #104666

Closed
Harley Acheson wants to merge 12 commits from Harley/blender:LoadingDialog into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
1 changed files with 94 additions and 1 deletions
Showing only changes of commit e2221acb16 - Show all commits

View File

@ -696,6 +696,8 @@ static void wm_file_read_post(bContext *C, const struct wmFileReadPost_Params *p
CTX_wm_window_set(C, static_cast<wmWindow *>(wm->windows.first));
}
WM_cursor_wait(true);
#ifdef WITH_PYTHON
if (is_startup_file) {
/* On startup (by default), Python won't have been initialized.
@ -782,6 +784,12 @@ static void wm_file_read_post(bContext *C, const struct wmFileReadPost_Params *p
#endif
}
#ifndef WITH_HEADLESS
if (!G.background) {
WM_redraw_windows(C);
}
#endif /* WITH_HEADLESS */
/* report any errors.
* currently disabled if addons aren't yet loaded */
if (addons_loaded) {
@ -815,6 +823,65 @@ static void wm_file_read_post(bContext *C, const struct wmFileReadPost_Params *p
WM_toolsystem_init(C);
}
}
WM_cursor_wait(false);
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name File Loading Dialog
* \{ */
/**
* Dialog displayed during blend file loading, showing thumbnail and file name.
*/
static uiBlock *wm_block_create_loading(bContext *C, ARegion *region, void *arg)
{
const char *filepath = (const char *)arg;
const int dialog_width = (int)(256.0f * UI_SCALE_FAC);
uiBlock *block = UI_block_begin(C, region, "file_open_loading_popup", UI_EMBOSS);
UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP);
uiLayout *layout = UI_block_layout(
block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, dialog_width, 0, 0, UI_style_get_dpi());
/* First look in local thumbnail cache folder. */
ImBuf *ibuf = IMB_thumb_read(filepath, THB_LARGE);
if (!ibuf) {
/* Not in cache, so extract from the blend file itself. */
BlendThumbnail *data = BLO_thumbnail_from_file(filepath);
ibuf = data ? BKE_main_thumbnail_to_imbuf(NULL, data) : NULL;
if (data) {
MEM_freeN(data);
}
}
const uchar *color = NULL;
if (!ibuf) {
/* No thumbnails found, so just use Blender logo. */
ibuf = UI_icon_alert_imbuf_get(ALERT_ICON_BLENDER);
color = UI_GetTheme()->tui.wcol_menu_back.text_sel;
IMB_premultiply_alpha(ibuf);
}
IMB_scaleImBuf(ibuf, dialog_width, (dialog_width * ibuf->y) / ibuf->x);
uiDefButImage(block, ibuf, 0, U.widget_unit, ibuf->x, ibuf->y, color);
uiItemS_ex(layout, 1.0f);
char filename[FILE_MAX];
BLI_path_split_file_part(filepath, filename, sizeof(filename));
uiItemL(layout, filename, ICON_NONE);
uiItemL_ex(layout, N_("Opening. Please wait..."), ICON_NONE, true, false);
UI_block_bounds_set_centered(block, 10 * UI_SCALE_FAC);
return block;
}
static void wm_read_callback_pre_wrapper(bContext *C, const char *filepath)
@ -994,6 +1061,28 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports)
/* so we can get the error message */
errno = 0;
#ifndef WITH_HEADLESS
if (!G.background) {
wmWindowManager *wm = CTX_wm_manager(C);
wmWindow *win = CTX_wm_window(C);
bool win_was_null = (win == NULL);
if (win_was_null) {
win = (wmWindow *)wm->windows.first;
CTX_wm_window_set(C, win);
}
if (win != NULL) {
UI_popup_block_invoke(C, wm_block_create_loading, (void *)filepath, NULL);
/* Redraw to remove any open menus and show loading block. */
WM_redraw_windows(C);
if (win_was_null) {
CTX_wm_window_set(C, NULL);
}
}
}
#endif /* WITH_HEADLESS */
WM_cursor_wait(true);
/* first try to append data from exotic file formats... */
@ -1057,7 +1146,7 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports)
bf_reports.duration.whole = PIL_check_seconds_timer() - bf_reports.duration.whole;
file_read_reports_finalize(&bf_reports);
WM_cursor_wait(true);
success = true;
}
}
@ -1162,6 +1251,8 @@ void wm_homefile_read_ex(bContext *C,
char filepath_startup[FILE_MAX];
char filepath_userdef[FILE_MAX];
WM_cursor_wait(true);
/* When 'app_template' is set:
* '{BLENDER_USER_CONFIG}/{app_template}' */
char app_template_system[FILE_MAX];
@ -1466,6 +1557,8 @@ void wm_homefile_read_ex(bContext *C,
CTX_wm_window_set(C, nullptr);
}
}
WM_cursor_wait(false);
}
void wm_homefile_read(bContext *C,