WM: pass the window manager & window to WM_report_banner_show
Avoid potential problems when the active window is known but not assigned to `wm->winactive`, where the first window would be used as a fallback. Instead, take a window argument, a fallback is still used as a last resort (when NULL).
This commit is contained in:
@@ -3257,7 +3257,7 @@ bool ui_but_string_set(bContext *C, uiBut *but, const char *str)
|
||||
double value;
|
||||
|
||||
if (ui_but_string_eval_number(C, but, str, &value) == false) {
|
||||
WM_report_banner_show();
|
||||
WM_report_banner_show(CTX_wm_manager(C), CTX_wm_window(C));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -3558,7 +3558,7 @@ static void ui_textedit_end(bContext *C, uiBut *but, uiHandleButtonData *data)
|
||||
data->escapecancel = true;
|
||||
|
||||
WM_reportf(RPT_ERROR, "Failed to find '%s'", but->editstr);
|
||||
WM_report_banner_show();
|
||||
WM_report_banner_show(CTX_wm_manager(C), win);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -615,7 +615,7 @@ static void renamebutton_cb(bContext *C, void * /*arg1*/, char *oldname)
|
||||
errno = 0;
|
||||
if ((BLI_rename(orgname, newname) != 0) || !BLI_exists(newname)) {
|
||||
WM_reportf(RPT_ERROR, "Could not rename: %s", errno ? strerror(errno) : "unknown error");
|
||||
WM_report_banner_show();
|
||||
WM_report_banner_show(wm, win);
|
||||
}
|
||||
else {
|
||||
/* If rename is successful, scroll to newly renamed entry. */
|
||||
|
||||
@@ -597,8 +597,9 @@ void WM_main_remap_editor_id_reference(const struct IDRemapper *mappings);
|
||||
/* reports */
|
||||
/**
|
||||
* Show the report in the info header.
|
||||
* \param win: When NULL, a best-guess is used.
|
||||
*/
|
||||
void WM_report_banner_show(void);
|
||||
void WM_report_banner_show(struct wmWindowManager *wm, struct wmWindow *win) ATTR_NONNULL(1);
|
||||
/**
|
||||
* Hide all currently displayed banners and abort their timer.
|
||||
*/
|
||||
|
||||
@@ -882,10 +882,15 @@ static void wm_event_handler_ui_cancel(bContext *C)
|
||||
* Access to #wmWindowManager.reports
|
||||
* \{ */
|
||||
|
||||
void WM_report_banner_show()
|
||||
void WM_report_banner_show(wmWindowManager *wm, wmWindow *win)
|
||||
{
|
||||
wmWindowManager *wm = static_cast<wmWindowManager *>(G_MAIN->wm.first);
|
||||
wmWindow *win = wm->winactive ? wm->winactive : static_cast<wmWindow *>(wm->windows.first);
|
||||
if (win == nullptr) {
|
||||
win = wm->winactive;
|
||||
if (win == nullptr) {
|
||||
win = static_cast<wmWindow *>(wm->windows.first);
|
||||
}
|
||||
}
|
||||
|
||||
ReportList *wm_reports = &wm->reports;
|
||||
|
||||
/* After adding reports to the global list, reset the report timer. */
|
||||
@@ -921,7 +926,7 @@ static void wm_add_reports(ReportList *reports)
|
||||
/* Add reports to the global list, otherwise they are not seen. */
|
||||
BLI_movelisttolist(&wm->reports.list, &reports->list);
|
||||
|
||||
WM_report_banner_show();
|
||||
WM_report_banner_show(wm, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2812,7 +2817,7 @@ static eHandlerActionFlag wm_handler_fileselect_do(bContext *C,
|
||||
BLI_movelisttolist(&CTX_wm_reports(C)->list, &handler->op->reports->list);
|
||||
|
||||
/* More hacks, since we meddle with reports, banner display doesn't happen automatic. */
|
||||
WM_report_banner_show();
|
||||
WM_report_banner_show(CTX_wm_manager(C), CTX_wm_window(C));
|
||||
|
||||
CTX_wm_window_set(C, win_prev);
|
||||
CTX_wm_area_set(C, area_prev);
|
||||
|
||||
@@ -603,29 +603,28 @@ void WM_file_autoexec_init(const char *filepath)
|
||||
}
|
||||
}
|
||||
|
||||
void wm_file_read_report(bContext *C, Main *bmain)
|
||||
void wm_file_read_report(Main *bmain, wmWindow *win)
|
||||
{
|
||||
ReportList *reports = nullptr;
|
||||
wmWindowManager *wm = static_cast<wmWindowManager *>(bmain->wm.first);
|
||||
ReportList *reports = &wm->reports;
|
||||
bool found = false;
|
||||
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
|
||||
if (scene->r.engine[0] &&
|
||||
BLI_findstring(&R_engines, scene->r.engine, offsetof(RenderEngineType, idname)) == nullptr)
|
||||
{
|
||||
if (reports == nullptr) {
|
||||
reports = CTX_wm_reports(C);
|
||||
}
|
||||
|
||||
BKE_reportf(reports,
|
||||
RPT_ERROR,
|
||||
"Engine '%s' not available for scene '%s' (an add-on may need to be installed "
|
||||
"or enabled)",
|
||||
scene->r.engine,
|
||||
scene->id.name + 2);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (reports) {
|
||||
if (found) {
|
||||
if (!G.background) {
|
||||
WM_report_banner_show();
|
||||
WM_report_banner_show(wm, win);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -778,7 +777,7 @@ static void wm_file_read_post(bContext *C, const wmFileReadPost_Params *params)
|
||||
/* report any errors.
|
||||
* currently disabled if addons aren't yet loaded */
|
||||
if (addons_loaded) {
|
||||
wm_file_read_report(C, bmain);
|
||||
wm_file_read_report(bmain, static_cast<wmWindow *>(wm->windows.first));
|
||||
}
|
||||
|
||||
if (use_data) {
|
||||
@@ -3739,6 +3738,7 @@ static void wm_block_file_close_discard(bContext *C, void *arg_block, void *arg_
|
||||
static void wm_block_file_close_save(bContext *C, void *arg_block, void *arg_data)
|
||||
{
|
||||
const Main *bmain = CTX_data_main(C);
|
||||
wmWindowManager *wm = static_cast<wmWindowManager *>(bmain->wm.first);
|
||||
wmGenericCallback *callback = WM_generic_callback_steal((wmGenericCallback *)arg_data);
|
||||
bool execute_callback = true;
|
||||
|
||||
@@ -3750,7 +3750,7 @@ static void wm_block_file_close_save(bContext *C, void *arg_block, void *arg_dat
|
||||
if (ED_image_should_save_modified(bmain)) {
|
||||
ReportList *reports = CTX_wm_reports(C);
|
||||
ED_image_save_all_modified(C, reports);
|
||||
WM_report_banner_show();
|
||||
WM_report_banner_show(wm, win);
|
||||
}
|
||||
else {
|
||||
execute_callback = false;
|
||||
|
||||
@@ -75,7 +75,7 @@ void wm_homefile_read(struct bContext *C,
|
||||
void wm_homefile_read_post(struct bContext *C,
|
||||
const struct wmFileReadPost_Params *params_file_read_post);
|
||||
|
||||
void wm_file_read_report(bContext *C, struct Main *bmain);
|
||||
void wm_file_read_report(struct Main *bmain, struct wmWindow *win);
|
||||
|
||||
void wm_close_file_dialog(bContext *C, struct wmGenericCallback *post_action);
|
||||
/**
|
||||
|
||||
@@ -43,10 +43,12 @@ static void wm_xr_error_handler(const GHOST_XrError *error)
|
||||
{
|
||||
wmXrErrorHandlerData *handler_data = error->customdata;
|
||||
wmWindowManager *wm = handler_data->wm;
|
||||
wmWindow *root_win = wm->xr.runtime ? wm->xr.runtime->session_root_win : NULL;
|
||||
|
||||
BKE_reports_clear(&wm->reports);
|
||||
WM_report(RPT_ERROR, error->user_message);
|
||||
WM_report_banner_show();
|
||||
/* Rely on the fallback when `root_win` is NULL. */
|
||||
WM_report_banner_show(wm, root_win);
|
||||
|
||||
if (wm->xr.runtime) {
|
||||
/* Just play safe and destroy the entire runtime data, including context. */
|
||||
|
||||
Reference in New Issue
Block a user