From f3801032b86f5cf76f63381ad43b707592144251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Mon, 21 Mar 2022 10:55:18 +0100 Subject: [PATCH] Add editor setting for AcceptDialog OK/Cancel buttons positioning The position (left/right) of the Cancel and OK buttons in AcceptDialog are DisplayServer specific, as Windows uses OK/Cancel and macOS uses Cancel/OK. Linux/X11 currently uses the macOS convention which is also the GTK+/GNOME one, though it's not consistent with Qt/KDE applications which follow the Windows convention. Since that can't satisfy everyone, it's best if it's configurable also for the editor (it's already configurable for the project). Fixes #59379. (cherry picked from commit 9bb05de89fcc286a0d78bea12dc779a56c274fb0) --- doc/classes/EditorSettings.xml | 6 ++++++ editor/editor_node.cpp | 9 ++++++++- editor/editor_settings.cpp | 2 ++ editor/project_manager.cpp | 7 +++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/doc/classes/EditorSettings.xml b/doc/classes/EditorSettings.xml index 73cbd58fd..f095020ef 100644 --- a/doc/classes/EditorSettings.xml +++ b/doc/classes/EditorSettings.xml @@ -391,6 +391,12 @@ If [code]true[/code], when saving a file, the editor will rename the old file to a different name, save a new file, then only remove the old file once the new file has been saved. This makes loss of data less likely to happen if the editor or operating system exits unexpectedly while saving (e.g. due to a crash or power outage). [b]Note:[/b] On Windows, this feature can interact negatively with certain antivirus programs. In this case, you may have to set this to [code]false[/code] to prevent file locking issues. + + How to position the Cancel and OK buttons in the editor's [AcceptDialog]s. Different platforms have different standard behaviors for this, which can be overridden using this setting. This is useful if you use Godot both on Windows and macOS/Linux and your Godot muscle memory is stronger than your OS specific one. + - [b]Auto[/b] follows the platform convention: Cancel first on macOS and Linux, OK first on Windows. + - [b]Cancel First[/b] forces the ordering Cancel/OK. + - [b]OK First[/b] forces the ordering OK/Cancel. + If [code]true[/code], automatically opens screenshots with the default program associated to [code].png[/code] files after a screenshot is taken using the [b]Editor > Take Screenshot[/b] action. diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 0a9abf27a..0d1b0046b 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -5878,10 +5878,17 @@ EditorNode::EditorNode() { // Define a minimum window size to prevent UI elements from overlapping or being cut off OS::get_singleton()->set_min_window_size(Size2(1024, 600) * EDSCALE); - ResourceLoader::set_abort_on_missing_resources(false); FileDialog::set_default_show_hidden_files(EditorSettings::get_singleton()->get("filesystem/file_dialog/show_hidden_files")); EditorFileDialog::set_default_show_hidden_files(EditorSettings::get_singleton()->get("filesystem/file_dialog/show_hidden_files")); EditorFileDialog::set_default_display_mode((EditorFileDialog::DisplayMode)EditorSettings::get_singleton()->get("filesystem/file_dialog/display_mode").operator int()); + + int swap_cancel_ok = EDITOR_GET("interface/editor/accept_dialog_cancel_ok_buttons"); + if (swap_cancel_ok != 0) { // 0 is auto, set in register_scene based on OS. + // Swap on means OK first. + AcceptDialog::set_swap_ok_cancel(swap_cancel_ok == 2); + } + + ResourceLoader::set_abort_on_missing_resources(false); ResourceLoader::set_error_notify_func(this, _load_error_notify); ResourceLoader::set_dependency_error_notify_func(this, _dependency_error_report); diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 45f9baf01..86d3934ac 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -352,6 +352,8 @@ void EditorSettings::_load_defaults(Ref p_extra_config) { _initial_set("interface/editor/automatically_open_screenshots", true); _initial_set("interface/editor/save_each_scene_on_quit", true); // Regression _initial_set("interface/editor/quit_confirmation", true); + _initial_set("interface/editor/accept_dialog_cancel_ok_buttons", 0); + hints["interface/editor/accept_dialog_cancel_ok_buttons"] = PropertyInfo(Variant::INT, "interface/editor/accept_dialog_cancel_ok_buttons", PROPERTY_HINT_ENUM, vformat("Auto (%s),Cancel First,OK First", OS::get_singleton()->get_swap_ok_cancel() ? "OK First" : "Cancel First"), PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); // Inspector _initial_set("interface/inspector/max_array_dictionary_items_per_page", 20); diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index 017e41d66..0522e74ea 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -2440,6 +2440,13 @@ ProjectManager::ProjectManager() { FileDialog::set_default_show_hidden_files(EditorSettings::get_singleton()->get("filesystem/file_dialog/show_hidden_files")); set_anchors_and_margins_preset(Control::PRESET_WIDE); + + int swap_cancel_ok = EDITOR_GET("interface/editor/accept_dialog_cancel_ok_buttons"); + if (swap_cancel_ok != 0) { // 0 is auto, set in register_scene based on OS. + // Swap on means OK first. + AcceptDialog::set_swap_ok_cancel(swap_cancel_ok == 2); + } + set_theme(create_custom_theme()); gui_base = memnew(Control);