Pārlūkot izejas kodu

Merge pull request #78363 from Sauermann/fix-simplify-acceptdialog

Fix focusloss of non-exclusive `AcceptDialog` with `close_on_escape`
Rémi Verschelde 2 gadi atpakaļ
vecāks
revīzija
e125af0d05
2 mainītis faili ar 3 papildinājumiem un 35 dzēšanām
  1. 3 32
      scene/gui/dialogs.cpp
  2. 0 3
      scene/gui/dialogs.h

+ 3 - 32
scene/gui/dialogs.cpp

@@ -44,12 +44,6 @@ 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() {
 void AcceptDialog::_update_theme_item_cache() {
 	Window::_update_theme_item_cache();
 	Window::_update_theme_item_cache();
 
 
@@ -70,16 +64,6 @@ void AcceptDialog::_notification(int p_what) {
 					get_ok_button()->grab_focus();
 					get_ok_button()->grab_focus();
 				}
 				}
 				_update_child_rects();
 				_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;
 		} break;
 
 
@@ -92,10 +76,9 @@ void AcceptDialog::_notification(int p_what) {
 			}
 			}
 		} break;
 		} break;
 
 
-		case NOTIFICATION_EXIT_TREE: {
-			if (parent_visible) {
-				parent_visible->disconnect("focus_entered", callable_mp(this, &AcceptDialog::_parent_focused));
-				parent_visible = nullptr;
+		case NOTIFICATION_WM_WINDOW_FOCUS_OUT: {
+			if (close_on_escape && !is_exclusive()) {
+				_cancel_pressed();
 			}
 			}
 		} break;
 		} break;
 
 
@@ -129,21 +112,9 @@ void AcceptDialog::_ok_pressed() {
 }
 }
 
 
 void AcceptDialog::_cancel_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"));
 	call_deferred(SNAME("hide"));
-
 	emit_signal(SNAME("canceled"));
 	emit_signal(SNAME("canceled"));
-
 	cancel_pressed();
 	cancel_pressed();
-
-	if (parent_window) {
-		//parent_window->grab_focus();
-	}
 	set_input_as_handled();
 	set_input_as_handled();
 }
 }
 
 

+ 0 - 3
scene/gui/dialogs.h

@@ -44,8 +44,6 @@ class LineEdit;
 class AcceptDialog : public Window {
 class AcceptDialog : public Window {
 	GDCLASS(AcceptDialog, Window);
 	GDCLASS(AcceptDialog, Window);
 
 
-	Window *parent_visible = nullptr;
-
 	Panel *bg_panel = nullptr;
 	Panel *bg_panel = nullptr;
 	Label *message_label = nullptr;
 	Label *message_label = nullptr;
 	HBoxContainer *buttons_hbox = nullptr;
 	HBoxContainer *buttons_hbox = nullptr;
@@ -65,7 +63,6 @@ class AcceptDialog : public Window {
 	static bool swap_cancel_ok;
 	static bool swap_cancel_ok;
 
 
 	void _input_from_window(const Ref<InputEvent> &p_event);
 	void _input_from_window(const Ref<InputEvent> &p_event);
-	void _parent_focused();
 
 
 protected:
 protected:
 	virtual Size2 _get_contents_minimum_size() const override;
 	virtual Size2 _get_contents_minimum_size() const override;