Merge pull request #71209 from bruvzg/ed_progress_reparent

Automatically reparent editor progress dialog to avoid error spam.
This commit is contained in:
Rémi Verschelde 2023-01-13 00:29:48 +01:00 committed by GitHub
commit f79c58aac5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 6 deletions

View File

@ -608,6 +608,9 @@ void EditorNode::_notification(int p_what) {
} break; } break;
case NOTIFICATION_EXIT_TREE: { case NOTIFICATION_EXIT_TREE: {
if (progress_dialog) {
progress_dialog->queue_free();
}
editor_data.save_editor_external_data(); editor_data.save_editor_external_data();
FileAccess::set_file_close_fail_notify_callback(nullptr); FileAccess::set_file_close_fail_notify_callback(nullptr);
log->deinit(); // Do not get messages anymore. log->deinit(); // Do not get messages anymore.
@ -4308,7 +4311,7 @@ bool EditorNode::is_object_of_custom_type(const Object *p_object, const StringNa
void EditorNode::progress_add_task(const String &p_task, const String &p_label, int p_steps, bool p_can_cancel) { void EditorNode::progress_add_task(const String &p_task, const String &p_label, int p_steps, bool p_can_cancel) {
if (singleton->cmdline_export_mode) { if (singleton->cmdline_export_mode) {
print_line(p_task + ": begin: " + p_label + " steps: " + itos(p_steps)); print_line(p_task + ": begin: " + p_label + " steps: " + itos(p_steps));
} else { } else if (singleton->progress_dialog) {
singleton->progress_dialog->add_task(p_task, p_label, p_steps, p_can_cancel); singleton->progress_dialog->add_task(p_task, p_label, p_steps, p_can_cancel);
} }
} }
@ -4317,15 +4320,17 @@ bool EditorNode::progress_task_step(const String &p_task, const String &p_state,
if (singleton->cmdline_export_mode) { if (singleton->cmdline_export_mode) {
print_line("\t" + p_task + ": step " + itos(p_step) + ": " + p_state); print_line("\t" + p_task + ": step " + itos(p_step) + ": " + p_state);
return false; return false;
} else { } else if (singleton->progress_dialog) {
return singleton->progress_dialog->task_step(p_task, p_state, p_step, p_force_refresh); return singleton->progress_dialog->task_step(p_task, p_state, p_step, p_force_refresh);
} else {
return false;
} }
} }
void EditorNode::progress_end_task(const String &p_task) { void EditorNode::progress_end_task(const String &p_task) {
if (singleton->cmdline_export_mode) { if (singleton->cmdline_export_mode) {
print_line(p_task + ": end"); print_line(p_task + ": end");
} else { } else if (singleton->progress_dialog) {
singleton->progress_dialog->end_task(p_task); singleton->progress_dialog->end_task(p_task);
} }
} }
@ -6291,7 +6296,6 @@ EditorNode::EditorNode() {
resource_preview = memnew(EditorResourcePreview); resource_preview = memnew(EditorResourcePreview);
add_child(resource_preview); add_child(resource_preview);
progress_dialog = memnew(ProgressDialog); progress_dialog = memnew(ProgressDialog);
gui_base->add_child(progress_dialog);
// Take up all screen. // Take up all screen.
gui_base->set_anchor(SIDE_RIGHT, Control::ANCHOR_END); gui_base->set_anchor(SIDE_RIGHT, Control::ANCHOR_END);

View File

@ -32,6 +32,7 @@
#include "core/object/message_queue.h" #include "core/object/message_queue.h"
#include "core/os/os.h" #include "core/os/os.h"
#include "editor/editor_node.h"
#include "editor/editor_scale.h" #include "editor/editor_scale.h"
#include "main/main.h" #include "main/main.h"
#include "servers/display_server.h" #include "servers/display_server.h"
@ -133,6 +134,14 @@ void BackgroundProgress::end_task(const String &p_task) {
ProgressDialog *ProgressDialog::singleton = nullptr; ProgressDialog *ProgressDialog::singleton = nullptr;
void ProgressDialog::_notification(int p_what) { void ProgressDialog::_notification(int p_what) {
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
if (!is_visible()) {
Node *p = get_parent();
if (p) {
p->remove_child(this);
}
}
}
} }
void ProgressDialog::_popup() { void ProgressDialog::_popup() {
@ -146,8 +155,17 @@ void ProgressDialog::_popup() {
main->set_offset(SIDE_TOP, style->get_margin(SIDE_TOP)); main->set_offset(SIDE_TOP, style->get_margin(SIDE_TOP));
main->set_offset(SIDE_BOTTOM, -style->get_margin(SIDE_BOTTOM)); main->set_offset(SIDE_BOTTOM, -style->get_margin(SIDE_BOTTOM));
//raise(); EditorNode *ed = EditorNode::get_singleton();
popup_centered(ms); 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(ms);
}
}
} }
void ProgressDialog::add_task(const String &p_task, const String &p_label, int p_steps, bool p_can_cancel) { void ProgressDialog::add_task(const String &p_task, const String &p_label, int p_steps, bool p_can_cancel) {

View File

@ -285,6 +285,7 @@ public:
bool is_wrapping_controls() const; bool is_wrapping_controls() const;
void child_controls_changed(); void child_controls_changed();
Window *get_exclusive_child() const { return exclusive_child; };
Window *get_parent_visible_window() const; Window *get_parent_visible_window() const;
Viewport *get_parent_viewport() const; Viewport *get_parent_viewport() const;
void popup(const Rect2i &p_rect = Rect2i()); void popup(const Rect2i &p_rect = Rect2i());