1
0
mirror of https://github.com/godotengine/godot.git synced 2025-12-02 16:48:55 +00:00

Use defined key mapping for closing popups and dialogs

As opposed to hardcoding the escape key. Also removed such hardcoding in a few other places as well as a hardcoded enter key in one of the affected input fields.
This commit is contained in:
Arman Elgudzhyan
2023-05-20 17:26:13 -07:00
parent 809a982162
commit 8ab2cf3d2d
7 changed files with 26 additions and 66 deletions

View File

@@ -122,24 +122,12 @@ void FindReplaceBar::unhandled_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null()); ERR_FAIL_COND(p_event.is_null());
Ref<InputEventKey> k = p_event; Ref<InputEventKey> k = p_event;
if (!k.is_valid() || !k->is_pressed()) {
return;
}
Control *focus_owner = get_viewport()->gui_get_focus_owner(); if (k.is_valid() && k->is_action_pressed(SNAME("ui_cancel"), false, true)) {
if (text_editor->has_focus() || (focus_owner && vbc_lineedit->is_ancestor_of(focus_owner))) { Control *focus_owner = get_viewport()->gui_get_focus_owner();
bool accepted = true;
switch (k->get_keycode()) { if (text_editor->has_focus() || (focus_owner && vbc_lineedit->is_ancestor_of(focus_owner))) {
case Key::ESCAPE: { _hide_bar();
_hide_bar();
} break;
default: {
accepted = false;
} break;
}
if (accepted) {
accept_event(); accept_event();
} }
} }

View File

@@ -2698,22 +2698,10 @@ void FindBar::unhandled_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null()); ERR_FAIL_COND(p_event.is_null());
Ref<InputEventKey> k = p_event; Ref<InputEventKey> k = p_event;
if (k.is_valid()) { if (k.is_valid() && k->is_action_pressed(SNAME("ui_cancel"), false, true)) {
if (k->is_pressed() && (rich_text_label->has_focus() || is_ancestor_of(get_viewport()->gui_get_focus_owner()))) { if (rich_text_label->has_focus() || is_ancestor_of(get_viewport()->gui_get_focus_owner())) {
bool accepted = true; _hide_bar();
accept_event();
switch (k->get_keycode()) {
case Key::ESCAPE: {
_hide_bar();
} break;
default: {
accepted = false;
} break;
}
if (accepted) {
accept_event();
}
} }
} }
} }

View File

@@ -42,25 +42,15 @@ void EditorLayoutsDialog::_line_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventKey> k = p_event; Ref<InputEventKey> k = p_event;
if (k.is_valid()) { if (k.is_valid()) {
if (!k->is_pressed()) { if (k->is_action_pressed(SNAME("ui_accept"), false, true)) {
return; if (get_hide_on_ok()) {
}
switch (k->get_keycode()) {
case Key::KP_ENTER:
case Key::ENTER: {
if (get_hide_on_ok()) {
hide();
}
ok_pressed();
set_input_as_handled();
} break;
case Key::ESCAPE: {
hide(); hide();
set_input_as_handled(); }
} break; ok_pressed();
default: set_input_as_handled();
break; } else if (k->is_action_pressed(SNAME("ui_cancel"), false, true)) {
hide();
set_input_as_handled();
} }
} }
} }

View File

@@ -2415,7 +2415,7 @@ bool CanvasItemEditor::_gui_input_select(const Ref<InputEvent> &p_event) {
} }
} }
if (k.is_valid() && k->is_pressed() && k->get_keycode() == Key::ESCAPE && drag_type == DRAG_NONE && tool == TOOL_SELECT) { if (k.is_valid() && k->is_action_pressed(SNAME("ui_cancel"), false, true) && drag_type == DRAG_NONE && tool == TOOL_SELECT) {
// Unselect everything // Unselect everything
editor_selection->clear(); editor_selection->clear();
viewport->queue_redraw(); viewport->queue_redraw();

View File

@@ -1834,19 +1834,13 @@ void ThemeItemEditorDialog::_edit_theme_item_gui_input(const Ref<InputEvent> &p_
return; return;
} }
switch (k->get_keycode()) { if (k->is_action_pressed(SNAME("ui_accept"), false, true)) {
case Key::KP_ENTER: _confirm_edit_theme_item();
case Key::ENTER: { edit_theme_item_dialog->hide();
_confirm_edit_theme_item(); edit_theme_item_dialog->set_input_as_handled();
edit_theme_item_dialog->hide(); } else if (k->is_action_pressed(SNAME("ui_cancel"), false, true)) {
edit_theme_item_dialog->set_input_as_handled(); edit_theme_item_dialog->hide();
} break; edit_theme_item_dialog->set_input_as_handled();
case Key::ESCAPE: {
edit_theme_item_dialog->hide();
edit_theme_item_dialog->set_input_as_handled();
} break;
default:
break;
} }
} }
} }

View File

@@ -39,7 +39,7 @@
void AcceptDialog::_input_from_window(const Ref<InputEvent> &p_event) { void AcceptDialog::_input_from_window(const Ref<InputEvent> &p_event) {
Ref<InputEventKey> key = p_event; Ref<InputEventKey> key = p_event;
if (close_on_escape && key.is_valid() && key->is_pressed() && key->get_keycode() == Key::ESCAPE) { if (close_on_escape && key.is_valid() && key->is_action_pressed(SNAME("ui_cancel"), false, true)) {
_cancel_pressed(); _cancel_pressed();
} }
} }

View File

@@ -36,7 +36,7 @@
void Popup::_input_from_window(const Ref<InputEvent> &p_event) { void Popup::_input_from_window(const Ref<InputEvent> &p_event) {
Ref<InputEventKey> key = p_event; Ref<InputEventKey> key = p_event;
if (get_flag(FLAG_POPUP) && key.is_valid() && key->is_pressed() && key->get_keycode() == Key::ESCAPE) { if (get_flag(FLAG_POPUP) && key.is_valid() && key->is_action_pressed(SNAME("ui_cancel"), false, true)) {
_close_pressed(); _close_pressed();
} }
} }