Fix some issues with the new theme support

This commit is contained in:
Stone_Red
2025-12-08 20:11:12 +01:00
parent 10fe4c773b
commit 0bc7033196
8 changed files with 103 additions and 24 deletions
+2 -2
View File
@@ -77,13 +77,13 @@
</Grid.ColumnDefinitions>
<ListBox x:Name="themesListBox" Grid.Row="0" Grid.ColumnSpan="1" Margin="{StaticResource DefaultMargin}" ItemsSource="{Binding Settings.Themes}" DisplayMemberPath="Name" SelectedValue="{Binding Settings.CurrentLayout.CurrentThemeName}" SelectedValuePath="Name" />
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" Margin="{StaticResource DefaultMargin}">
<Button x:Name="addThemeButton" Margin="0,0,0,5" HorizontalAlignment="Stretch" FontWeight="Regular">
<Button x:Name="addThemeButton" Margin="0,0,0,5" HorizontalAlignment="Stretch" Click="AddThemeButton_Click" FontWeight="Regular">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="Add" Margin="0 0 10 0" />
<TextBlock Text="{DynamicResource newTheme}" />
</StackPanel>
</Button>
<Button x:Name="deleteThemeButton" Margin="0,0,0,5" HorizontalAlignment="Stretch" FontWeight="Regular">
<Button x:Name="deleteThemeButton" Margin="0,0,0,5" HorizontalAlignment="Stretch" Click="DeleteThemeButton_Click" FontWeight="Regular">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="DeleteOutline" Margin="0 0 10 0" />
<TextBlock Text="{DynamicResource deleteTheme}" />
+53 -17
View File
@@ -299,6 +299,39 @@ namespace DesktopMagic
#region Options
private void AddThemeButton_Click(object sender, RoutedEventArgs e)
{
InputDialog inputDialog = new((string)FindResource("enterThemeName"))
{
Owner = this
};
if (inputDialog.ShowDialog() == true)
{
if (Settings.Themes.Any(l => l.Name.Trim() == inputDialog.ResponseText.Trim()))
{
_ = MessageBox.Show((string)FindResource("themeAlreadyExists"), App.AppName, MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
Settings.Themes.Add(new Theme(inputDialog.ResponseText.Trim()));
Settings.CurrentLayout.CurrentThemeName = inputDialog.ResponseText.Trim();
SaveSettings();
}
}
private void DeleteThemeButton_Click(object sender, RoutedEventArgs e)
{
if (Settings.Themes.Count <= 1)
{
_ = MessageBox.Show((string)FindResource("cannotDeleteLastTheme"), App.AppName, MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
Settings.Themes.Remove((Theme)themesListBox.SelectedItem);
SaveSettings();
}
private void ChangeThemeButton_Click(object sender, RoutedEventArgs e)
{
Theme theme = themesListBox.SelectedItem as Theme ?? Settings.CurrentLayout.Theme;
@@ -428,6 +461,12 @@ namespace DesktopMagic
private void RemoveLayoutButton_Click(object sender, RoutedEventArgs e)
{
if (Settings.Layouts.Count <= 1)
{
_ = MessageBox.Show((string)FindResource("cannotDeleteLastLayout"), App.AppName, MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
Settings.Layouts.Remove(Settings.CurrentLayout);
SaveSettings();
}
@@ -447,30 +486,27 @@ namespace DesktopMagic
{
if (!File.Exists(Path.Combine(App.ApplicationDataPath, "settings.json")))
{
Settings = new DesktopMagicSettings()
{
Layouts = [
new Layout((string)FindResource("default"))
],
Themes = [
new Theme((string)FindResource("default"))
]
};
Settings = new DesktopMagicSettings();
Settings.Layouts.Add(new Layout((string)FindResource("default")));
Settings.Themes.Add(new Theme((string)FindResource("default")));
return;
}
string json = File.ReadAllText(Path.Combine(App.ApplicationDataPath, "settings.json"));
Settings = JsonSerializer.Deserialize<DesktopMagicSettings>(json, jsonSettingsOptions) ?? new DesktopMagicSettings()
Settings = JsonSerializer.Deserialize<DesktopMagicSettings>(json, jsonSettingsOptions) ?? new DesktopMagicSettings();
if(Settings.Layouts.Count == 0)
{
Layouts = [
new Layout((string)FindResource("default"))
],
Themes = [
new Theme((string)FindResource("default"))
]
};
Settings.Layouts.Add(new Layout((string)FindResource("default")));
}
if (Settings.Themes.Count == 0)
{
Settings.Themes.Add(new Theme((string)FindResource("default")));
}
}
private void LoadLayout(bool minimize = true)
+11 -1
View File
@@ -56,7 +56,17 @@ public partial class PluginWindow : Window
Owner = w;
settings.Theme.PropertyChanged += (e, s) => ThemeChanged();
settings.PropertyChanged += (e, s) =>
{
if (s.PropertyName == nameof(PluginSettings.CurrentThemeName))
{
settings.Theme.PropertyChanged += (se, ev) =>
{
ThemeChanged();
};
ThemeChanged();
}
};
PluginMetadata = pluginMetadata;
this.settings = settings;
@@ -41,6 +41,8 @@
<system:String x:Key="cancel">Abbrechen</system:String>
<system:String x:Key="enterLayoutName">Layoutnamen eingeben:</system:String>
<system:String x:Key="layoutAlreadyExists">Layout existiert bereits!</system:String>
<system:String x:Key="enterThemeName">Themenamen eingeben:</system:String>
<system:String x:Key="themeAlreadyExists">Theme existiert bereits!</system:String>
<system:String x:Key="install">Installieren</system:String>
<system:String x:Key="uninstall">Deinstallieren</system:String>
<system:String x:Key="remove">Entfernen</system:String>
@@ -41,6 +41,10 @@
<system:String x:Key="cancel">Cancel</system:String>
<system:String x:Key="enterLayoutName">Enter layout name</system:String>
<system:String x:Key="layoutAlreadyExists">Layout already exists!</system:String>
<system:String x:Key="cannotDeleteLastLayout">Can't delete last layout!</system:String>
<system:String x:Key="enterThemeName">Enter theme name</system:String>
<system:String x:Key="themeAlreadyExists">Theme already exists!</system:String>
<system:String x:Key="cannotDeleteLastTheme">Can't delete last theme!</system:String>
<system:String x:Key="install">Install</system:String>
<system:String x:Key="uninstall">Uninstall</system:String>
<system:String x:Key="remove">Remove</system:String>
@@ -19,9 +19,10 @@ internal class DesktopMagicSettings : INotifyPropertyChanged
public ObservableCollection<Theme> Themes
{
get => themes;
set
init
{
themes = value;
themes.CollectionChanged += (s, e) => CurrentLayout.UpdateTheme();
OnPropertyChanged();
}
}
@@ -32,6 +33,8 @@ internal class DesktopMagicSettings : INotifyPropertyChanged
set
{
layouts = value;
layouts.CollectionChanged += (s, e) => OnPropertyChanged(nameof(CurrentLayout));
layouts.CollectionChanged += (s, e) => OnPropertyChanged(nameof(CurrentLayoutName));
OnPropertyChanged();
}
}
@@ -52,6 +55,14 @@ internal class DesktopMagicSettings : INotifyPropertyChanged
public string? ModIoAccessToken { get; set; }
public DesktopMagicSettings()
{
themes.CollectionChanged += (s, e) => CurrentLayout.UpdateTheme();
layouts.CollectionChanged += (s, e) => OnPropertyChanged(nameof(CurrentLayout));
layouts.CollectionChanged += (s, e) => OnPropertyChanged(nameof(CurrentLayoutName));
}
protected void OnPropertyChanged([CallerMemberName] string? name = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
+13 -3
View File
@@ -29,14 +29,13 @@ internal class Layout(string name) : INotifyPropertyChanged
public string? CurrentThemeName
{
get => currentThemeName;
get => Theme.Name;
set
{
if (currentThemeName != value)
{
currentThemeName = value;
OnPropertyChanged();
OnPropertyChanged(nameof(Theme));
UpdateTheme();
}
}
}
@@ -67,6 +66,17 @@ internal class Layout(string name) : INotifyPropertyChanged
OnPropertyChanged(nameof(Plugins));
}
public void UpdateTheme()
{
OnPropertyChanged(nameof(Theme));
OnPropertyChanged(nameof(CurrentThemeName));
foreach (PluginSettings pluginSettings in plugins.Values)
{
pluginSettings.UpdateTheme();
}
}
protected void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
@@ -100,6 +100,12 @@ public class PluginSettings : INotifyPropertyChanged
}
}
public void UpdateTheme()
{
OnPropertyChanged(nameof(Theme));
OnPropertyChanged(nameof(CurrentThemeName));
}
protected void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));