Skip to content

Commit 40bc8de

Browse files
committed
persist selected theme to AppState
1 parent 6f02c1e commit 40bc8de

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

src/SharpIDE.Godot/Features/IdeSettings/AppState.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class IdeSettings
1313
public string? DebuggerExecutablePath { get; set; }
1414
public bool DebuggerUseSharpDbg { get; set; } = true;
1515
public float UiScale { get; set; } = 1.0f;
16+
public string Theme { get; set; } = "Dark";
1617
}
1718

1819
public record RecentSln

src/SharpIDE.Godot/Features/Settings/SettingsWindow.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ private void OnAboutToPopup()
2828
_uiScaleSpinBox.Value = Singletons.AppState.IdeSettings.UiScale;
2929
_debuggerFilePathLineEdit.Text = Singletons.AppState.IdeSettings.DebuggerExecutablePath;
3030
_debuggerUseSharpDbgCheckButton.ButtonPressed = Singletons.AppState.IdeSettings.DebuggerUseSharpDbg;
31+
var themeOptionIndex = _themeOptionButton.GetOptionIndexOrNullForString(Singletons.AppState.IdeSettings.Theme);
32+
if (themeOptionIndex is not null) _themeOptionButton.Selected = themeOptionIndex.Value;
3133
}
3234

3335
private void OnUiScaleSpinBoxValueChanged(double value)
@@ -52,6 +54,7 @@ private void OnDebuggerUseSharpDbgToggled(bool pressed)
5254
private void OnThemeItemSelected(long index)
5355
{
5456
var selectedTheme = _themeOptionButton.GetItemText((int)index);
57+
Singletons.AppState.IdeSettings.Theme = selectedTheme;
5558
this.SetIdeTheme(selectedTheme);
5659
}
5760
}

src/SharpIDE.Godot/NodeExtensions.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,21 @@ public void DrawDashedLine(Rid canvasItemRid, Vector2 from, Vector2 to, Color co
8787
}
8888
}
8989

90+
extension(OptionButton optionButton)
91+
{
92+
public int? GetOptionIndexOrNullForString(string optionString)
93+
{
94+
for (var i = 0; i < optionButton.GetItemCount(); i++)
95+
{
96+
if (optionButton.GetItemText(i) == optionString)
97+
{
98+
return i;
99+
}
100+
}
101+
return null;
102+
}
103+
}
104+
90105
extension(TreeItem treeItem)
91106
{
92107
public T? GetTypedMetadata<T>(int column) where T : RefCounted?

0 commit comments

Comments
 (0)