Skip to content

Commit 979f8fa

Browse files
committed
Add support for closing dialog windows with Cmd+W on macOS
1 parent 9e02194 commit 979f8fa

4 files changed

Lines changed: 19 additions & 2 deletions

File tree

core/input/input_map.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ static const _BuiltinActionDisplayName _builtin_action_display_names[] = {
334334
{ "ui_accept", TTRC("Accept") },
335335
{ "ui_select", TTRC("Select") },
336336
{ "ui_cancel", TTRC("Cancel") },
337+
{ "ui_close_dialog", TTRC("Close Dialog") },
337338
{ "ui_focus_next", TTRC("Focus Next") },
338339
{ "ui_focus_prev", TTRC("Focus Prev") },
339340
{ "ui_left", TTRC("Left") },
@@ -447,6 +448,15 @@ const HashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins() {
447448
inputs.push_back(InputEventKey::create_reference(Key::ESCAPE));
448449
default_builtin_cache.insert("ui_cancel", inputs);
449450

451+
inputs = List<Ref<InputEvent>>();
452+
inputs.push_back(InputEventKey::create_reference(Key::ESCAPE));
453+
default_builtin_cache.insert("ui_close_dialog", inputs);
454+
455+
inputs = List<Ref<InputEvent>>();
456+
inputs.push_back(InputEventKey::create_reference(Key::W | KeyModifierMask::META));
457+
inputs.push_back(InputEventKey::create_reference(Key::ESCAPE));
458+
default_builtin_cache.insert("ui_close_dialog.macos", inputs);
459+
450460
inputs = List<Ref<InputEvent>>();
451461
inputs.push_back(InputEventKey::create_reference(Key::TAB));
452462
default_builtin_cache.insert("ui_focus_next", inputs);

doc/classes/AcceptDialog.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
Sets autowrapping for the text in the dialog.
6363
</member>
6464
<member name="dialog_close_on_escape" type="bool" setter="set_close_on_escape" getter="get_close_on_escape" default="true">
65-
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]).
65+
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).
6666
</member>
6767
<member name="dialog_hide_on_ok" type="bool" setter="set_hide_on_ok" getter="get_hide_on_ok" default="true">
6868
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.

doc/classes/ProjectSettings.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,13 @@
12571257
Default [InputEventAction] to discard a modal or pending input.
12581258
[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.
12591259
</member>
1260+
<member name="input/ui_close_dialog" type="Dictionary" setter="" getter="">
1261+
Default [InputEventAction] to close a dialog window.
1262+
[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.
1263+
</member>
1264+
<member name="input/ui_close_dialog.macos" type="Dictionary" setter="" getter="">
1265+
macOS specific override for the shortcut to close a dialog window.
1266+
</member>
12601267
<member name="input/ui_colorpicker_delete_preset" type="Dictionary" setter="" getter="">
12611268
Default [InputEventAction] to delete a color preset in a [ColorPicker].
12621269
[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.

scene/gui/dialogs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
// AcceptDialog
3838

3939
void AcceptDialog::_input_from_window(const Ref<InputEvent> &p_event) {
40-
if (close_on_escape && p_event->is_action_pressed(SNAME("ui_cancel"), false, true)) {
40+
if (close_on_escape && p_event->is_action_pressed(SNAME("ui_close_dialog"), false, true)) {
4141
_cancel_pressed();
4242
}
4343
Window::_input_from_window(p_event);

0 commit comments

Comments
 (0)