From 40bc8def262570c0cdd0c48b2feb224b2ff13bac Mon Sep 17 00:00:00 2001 From: Matt Parker <61717342+MattParkerDev@users.noreply.github.com> Date: Sat, 31 Jan 2026 13:38:29 +1000 Subject: [PATCH] persist selected theme to AppState --- .../Features/IdeSettings/AppState.cs | 1 + .../Features/Settings/SettingsWindow.cs | 3 +++ src/SharpIDE.Godot/NodeExtensions.cs | 15 +++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/src/SharpIDE.Godot/Features/IdeSettings/AppState.cs b/src/SharpIDE.Godot/Features/IdeSettings/AppState.cs index 4c49004..0e97bb9 100644 --- a/src/SharpIDE.Godot/Features/IdeSettings/AppState.cs +++ b/src/SharpIDE.Godot/Features/IdeSettings/AppState.cs @@ -13,6 +13,7 @@ public class IdeSettings public string? DebuggerExecutablePath { get; set; } public bool DebuggerUseSharpDbg { get; set; } = true; public float UiScale { get; set; } = 1.0f; + public string Theme { get; set; } = "Dark"; } public record RecentSln diff --git a/src/SharpIDE.Godot/Features/Settings/SettingsWindow.cs b/src/SharpIDE.Godot/Features/Settings/SettingsWindow.cs index ac17dbc..f2e9af9 100644 --- a/src/SharpIDE.Godot/Features/Settings/SettingsWindow.cs +++ b/src/SharpIDE.Godot/Features/Settings/SettingsWindow.cs @@ -28,6 +28,8 @@ public partial class SettingsWindow : Window _uiScaleSpinBox.Value = Singletons.AppState.IdeSettings.UiScale; _debuggerFilePathLineEdit.Text = Singletons.AppState.IdeSettings.DebuggerExecutablePath; _debuggerUseSharpDbgCheckButton.ButtonPressed = Singletons.AppState.IdeSettings.DebuggerUseSharpDbg; + var themeOptionIndex = _themeOptionButton.GetOptionIndexOrNullForString(Singletons.AppState.IdeSettings.Theme); + if (themeOptionIndex is not null) _themeOptionButton.Selected = themeOptionIndex.Value; } private void OnUiScaleSpinBoxValueChanged(double value) @@ -52,6 +54,7 @@ public partial class SettingsWindow : Window private void OnThemeItemSelected(long index) { var selectedTheme = _themeOptionButton.GetItemText((int)index); + Singletons.AppState.IdeSettings.Theme = selectedTheme; this.SetIdeTheme(selectedTheme); } } \ No newline at end of file diff --git a/src/SharpIDE.Godot/NodeExtensions.cs b/src/SharpIDE.Godot/NodeExtensions.cs index 94d721a..a8df333 100644 --- a/src/SharpIDE.Godot/NodeExtensions.cs +++ b/src/SharpIDE.Godot/NodeExtensions.cs @@ -87,6 +87,21 @@ public static class NodeExtensions } } + extension(OptionButton optionButton) + { + public int? GetOptionIndexOrNullForString(string optionString) + { + for (var i = 0; i < optionButton.GetItemCount(); i++) + { + if (optionButton.GetItemText(i) == optionString) + { + return i; + } + } + return null; + } + } + extension(TreeItem treeItem) { public T? GetTypedMetadata(int column) where T : RefCounted?