Skip to content

Commit f27126e

Browse files
committed
Merge pull request godotengine#107303 from passivestar/close-dialog-action
Add support for closing dialog windows with Cmd+W on macOS
2 parents a22f388 + fe0bbe9 commit f27126e

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") },
@@ -436,6 +437,15 @@ const HashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins() {
436437
inputs.push_back(InputEventKey::create_reference(Key::ESCAPE));
437438
default_builtin_cache.insert("ui_cancel", inputs);
438439

440+
inputs = List<Ref<InputEvent>>();
441+
inputs.push_back(InputEventKey::create_reference(Key::ESCAPE));
442+
default_builtin_cache.insert("ui_close_dialog", inputs);
443+
444+
inputs = List<Ref<InputEvent>>();
445+
inputs.push_back(InputEventKey::create_reference(Key::W | KeyModifierMask::META));
446+
inputs.push_back(InputEventKey::create_reference(Key::ESCAPE));
447+
default_builtin_cache.insert("ui_close_dialog.macos", inputs);
448+
439449
inputs = List<Ref<InputEvent>>();
440450
inputs.push_back(InputEventKey::create_reference(Key::TAB));
441451
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
@@ -63,7 +63,7 @@
6363
Sets autowrapping for the text in the dialog.
6464
</member>
6565
<member name="dialog_close_on_escape" type="bool" setter="set_close_on_escape" getter="get_close_on_escape" default="true">
66-
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]).
66+
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).
6767
</member>
6868
<member name="dialog_hide_on_ok" type="bool" setter="set_hide_on_ok" getter="get_hide_on_ok" default="true">
6969
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
@@ -1270,6 +1270,13 @@
12701270
Default [InputEventAction] to discard a modal or pending input.
12711271
[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.
12721272
</member>
1273+
<member name="input/ui_close_dialog" type="Dictionary" setter="" getter="">
1274+
Default [InputEventAction] to close a dialog window.
1275+
[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.
1276+
</member>
1277+
<member name="input/ui_close_dialog.macos" type="Dictionary" setter="" getter="">
1278+
macOS specific override for the shortcut to close a dialog window.
1279+
</member>
12731280
<member name="input/ui_colorpicker_delete_preset" type="Dictionary" setter="" getter="">
12741281
Default [InputEventAction] to delete a color preset in a [ColorPicker].
12751282
[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)