Skip to content

Commit

Permalink
Refactor the theme selection code and add a new theme
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Oct 6, 2024
1 parent 4046c39 commit f725970
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
23 changes: 7 additions & 16 deletions JL.Windows/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,27 +183,18 @@ internal static class ConfigManager

private static readonly ComboBoxItem[] s_japaneseFonts = WindowsUtils.FindJapaneseFonts();
private static readonly ComboBoxItem[] s_popupJapaneseFonts = WindowsUtils.CloneJapaneseFontComboBoxItems(s_japaneseFonts);
private static SkinType s_theme = SkinType.Dark;
private static SkinType Theme { get; set; } = SkinType.Dark;

public static void ApplyPreferences()
{
using SqliteConnection connection = ConfigDBManager.CreateReadWriteDBConnection();
CoreConfigManager.ApplyPreferences(connection);

SkinType skinType = ConfigDBManager.GetValueFromConfig(connection, Theme, nameof(Theme), Enum.TryParse);
if (skinType != Theme)
{
string? themeStr = ConfigDBManager.GetSettingValue(connection, "Theme");
if (themeStr is null)
{
themeStr = nameof(SkinType.Dark);
ConfigDBManager.InsertSetting(connection, "Theme", themeStr);
}

SkinType skinType = themeStr is nameof(SkinType.Dark) ? SkinType.Dark : SkinType.Default;
if (s_theme != skinType)
{
s_theme = skinType;
WindowsUtils.ChangeTheme(s_theme);
}
Theme = skinType;
WindowsUtils.ChangeTheme(Theme);
}

if (CoreConfigManager.CaptureTextFromClipboard)
Expand Down Expand Up @@ -950,7 +941,7 @@ public static void LoadPreferenceWindow(PreferencesWindow preferenceWindow)
using SqliteConnection connection = ConfigDBManager.CreateReadOnlyDBConnection();
preferenceWindow.ProfileComboBox.ItemsSource = ProfileDBUtils.GetProfileNames(connection);
preferenceWindow.ProfileComboBox.SelectedItem = ProfileUtils.CurrentProfileName;
preferenceWindow.ThemeComboBox.SelectedValue = ConfigDBManager.GetSettingValue(connection, "Theme");
preferenceWindow.ThemeComboBox.SelectedValue = ConfigDBManager.GetSettingValue(connection, nameof(Theme));
preferenceWindow.MainWindowTextVerticalAlignmentComboBox.SelectedValue = ConfigDBManager.GetSettingValue(connection, nameof(MainWindowTextVerticalAlignment));
preferenceWindow.MinimumLogLevelComboBox.SelectedValue = ConfigDBManager.GetSettingValue(connection, "MinimumLogLevel");
preferenceWindow.PopupPositionRelativeToCursorComboBox.SelectedValue = ConfigDBManager.GetSettingValue(connection, "PopupPositionRelativeToCursor");
Expand Down Expand Up @@ -1154,7 +1145,7 @@ public static async Task SavePreferences(PreferencesWindow preferenceWindow)
ConfigDBManager.UpdateSetting(connection, "MainWindowOpacity",
preferenceWindow.MainWindowOpacityNumericUpDown.Value.ToString(CultureInfo.InvariantCulture));

ConfigDBManager.UpdateSetting(connection, "Theme", preferenceWindow.ThemeComboBox.SelectedValue.ToString()!);
ConfigDBManager.UpdateSetting(connection, nameof(Theme), preferenceWindow.ThemeComboBox.SelectedValue.ToString()!);
ConfigDBManager.UpdateSetting(connection, nameof(MainWindowTextVerticalAlignment), preferenceWindow.MainWindowTextVerticalAlignmentComboBox.SelectedValue.ToString()!);

ConfigDBManager.UpdateSetting(connection, "MinimumLogLevel", preferenceWindow.MinimumLogLevelComboBox.SelectedValue.ToString()!);
Expand Down
3 changes: 2 additions & 1 deletion JL.Windows/GUI/PreferencesWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
<ComboBox x:Name="ThemeComboBox" HorizontalAlignment="Right"
SelectedValuePath="Tag" Width="250">
<ComboBoxItem Content="Dark" Tag="Dark" />
<ComboBoxItem Content="Light" Tag="Light" />
<ComboBoxItem Content="Light" Tag="Default" />
<ComboBoxItem Content="Violet" Tag="Violet" />
</ComboBox>
</DockPanel>

Expand Down

0 comments on commit f725970

Please sign in to comment.