Skip to content

Commit 316c4d5

Browse files
committed
Merge pull request godotengine#91112 from RandomShaper/fix_double_confirm
Avoid double handling of rename in the file system dock
2 parents 594498e + eb2bd41 commit 316c4d5

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

editor/filesystem_dock.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,7 @@ String FileSystemList::get_edit_text() {
138138
}
139139

140140
void FileSystemList::_text_editor_popup_modal_close() {
141-
if (Input::get_singleton()->is_key_pressed(Key::ESCAPE) ||
142-
Input::get_singleton()->is_key_pressed(Key::KP_ENTER) ||
143-
Input::get_singleton()->is_key_pressed(Key::ENTER)) {
141+
if (popup_editor->get_hide_reason() == Popup::HIDE_REASON_CANCELED) {
144142
return;
145143
}
146144

scene/gui/popup.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ void Popup::_notification(int p_what) {
7777
_initialize_visible_parents();
7878
} else {
7979
_deinitialize_visible_parents();
80+
if (hide_reason == HIDE_REASON_NONE) {
81+
hide_reason = HIDE_REASON_CANCELED;
82+
}
8083
emit_signal(SNAME("popup_hide"));
8184
popped_up = false;
8285
}
@@ -87,6 +90,7 @@ void Popup::_notification(int p_what) {
8790
if (!is_in_edited_scene_root()) {
8891
if (has_focus()) {
8992
popped_up = true;
93+
hide_reason = HIDE_REASON_NONE;
9094
}
9195
}
9296
} break;
@@ -100,6 +104,7 @@ void Popup::_notification(int p_what) {
100104

101105
case NOTIFICATION_WM_CLOSE_REQUEST: {
102106
if (!is_in_edited_scene_root()) {
107+
hide_reason = HIDE_REASON_UNFOCUSED;
103108
_close_pressed();
104109
}
105110
} break;
@@ -114,6 +119,7 @@ void Popup::_notification(int p_what) {
114119

115120
void Popup::_parent_focused() {
116121
if (popped_up && get_flag(FLAG_POPUP)) {
122+
hide_reason = HIDE_REASON_UNFOCUSED;
117123
_close_pressed();
118124
}
119125
}

scene/gui/popup.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ class Popup : public Window {
4343
LocalVector<Window *> visible_parents;
4444
bool popped_up = false;
4545

46+
public:
47+
enum HideReason {
48+
HIDE_REASON_NONE,
49+
HIDE_REASON_CANCELED, // E.g., because of rupture of UI flow (app unfocused). Includes closed programmatically.
50+
HIDE_REASON_UNFOCUSED, // E.g., user clicked outside.
51+
};
52+
53+
private:
54+
HideReason hide_reason = HIDE_REASON_NONE;
55+
4656
void _initialize_visible_parents();
4757
void _deinitialize_visible_parents();
4858

@@ -60,6 +70,8 @@ class Popup : public Window {
6070
virtual void _post_popup() override;
6171

6272
public:
73+
HideReason get_hide_reason() const { return hide_reason; }
74+
6375
Popup();
6476
~Popup();
6577
};

scene/gui/tree.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3152,9 +3152,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int
31523152
}
31533153

31543154
void Tree::_text_editor_popup_modal_close() {
3155-
if (Input::get_singleton()->is_key_pressed(Key::ESCAPE) ||
3156-
Input::get_singleton()->is_key_pressed(Key::KP_ENTER) ||
3157-
Input::get_singleton()->is_key_pressed(Key::ENTER)) {
3155+
if (popup_editor->get_hide_reason() == Popup::HIDE_REASON_CANCELED) {
31583156
return;
31593157
}
31603158

0 commit comments

Comments
 (0)