diff --git a/core/input/input_map.cpp b/core/input/input_map.cpp index b39e46c7254..faf32e072b4 100644 --- a/core/input/input_map.cpp +++ b/core/input/input_map.cpp @@ -334,6 +334,7 @@ static const _BuiltinActionDisplayName _builtin_action_display_names[] = { { "ui_accept", TTRC("Accept") }, { "ui_select", TTRC("Select") }, { "ui_cancel", TTRC("Cancel") }, + { "ui_close_dialog", TTRC("Close Dialog") }, { "ui_focus_next", TTRC("Focus Next") }, { "ui_focus_prev", TTRC("Focus Prev") }, { "ui_left", TTRC("Left") }, @@ -447,6 +448,15 @@ const HashMap>> &InputMap::get_builtins() { inputs.push_back(InputEventKey::create_reference(Key::ESCAPE)); default_builtin_cache.insert("ui_cancel", inputs); + inputs = List>(); + inputs.push_back(InputEventKey::create_reference(Key::ESCAPE)); + default_builtin_cache.insert("ui_close_dialog", inputs); + + inputs = List>(); + inputs.push_back(InputEventKey::create_reference(Key::W | KeyModifierMask::META)); + inputs.push_back(InputEventKey::create_reference(Key::ESCAPE)); + default_builtin_cache.insert("ui_close_dialog.macos", inputs); + inputs = List>(); inputs.push_back(InputEventKey::create_reference(Key::TAB)); default_builtin_cache.insert("ui_focus_next", inputs); diff --git a/doc/classes/AcceptDialog.xml b/doc/classes/AcceptDialog.xml index a5b589842a8..80956e48c48 100644 --- a/doc/classes/AcceptDialog.xml +++ b/doc/classes/AcceptDialog.xml @@ -62,7 +62,7 @@ Sets autowrapping for the text in the dialog. - If [code]true[/code], the dialog will be hidden when the [code]ui_cancel[/code] action is pressed (by default, this action is bound to [constant KEY_ESCAPE]). + If [code]true[/code], the dialog will be hidden when the [code]ui_close_dialog[/code] action is pressed (by default, this action is bound to [kbd]Escape[/kbd], or [kbd]Cmd + W[/kbd] on macOS). If [code]true[/code], the dialog is hidden when the OK button is pressed. You can set it to [code]false[/code] if you want to do e.g. input validation when receiving the [signal confirmed] signal, and handle hiding the dialog in your own logic. diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index 42c2316f486..e4cf6bd3dfb 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -1257,6 +1257,13 @@ Default [InputEventAction] to discard a modal or pending input. [b]Note:[/b] Default [code]ui_*[/code] actions cannot be removed as they are necessary for the internal logic of several [Control]s. The events assigned to the action can however be modified. + + Default [InputEventAction] to close a dialog window. + [b]Note:[/b] Default [code]ui_*[/code] actions cannot be removed as they are necessary for the internal logic of several [Control]s. The events assigned to the action can however be modified. + + + macOS specific override for the shortcut to close a dialog window. + Default [InputEventAction] to delete a color preset in a [ColorPicker]. [b]Note:[/b] Default [code]ui_*[/code] actions cannot be removed as they are necessary for the internal logic of several [Control]s. The events assigned to the action can however be modified. diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index 569329b3a8f..c0f036b1ec7 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -37,7 +37,7 @@ // AcceptDialog void AcceptDialog::_input_from_window(const Ref &p_event) { - if (close_on_escape && p_event->is_action_pressed(SNAME("ui_cancel"), false, true)) { + if (close_on_escape && p_event->is_action_pressed(SNAME("ui_close_dialog"), false, true)) { _cancel_pressed(); } Window::_input_from_window(p_event);