Skip to content

Commit

Permalink
Merge pull request #92460 from bruvzg/adlg_cancel_conf
Browse files Browse the repository at this point in the history
Fix duplicate AcceptDialog cancel/confirm events.
  • Loading branch information
akien-mga committed May 29, 2024
2 parents 21810ca + 3e691e0 commit 9bb858c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 17 additions & 1 deletion scene/gui/dialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void AcceptDialog::_input_from_window(const Ref<InputEvent> &p_event) {
}

void AcceptDialog::_parent_focused() {
if (!is_exclusive() && get_flag(FLAG_POPUP)) {
if (popped_up && !is_exclusive() && get_flag(FLAG_POPUP)) {
_cancel_pressed();
}
}
Expand All @@ -71,13 +71,22 @@ void AcceptDialog::_notification(int p_what) {
parent_visible->connect(SceneStringName(focus_entered), callable_mp(this, &AcceptDialog::_parent_focused));
}
} else {
popped_up = false;
if (parent_visible) {
parent_visible->disconnect(SceneStringName(focus_entered), callable_mp(this, &AcceptDialog::_parent_focused));
parent_visible = nullptr;
}
}
} break;

case NOTIFICATION_WM_WINDOW_FOCUS_IN: {
if (!is_in_edited_scene_root()) {
if (has_focus()) {
popped_up = true;
}
}
} break;

case NOTIFICATION_THEME_CHANGED: {
bg_panel->add_theme_style_override("panel", theme_cache.panel_style);

Expand Down Expand Up @@ -114,8 +123,14 @@ void AcceptDialog::_text_submitted(const String &p_text) {
_ok_pressed();
}

void AcceptDialog::_post_popup() {
Window::_post_popup();
popped_up = true;
}

void AcceptDialog::_ok_pressed() {
if (hide_on_ok) {
popped_up = false;
set_visible(false);
}
ok_pressed();
Expand All @@ -124,6 +139,7 @@ void AcceptDialog::_ok_pressed() {
}

void AcceptDialog::_cancel_pressed() {
popped_up = false;
Window *parent_window = parent_visible;
if (parent_visible) {
parent_visible->disconnect(SceneStringName(focus_entered), callable_mp(this, &AcceptDialog::_parent_focused));
Expand Down
2 changes: 2 additions & 0 deletions scene/gui/dialogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class AcceptDialog : public Window {
HBoxContainer *buttons_hbox = nullptr;
Button *ok_button = nullptr;

bool popped_up = false;
bool hide_on_ok = true;
bool close_on_escape = true;

Expand All @@ -72,6 +73,7 @@ class AcceptDialog : public Window {
protected:
virtual Size2 _get_contents_minimum_size() const override;
virtual void _input_from_window(const Ref<InputEvent> &p_event) override;
virtual void _post_popup() override;

void _notification(int p_what);
static void _bind_methods();
Expand Down

0 comments on commit 9bb858c

Please sign in to comment.