Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Fix focusloss of non-exclusive AcceptDialog with close_on_escape" #79084

Merged
merged 1 commit into from Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 32 additions & 3 deletions scene/gui/dialogs.cpp
Expand Up @@ -44,6 +44,12 @@ void AcceptDialog::_input_from_window(const Ref<InputEvent> &p_event) {
}
}

void AcceptDialog::_parent_focused() {
if (close_on_escape && !is_exclusive()) {
_cancel_pressed();
}
}

void AcceptDialog::_update_theme_item_cache() {
Window::_update_theme_item_cache();

Expand All @@ -64,6 +70,16 @@ void AcceptDialog::_notification(int p_what) {
get_ok_button()->grab_focus();
}
_update_child_rects();

parent_visible = get_parent_visible_window();
if (parent_visible) {
parent_visible->connect("focus_entered", callable_mp(this, &AcceptDialog::_parent_focused));
}
} else {
if (parent_visible) {
parent_visible->disconnect("focus_entered", callable_mp(this, &AcceptDialog::_parent_focused));
parent_visible = nullptr;
}
}
} break;

Expand All @@ -76,9 +92,10 @@ void AcceptDialog::_notification(int p_what) {
}
} break;

case NOTIFICATION_WM_WINDOW_FOCUS_OUT: {
if (close_on_escape && !is_exclusive()) {
_cancel_pressed();
case NOTIFICATION_EXIT_TREE: {
if (parent_visible) {
parent_visible->disconnect("focus_entered", callable_mp(this, &AcceptDialog::_parent_focused));
parent_visible = nullptr;
}
} break;

Expand Down Expand Up @@ -112,9 +129,21 @@ void AcceptDialog::_ok_pressed() {
}

void AcceptDialog::_cancel_pressed() {
Window *parent_window = parent_visible;
if (parent_visible) {
parent_visible->disconnect("focus_entered", callable_mp(this, &AcceptDialog::_parent_focused));
parent_visible = nullptr;
}

call_deferred(SNAME("hide"));

emit_signal(SNAME("canceled"));

cancel_pressed();

if (parent_window) {
//parent_window->grab_focus();
}
set_input_as_handled();
}

Expand Down
3 changes: 3 additions & 0 deletions scene/gui/dialogs.h
Expand Up @@ -44,6 +44,8 @@ class LineEdit;
class AcceptDialog : public Window {
GDCLASS(AcceptDialog, Window);

Window *parent_visible = nullptr;

Panel *bg_panel = nullptr;
Label *message_label = nullptr;
HBoxContainer *buttons_hbox = nullptr;
Expand All @@ -63,6 +65,7 @@ class AcceptDialog : public Window {
static bool swap_cancel_ok;

void _input_from_window(const Ref<InputEvent> &p_event);
void _parent_focused();

protected:
virtual Size2 _get_contents_minimum_size() const override;
Expand Down