mirror of
https://github.com/godotengine/godot
synced 2024-09-05 05:58:29 +00:00
Make handling of rename line-edit popups more robust
This commit is contained in:
parent
259d576f6e
commit
eb2bd41fb8
|
@ -138,9 +138,7 @@ String FileSystemList::get_edit_text() {
|
|||
}
|
||||
|
||||
void FileSystemList::_text_editor_popup_modal_close() {
|
||||
if (Input::get_singleton()->is_key_pressed(Key::ESCAPE) ||
|
||||
Input::get_singleton()->is_key_pressed(Key::KP_ENTER) ||
|
||||
Input::get_singleton()->is_key_pressed(Key::ENTER)) {
|
||||
if (popup_editor->get_hide_reason() == Popup::HIDE_REASON_CANCELED) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -77,6 +77,9 @@ void Popup::_notification(int p_what) {
|
|||
_initialize_visible_parents();
|
||||
} else {
|
||||
_deinitialize_visible_parents();
|
||||
if (hide_reason == HIDE_REASON_NONE) {
|
||||
hide_reason = HIDE_REASON_CANCELED;
|
||||
}
|
||||
emit_signal(SNAME("popup_hide"));
|
||||
popped_up = false;
|
||||
}
|
||||
|
@ -87,6 +90,7 @@ void Popup::_notification(int p_what) {
|
|||
if (!is_in_edited_scene_root()) {
|
||||
if (has_focus()) {
|
||||
popped_up = true;
|
||||
hide_reason = HIDE_REASON_NONE;
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
@ -100,6 +104,7 @@ void Popup::_notification(int p_what) {
|
|||
|
||||
case NOTIFICATION_WM_CLOSE_REQUEST: {
|
||||
if (!is_in_edited_scene_root()) {
|
||||
hide_reason = HIDE_REASON_UNFOCUSED;
|
||||
_close_pressed();
|
||||
}
|
||||
} break;
|
||||
|
@ -114,6 +119,7 @@ void Popup::_notification(int p_what) {
|
|||
|
||||
void Popup::_parent_focused() {
|
||||
if (popped_up && get_flag(FLAG_POPUP)) {
|
||||
hide_reason = HIDE_REASON_UNFOCUSED;
|
||||
_close_pressed();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,16 @@ class Popup : public Window {
|
|||
LocalVector<Window *> visible_parents;
|
||||
bool popped_up = false;
|
||||
|
||||
public:
|
||||
enum HideReason {
|
||||
HIDE_REASON_NONE,
|
||||
HIDE_REASON_CANCELED, // E.g., because of rupture of UI flow (app unfocused). Includes closed programmatically.
|
||||
HIDE_REASON_UNFOCUSED, // E.g., user clicked outside.
|
||||
};
|
||||
|
||||
private:
|
||||
HideReason hide_reason = HIDE_REASON_NONE;
|
||||
|
||||
void _initialize_visible_parents();
|
||||
void _deinitialize_visible_parents();
|
||||
|
||||
|
@ -60,6 +70,8 @@ protected:
|
|||
virtual void _post_popup() override;
|
||||
|
||||
public:
|
||||
HideReason get_hide_reason() const { return hide_reason; }
|
||||
|
||||
Popup();
|
||||
~Popup();
|
||||
};
|
||||
|
|
|
@ -3152,9 +3152,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int
|
|||
}
|
||||
|
||||
void Tree::_text_editor_popup_modal_close() {
|
||||
if (Input::get_singleton()->is_key_pressed(Key::ESCAPE) ||
|
||||
Input::get_singleton()->is_key_pressed(Key::KP_ENTER) ||
|
||||
Input::get_singleton()->is_key_pressed(Key::ENTER)) {
|
||||
if (popup_editor->get_hide_reason() == Popup::HIDE_REASON_CANCELED) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue