persist selected theme to AppState

This commit is contained in:
Matt Parker
2026-01-31 13:38:29 +10:00
parent 6f02c1e1e7
commit 40bc8def26
3 changed files with 19 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ public class IdeSettings
public string? DebuggerExecutablePath { get; set; } public string? DebuggerExecutablePath { get; set; }
public bool DebuggerUseSharpDbg { get; set; } = true; public bool DebuggerUseSharpDbg { get; set; } = true;
public float UiScale { get; set; } = 1.0f; public float UiScale { get; set; } = 1.0f;
public string Theme { get; set; } = "Dark";
} }
public record RecentSln public record RecentSln

View File

@@ -28,6 +28,8 @@ public partial class SettingsWindow : Window
_uiScaleSpinBox.Value = Singletons.AppState.IdeSettings.UiScale; _uiScaleSpinBox.Value = Singletons.AppState.IdeSettings.UiScale;
_debuggerFilePathLineEdit.Text = Singletons.AppState.IdeSettings.DebuggerExecutablePath; _debuggerFilePathLineEdit.Text = Singletons.AppState.IdeSettings.DebuggerExecutablePath;
_debuggerUseSharpDbgCheckButton.ButtonPressed = Singletons.AppState.IdeSettings.DebuggerUseSharpDbg; _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) private void OnUiScaleSpinBoxValueChanged(double value)
@@ -52,6 +54,7 @@ public partial class SettingsWindow : Window
private void OnThemeItemSelected(long index) private void OnThemeItemSelected(long index)
{ {
var selectedTheme = _themeOptionButton.GetItemText((int)index); var selectedTheme = _themeOptionButton.GetItemText((int)index);
Singletons.AppState.IdeSettings.Theme = selectedTheme;
this.SetIdeTheme(selectedTheme); this.SetIdeTheme(selectedTheme);
} }
} }

View File

@@ -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) extension(TreeItem treeItem)
{ {
public T? GetTypedMetadata<T>(int column) where T : RefCounted? public T? GetTypedMetadata<T>(int column) where T : RefCounted?