Skip to content

Commit

Permalink
Merge pull request #77297 from puchik/popup-close-key-mapping
Browse files Browse the repository at this point in the history
Use defined key mapping for closing popups and dialogs
  • Loading branch information
akien-mga committed May 23, 2023
2 parents 7b802ed + 8ab2cf3 commit 8f9e067
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 66 deletions.
20 changes: 4 additions & 16 deletions editor/code_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
20 changes: 4 additions & 16 deletions editor/editor_help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand Down
26 changes: 8 additions & 18 deletions editor/editor_layouts_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/canvas_item_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
20 changes: 7 additions & 13 deletions editor/plugins/theme_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion scene/gui/dialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

void AcceptDialog::_input_from_window(const Ref<InputEvent> &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();
}
}
Expand Down
2 changes: 1 addition & 1 deletion scene/gui/popup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

void Popup::_input_from_window(const Ref<InputEvent> &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();
}
}
Expand Down

0 comments on commit 8f9e067

Please sign in to comment.