summaryrefslogtreecommitdiffstats
path: root/editor
diff options
context:
space:
mode:
authorArman Elgudzhyan <48544263+puchik@users.noreply.github.com>2023-05-20 17:26:13 -0700
committerArman Elgudzhyan <48544263+puchik@users.noreply.github.com>2023-05-20 17:39:59 -0700
commit8ab2cf3d2d7efee7316955a5bb7bffb3ad81f7a5 (patch)
tree4c7cf862a380751232223b9a8ae721ff095352b3 /editor
parent809a98216267f3066b9fec2f02b2042bdc9d3e0d (diff)
downloadredot-engine-8ab2cf3d2d7efee7316955a5bb7bffb3ad81f7a5.tar.gz
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.
Diffstat (limited to 'editor')
-rw-r--r--editor/code_editor.cpp20
-rw-r--r--editor/editor_help.cpp20
-rw-r--r--editor/editor_layouts_dialog.cpp26
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp2
-rw-r--r--editor/plugins/theme_editor_plugin.cpp20
5 files changed, 24 insertions, 64 deletions
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp
index b188e1faca..43fc581023 100644
--- a/editor/code_editor.cpp
+++ b/editor/code_editor.cpp
@@ -122,24 +122,12 @@ void FindReplaceBar::unhandled_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());
Ref<InputEventKey> k = p_event;
- if (!k.is_valid() || !k->is_pressed()) {
- return;
- }
-
- Control *focus_owner = get_viewport()->gui_get_focus_owner();
- if (text_editor->has_focus() || (focus_owner && vbc_lineedit->is_ancestor_of(focus_owner))) {
- bool accepted = true;
- switch (k->get_keycode()) {
- case Key::ESCAPE: {
- _hide_bar();
- } break;
- default: {
- accepted = false;
- } break;
- }
+ if (k.is_valid() && k->is_action_pressed(SNAME("ui_cancel"), false, true)) {
+ Control *focus_owner = get_viewport()->gui_get_focus_owner();
- if (accepted) {
+ if (text_editor->has_focus() || (focus_owner && vbc_lineedit->is_ancestor_of(focus_owner))) {
+ _hide_bar();
accept_event();
}
}
diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp
index aee3574398..2ddde4e507 100644
--- a/editor/editor_help.cpp
+++ b/editor/editor_help.cpp
@@ -2698,22 +2698,10 @@ void FindBar::unhandled_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());
Ref<InputEventKey> k = p_event;
- if (k.is_valid()) {
- if (k->is_pressed() && (rich_text_label->has_focus() || is_ancestor_of(get_viewport()->gui_get_focus_owner()))) {
- bool accepted = true;
-
- switch (k->get_keycode()) {
- case Key::ESCAPE: {
- _hide_bar();
- } break;
- default: {
- accepted = false;
- } break;
- }
-
- if (accepted) {
- accept_event();
- }
+ if (k.is_valid() && k->is_action_pressed(SNAME("ui_cancel"), false, true)) {
+ if (rich_text_label->has_focus() || is_ancestor_of(get_viewport()->gui_get_focus_owner())) {
+ _hide_bar();
+ accept_event();
}
}
}
diff --git a/editor/editor_layouts_dialog.cpp b/editor/editor_layouts_dialog.cpp
index 31228ab57d..1f7172db57 100644
--- a/editor/editor_layouts_dialog.cpp
+++ b/editor/editor_layouts_dialog.cpp
@@ -42,25 +42,15 @@ void EditorLayoutsDialog::_line_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventKey> k = p_event;
if (k.is_valid()) {
- if (!k->is_pressed()) {
- return;
- }
-
- 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: {
+ if (k->is_action_pressed(SNAME("ui_accept"), false, true)) {
+ if (get_hide_on_ok()) {
hide();
- set_input_as_handled();
- } break;
- default:
- break;
+ }
+ ok_pressed();
+ set_input_as_handled();
+ } else if (k->is_action_pressed(SNAME("ui_cancel"), false, true)) {
+ hide();
+ set_input_as_handled();
}
}
}
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index 2a04f7b174..368c81a0f4 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -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
editor_selection->clear();
viewport->queue_redraw();
diff --git a/editor/plugins/theme_editor_plugin.cpp b/editor/plugins/theme_editor_plugin.cpp
index 715db9cf51..09053db122 100644
--- a/editor/plugins/theme_editor_plugin.cpp
+++ b/editor/plugins/theme_editor_plugin.cpp
@@ -1834,19 +1834,13 @@ void ThemeItemEditorDialog::_edit_theme_item_gui_input(const Ref<InputEvent> &p_
return;
}
- switch (k->get_keycode()) {
- case Key::KP_ENTER:
- case Key::ENTER: {
- _confirm_edit_theme_item();
- edit_theme_item_dialog->hide();
- edit_theme_item_dialog->set_input_as_handled();
- } break;
- case Key::ESCAPE: {
- edit_theme_item_dialog->hide();
- edit_theme_item_dialog->set_input_as_handled();
- } break;
- default:
- break;
+ if (k->is_action_pressed(SNAME("ui_accept"), false, true)) {
+ _confirm_edit_theme_item();
+ edit_theme_item_dialog->hide();
+ edit_theme_item_dialog->set_input_as_handled();
+ } else if (k->is_action_pressed(SNAME("ui_cancel"), false, true)) {
+ edit_theme_item_dialog->hide();
+ edit_theme_item_dialog->set_input_as_handled();
}
}
}