From 2f8b96e8a28c4a66c809d6080717c969bb71c753 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pa=CC=84vels=20Nadtoc=CC=8Cajevs?=
<7645683+bruvzg@users.noreply.github.com>
Date: Thu, 3 Apr 2025 11:09:37 +0300
Subject: [PATCH] Make `swap_cancel_ok` setting 3-state instead of boolean.
---
doc/classes/EditorSettings.xml | 2 +-
doc/classes/ProjectSettings.xml | 7 +++++--
editor/project_manager.cpp | 6 +++++-
editor/project_manager/quick_settings_dialog.cpp | 6 +++++-
scene/register_scene_types.cpp | 8 ++++----
5 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/doc/classes/EditorSettings.xml b/doc/classes/EditorSettings.xml
index 2879b6e09b9..cb910eb8467 100644
--- a/doc/classes/EditorSettings.xml
+++ b/doc/classes/EditorSettings.xml
@@ -805,7 +805,7 @@
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]Auto[/b] follows the platform convention: OK first on Windows, KDE, and LXQt, Cancel first on macOS and other Linux desktop environments.
- [b]Cancel First[/b] forces the ordering Cancel/OK.
- [b]OK First[/b] forces the ordering OK/Cancel.
diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml
index 6f40c59c193..a156c0ad275 100644
--- a/doc/classes/ProjectSettings.xml
+++ b/doc/classes/ProjectSettings.xml
@@ -1125,8 +1125,11 @@
If [code]true[/code], snaps [Control] node vertices to the nearest pixel to ensure they remain crisp even when the camera moves or zooms.
-
- If [code]true[/code], swaps [b]Cancel[/b] and [b]OK[/b] buttons in dialogs on Windows to follow interface conventions. [method DisplayServer.get_swap_cancel_ok] can be used to query whether buttons are swapped at run-time.
+
+ How to position the Cancel and OK buttons in the project's [AcceptDialog]s. Different platforms have different standard behaviors for this, which can be overridden using this setting.
+ - [b]Auto[/b] ([code]0[/code]) follows the platform convention: OK first on Windows, KDE, and LXQt, Cancel first on macOS and other Linux desktop environments. [method DisplayServer.get_swap_cancel_ok] can be used to query whether buttons are swapped at run-time.
+ - [b]Cancel First[/b] ([code]1[/code]) forces the ordering Cancel/OK.
+ - [b]OK First[/b] ([code]2[/code]) forces the ordering OK/Cancel.
[b]Note:[/b] This doesn't affect native dialogs such as the ones spawned by [method DisplayServer.dialog_show].
diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp
index 848ce62de22..16c3721060f 100644
--- a/editor/project_manager.cpp
+++ b/editor/project_manager.cpp
@@ -1630,7 +1630,11 @@ ProjectManager::ProjectManager() {
ask_update_settings = memnew(ConfirmationDialog);
ask_update_settings->set_autowrap(true);
ask_update_settings->get_ok_button()->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_open_selected_projects_with_migration));
- full_convert_button = ask_update_settings->add_button(TTR("Convert Full Project"), !GLOBAL_GET("gui/common/swap_cancel_ok"));
+ int ed_swap_cancel_ok = EDITOR_GET("interface/editor/accept_dialog_cancel_ok_buttons");
+ if (ed_swap_cancel_ok == 0) {
+ ed_swap_cancel_ok = DisplayServer::get_singleton()->get_swap_cancel_ok() ? 2 : 1;
+ }
+ full_convert_button = ask_update_settings->add_button(TTR("Convert Full Project"), ed_swap_cancel_ok != 2);
full_convert_button->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_full_convert_button_pressed));
add_child(ask_update_settings);
diff --git a/editor/project_manager/quick_settings_dialog.cpp b/editor/project_manager/quick_settings_dialog.cpp
index a805f6c75e6..923c72287a1 100644
--- a/editor/project_manager/quick_settings_dialog.cpp
+++ b/editor/project_manager/quick_settings_dialog.cpp
@@ -192,7 +192,11 @@ void QuickSettingsDialog::_set_setting_value(const String &p_setting, const Vari
restart_required_label->show();
if (!restart_required_button) {
- restart_required_button = add_button(TTR("Restart Now"), !GLOBAL_GET("gui/common/swap_cancel_ok"));
+ int ed_swap_cancel_ok = EDITOR_GET("interface/editor/accept_dialog_cancel_ok_buttons");
+ if (ed_swap_cancel_ok == 0) {
+ ed_swap_cancel_ok = DisplayServer::get_singleton()->get_swap_cancel_ok() ? 2 : 1;
+ }
+ restart_required_button = add_button(TTR("Restart Now"), ed_swap_cancel_ok != 2);
restart_required_button->connect(SceneStringName(pressed), callable_mp(this, &QuickSettingsDialog::_request_restart));
}
}
diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp
index 006f9a45a8a..eaa809b1eb8 100644
--- a/scene/register_scene_types.cpp
+++ b/scene/register_scene_types.cpp
@@ -521,11 +521,11 @@ void register_scene_types() {
OS::get_singleton()->yield(); // may take time to init
- bool swap_cancel_ok = false;
- if (DisplayServer::get_singleton()) {
- swap_cancel_ok = GLOBAL_DEF_NOVAL("gui/common/swap_cancel_ok", bool(DisplayServer::get_singleton()->get_swap_cancel_ok()));
+ int swap_cancel_ok = GLOBAL_DEF(PropertyInfo(Variant::INT, "gui/common/swap_cancel_ok", PROPERTY_HINT_ENUM, "Auto,Cancel First,OK First"), 0);
+ if (DisplayServer::get_singleton() && swap_cancel_ok == 0) {
+ swap_cancel_ok = DisplayServer::get_singleton()->get_swap_cancel_ok() ? 2 : 1;
}
- AcceptDialog::set_swap_cancel_ok(swap_cancel_ok);
+ AcceptDialog::set_swap_cancel_ok(swap_cancel_ok == 2);
#endif
int root_dir = GLOBAL_GET("internationalization/rendering/root_node_layout_direction");