summaryrefslogtreecommitdiffstats
path: root/editor/editor_node.cpp
diff options
context:
space:
mode:
authorbruvzg <7645683+bruvzg@users.noreply.github.com>2023-02-15 16:35:16 +0200
committerbruvzg <7645683+bruvzg@users.noreply.github.com>2023-02-21 12:32:11 +0200
commit921f3b7589084e07a4b6eefd89ec7fe81857a8b7 (patch)
tree31ec1014899b5e50d48e37147efe504c06a9c2c1 /editor/editor_node.cpp
parent6cde3fac328e97e66b1c12d386deb25af395e215 (diff)
downloadredot-engine-921f3b7589084e07a4b6eefd89ec7fe81857a8b7.tar.gz
Automatically reparent editor message dialogs to avoid error spam.
Diffstat (limited to 'editor/editor_node.cpp')
-rw-r--r--editor/editor_node.cpp132
1 files changed, 99 insertions, 33 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 3555caac8a..49f32e5990 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -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));