Automatically reparent editor message dialogs to avoid error spam.

This commit is contained in:
bruvzg 2023-02-15 16:35:16 +02:00
parent 6cde3fac32
commit 921f3b7589
No known key found for this signature in database
GPG key ID: 7960FCF39844EC38
6 changed files with 113 additions and 44 deletions

View file

@ -151,6 +151,51 @@ EditorNode *EditorNode::singleton = nullptr;
// The metadata key used to store and retrieve the version text to copy to the clipboard.
static const String META_TEXT_TO_COPY = "text_to_copy";
class AcceptDialogAutoReparent : public AcceptDialog {
GDCLASS(AcceptDialogAutoReparent, AcceptDialog);
protected:
void _notification(int p_what) {
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
if (!is_visible()) {
Node *p = get_parent();
if (p) {
p->remove_child(this);
}
}
}
}
public:
void attach_and_popup_centered() {
EditorNode *ed = EditorNode::get_singleton();
if (ed && !is_inside_tree()) {
Window *w = ed->get_window();
while (w && w->get_exclusive_child()) {
w = w->get_exclusive_child();
}
if (w && w != this) {
w->add_child(this);
popup_centered();
}
}
}
void attach_and_popup_centered_ratio(float p_ratio = 0.8) {
EditorNode *ed = EditorNode::get_singleton();
if (ed && !is_inside_tree()) {
Window *w = ed->get_window();
while (w && w->get_exclusive_child()) {
w = w->get_exclusive_child();
}
if (w && w != this) {
w->add_child(this);
popup_centered_ratio(p_ratio);
}
}
}
};
void EditorNode::disambiguate_filenames(const Vector<String> p_full_paths, Vector<String> &r_filenames) {
ERR_FAIL_COND_MSG(p_full_paths.size() != r_filenames.size(), vformat("disambiguate_filenames requires two string vectors of same length (%d != %d).", p_full_paths.size(), r_filenames.size()));
@ -615,6 +660,21 @@ void EditorNode::_notification(int p_what) {
if (progress_dialog) {
progress_dialog->queue_free();
}
if (load_error_dialog) {
load_error_dialog->queue_free();
}
if (execute_output_dialog) {
execute_output_dialog->queue_free();
}
if (warning) {
warning->queue_free();
}
if (accept) {
accept->queue_free();
}
if (save_accept) {
save_accept->queue_free();
}
editor_data.save_editor_external_data();
FileAccess::set_file_close_fail_notify_callback(nullptr);
log->deinit(); // Do not get messages anymore.
@ -4246,9 +4306,11 @@ void EditorNode::add_io_error(const String &p_error) {
void EditorNode::_load_error_notify(void *p_ud, const String &p_text) {
EditorNode *en = static_cast<EditorNode *>(p_ud);
en->load_errors->add_image(en->gui_base->get_theme_icon(SNAME("Error"), SNAME("EditorIcons")));
en->load_errors->add_text(p_text + "\n");
en->load_error_dialog->popup_centered_ratio(0.5);
if (en && en->load_error_dialog) {
en->load_errors->add_image(en->gui_base->get_theme_icon(SNAME("Error"), SNAME("EditorIcons")));
en->load_errors->add_text(p_text + "\n");
en->load_error_dialog->attach_and_popup_centered_ratio(0.5);
}
}
bool EditorNode::_find_scene_in_use(Node *p_node, const String &p_path) const {
@ -4619,23 +4681,27 @@ Error EditorNode::export_preset(const String &p_preset, const String &p_path, bo
void EditorNode::show_accept(const String &p_text, const String &p_title) {
current_menu_option = -1;
accept->set_ok_button_text(p_title);
accept->set_text(p_text);
accept->popup_centered();
if (accept) {
accept->set_ok_button_text(p_title);
accept->set_text(p_text);
accept->attach_and_popup_centered();
}
}
void EditorNode::show_save_accept(const String &p_text, const String &p_title) {
current_menu_option = -1;
save_accept->set_ok_button_text(p_title);
save_accept->set_text(p_text);
save_accept->popup_centered();
if (save_accept) {
save_accept->set_ok_button_text(p_title);
save_accept->set_text(p_text);
save_accept->attach_and_popup_centered();
}
}
void EditorNode::show_warning(const String &p_text, const String &p_title) {
if (warning->is_inside_tree()) {
if (warning) {
warning->set_text(p_text);
warning->set_title(p_title);
warning->popup_centered();
warning->attach_and_popup_centered();
} else {
WARN_PRINT(p_title + " " + p_text);
}
@ -6517,11 +6583,13 @@ static void _execute_thread(void *p_ud) {
}
int EditorNode::execute_and_show_output(const String &p_title, const String &p_path, const List<String> &p_arguments, bool p_close_on_ok, bool p_close_on_errors) {
execute_output_dialog->set_title(p_title);
execute_output_dialog->get_ok_button()->set_disabled(true);
execute_outputs->clear();
execute_outputs->set_scroll_follow(true);
execute_output_dialog->popup_centered_ratio();
if (execute_output_dialog) {
execute_output_dialog->set_title(p_title);
execute_output_dialog->get_ok_button()->set_disabled(true);
execute_outputs->clear();
execute_outputs->set_scroll_follow(true);
execute_output_dialog->attach_and_popup_centered_ratio();
}
ExecuteThreadArgs eta;
eta.path = p_path;
@ -6539,6 +6607,7 @@ int EditorNode::execute_and_show_output(const String &p_title, const String &p_p
String to_add = eta.output.substr(prev_len, eta.output.length());
prev_len = eta.output.length();
execute_outputs->add_text(to_add);
DisplayServer::get_singleton()->process_events(); // Get rid of pending events.
Main::iteration();
}
}
@ -6548,14 +6617,16 @@ int EditorNode::execute_and_show_output(const String &p_title, const String &p_p
eta.execute_output_thread.wait_to_finish();
execute_outputs->add_text("\nExit Code: " + itos(eta.exitcode));
if (p_close_on_errors && eta.exitcode != 0) {
execute_output_dialog->hide();
}
if (p_close_on_ok && eta.exitcode == 0) {
execute_output_dialog->hide();
}
if (execute_output_dialog) {
if (p_close_on_errors && eta.exitcode != 0) {
execute_output_dialog->hide();
}
if (p_close_on_ok && eta.exitcode == 0) {
execute_output_dialog->hide();
}
execute_output_dialog->get_ok_button()->set_disabled(false);
execute_output_dialog->get_ok_button()->set_disabled(false);
}
return eta.exitcode;
}
@ -7126,12 +7197,10 @@ EditorNode::EditorNode() {
prev_scene->set_position(Point2(3, 24));
prev_scene->hide();
accept = memnew(AcceptDialog);
gui_base->add_child(accept);
accept = memnew(AcceptDialogAutoReparent);
accept->connect("confirmed", callable_mp(this, &EditorNode::_menu_confirm_current));
save_accept = memnew(AcceptDialog);
gui_base->add_child(save_accept);
save_accept = memnew(AcceptDialogAutoReparent);
save_accept->connect("confirmed", callable_mp(this, &EditorNode::_menu_option).bind((int)MenuOptions::FILE_SAVE_AS_SCENE));
project_export = memnew(ProjectExportDialog);
@ -7176,9 +7245,8 @@ EditorNode::EditorNode() {
gui_base->add_child(fbx_importer_manager);
#endif
warning = memnew(AcceptDialog);
warning = memnew(AcceptDialogAutoReparent);
warning->add_button(TTR("Copy Text"), true, "copy");
gui_base->add_child(warning);
warning->connect("custom_action", callable_mp(this, &EditorNode::_copy_warning));
ED_SHORTCUT("editor/next_tab", TTR("Next Scene Tab"), KeyModifierMask::CMD_OR_CTRL + Key::TAB);
@ -7946,17 +8014,15 @@ EditorNode::EditorNode() {
set_process_shortcut_input(true);
load_errors = memnew(RichTextLabel);
load_error_dialog = memnew(AcceptDialog);
load_error_dialog = memnew(AcceptDialogAutoReparent);
load_error_dialog->add_child(load_errors);
load_error_dialog->set_title(TTR("Load Errors"));
gui_base->add_child(load_error_dialog);
execute_outputs = memnew(RichTextLabel);
execute_outputs->set_selection_enabled(true);
execute_output_dialog = memnew(AcceptDialog);
execute_output_dialog = memnew(AcceptDialogAutoReparent);
execute_output_dialog->add_child(execute_outputs);
execute_output_dialog->set_title("");
gui_base->add_child(execute_output_dialog);
EditorFileSystem::get_singleton()->connect("sources_changed", callable_mp(this, &EditorNode::_sources_changed));
EditorFileSystem::get_singleton()->connect("filesystem_changed", callable_mp(this, &EditorNode::_fs_changed));

View file

@ -45,6 +45,7 @@ typedef void (*EditorPluginInitializeCallback)();
typedef bool (*EditorBuildCallback)();
class AcceptDialog;
class AcceptDialogAutoReparent;
class AudioStreamPreviewGenerator;
class BackgroundProgress;
class CenterContainer;
@ -370,10 +371,10 @@ private:
PluginConfigDialog *plugin_config_dialog = nullptr;
RichTextLabel *load_errors = nullptr;
AcceptDialog *load_error_dialog = nullptr;
AcceptDialogAutoReparent *load_error_dialog = nullptr;
RichTextLabel *execute_outputs = nullptr;
AcceptDialog *execute_output_dialog = nullptr;
AcceptDialogAutoReparent *execute_output_dialog = nullptr;
Ref<Theme> theme;
@ -388,10 +389,10 @@ private:
ConfirmationDialog *import_confirmation = nullptr;
ConfirmationDialog *pick_main_scene = nullptr;
Button *select_current_scene_button = nullptr;
AcceptDialog *accept = nullptr;
AcceptDialog *save_accept = nullptr;
AcceptDialogAutoReparent *accept = nullptr;
AcceptDialogAutoReparent *save_accept = nullptr;
EditorAbout *about = nullptr;
AcceptDialog *warning = nullptr;
AcceptDialogAutoReparent *warning = nullptr;
int overridden_default_layout = -1;
Ref<ConfigFile> default_layout;

View file

@ -137,6 +137,7 @@ Vector<Ref<Texture2D>> EditorInterface::make_mesh_previews(const Vector<Ref<Mesh
RS::get_singleton()->instance_set_transform(light_instance2, xform * Transform3D().looking_at(Vector3(+1, -1, -2), Vector3(0, 1, 0)));
ep.step(TTR("Thumbnail..."), i);
DisplayServer::get_singleton()->process_events();
Main::iteration();
Main::iteration();
Ref<Image> img = RS::get_singleton()->texture_2d_get(viewport_texture);

View file

@ -943,8 +943,8 @@ void ProjectExportDialog::_export_pck_zip_selected(const String &p_path) {
}
void ProjectExportDialog::_open_export_template_manager() {
EditorNode::get_singleton()->open_export_template_manager();
hide();
EditorNode::get_singleton()->open_export_template_manager();
}
void ProjectExportDialog::_validate_export_path(const String &p_path) {

View file

@ -221,9 +221,7 @@ bool ProgressDialog::task_step(const String &p_task, const String &p_state, int
t.state->set_text(p_state);
last_progress_tick = OS::get_singleton()->get_ticks_usec();
if (cancel_hb->is_visible()) {
DisplayServer::get_singleton()->process_events();
}
DisplayServer::get_singleton()->process_events();
#ifndef ANDROID_ENABLED
Main::iteration(); // this will not work on a lot of platforms, so it's only meant for the editor

View file

@ -1365,8 +1365,11 @@ void Window::_window_input(const Ref<InputEvent> &p_ev) {
emit_signal(SceneStringNames::get_singleton()->window_input, p_ev);
push_input(p_ev);
if (!is_input_handled()) {
if (is_inside_tree()) {
push_input(p_ev);
}
if (!is_input_handled() && is_inside_tree()) {
push_unhandled_input(p_ev);
}
}