mirror of
https://github.com/Stone-Red-Code/DesktopMagic.git
synced 2026-09-04 00:46:12 +02:00
Fix some issues with the new theme support
This commit is contained in:
@@ -77,13 +77,13 @@
|
|||||||
</Grid.ColumnDefinitions>
|
</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" />
|
<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}">
|
<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">
|
<StackPanel Orientation="Horizontal">
|
||||||
<materialDesign:PackIcon Kind="Add" Margin="0 0 10 0" />
|
<materialDesign:PackIcon Kind="Add" Margin="0 0 10 0" />
|
||||||
<TextBlock Text="{DynamicResource newTheme}" />
|
<TextBlock Text="{DynamicResource newTheme}" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Button>
|
</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">
|
<StackPanel Orientation="Horizontal">
|
||||||
<materialDesign:PackIcon Kind="DeleteOutline" Margin="0 0 10 0" />
|
<materialDesign:PackIcon Kind="DeleteOutline" Margin="0 0 10 0" />
|
||||||
<TextBlock Text="{DynamicResource deleteTheme}" />
|
<TextBlock Text="{DynamicResource deleteTheme}" />
|
||||||
|
|||||||
@@ -299,6 +299,39 @@ namespace DesktopMagic
|
|||||||
|
|
||||||
#region Options
|
#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)
|
private void ChangeThemeButton_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
Theme theme = themesListBox.SelectedItem as Theme ?? Settings.CurrentLayout.Theme;
|
Theme theme = themesListBox.SelectedItem as Theme ?? Settings.CurrentLayout.Theme;
|
||||||
@@ -428,6 +461,12 @@ namespace DesktopMagic
|
|||||||
|
|
||||||
private void RemoveLayoutButton_Click(object sender, RoutedEventArgs e)
|
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);
|
Settings.Layouts.Remove(Settings.CurrentLayout);
|
||||||
SaveSettings();
|
SaveSettings();
|
||||||
}
|
}
|
||||||
@@ -447,30 +486,27 @@ namespace DesktopMagic
|
|||||||
{
|
{
|
||||||
if (!File.Exists(Path.Combine(App.ApplicationDataPath, "settings.json")))
|
if (!File.Exists(Path.Combine(App.ApplicationDataPath, "settings.json")))
|
||||||
{
|
{
|
||||||
Settings = new DesktopMagicSettings()
|
Settings = new DesktopMagicSettings();
|
||||||
{
|
|
||||||
Layouts = [
|
Settings.Layouts.Add(new Layout((string)FindResource("default")));
|
||||||
new Layout((string)FindResource("default"))
|
Settings.Themes.Add(new Theme((string)FindResource("default")));
|
||||||
],
|
|
||||||
Themes = [
|
|
||||||
new Theme((string)FindResource("default"))
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string json = File.ReadAllText(Path.Combine(App.ApplicationDataPath, "settings.json"));
|
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 = [
|
Settings.Layouts.Add(new Layout((string)FindResource("default")));
|
||||||
new Layout((string)FindResource("default"))
|
}
|
||||||
],
|
|
||||||
Themes = [
|
if (Settings.Themes.Count == 0)
|
||||||
new Theme((string)FindResource("default"))
|
{
|
||||||
]
|
Settings.Themes.Add(new Theme((string)FindResource("default")));
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadLayout(bool minimize = true)
|
private void LoadLayout(bool minimize = true)
|
||||||
|
|||||||
@@ -56,7 +56,17 @@ public partial class PluginWindow : Window
|
|||||||
|
|
||||||
Owner = w;
|
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;
|
PluginMetadata = pluginMetadata;
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
|
|||||||
@@ -41,6 +41,8 @@
|
|||||||
<system:String x:Key="cancel">Abbrechen</system:String>
|
<system:String x:Key="cancel">Abbrechen</system:String>
|
||||||
<system:String x:Key="enterLayoutName">Layoutnamen eingeben:</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="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="install">Installieren</system:String>
|
||||||
<system:String x:Key="uninstall">Deinstallieren</system:String>
|
<system:String x:Key="uninstall">Deinstallieren</system:String>
|
||||||
<system:String x:Key="remove">Entfernen</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="cancel">Cancel</system:String>
|
||||||
<system:String x:Key="enterLayoutName">Enter layout name</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="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="install">Install</system:String>
|
||||||
<system:String x:Key="uninstall">Uninstall</system:String>
|
<system:String x:Key="uninstall">Uninstall</system:String>
|
||||||
<system:String x:Key="remove">Remove</system:String>
|
<system:String x:Key="remove">Remove</system:String>
|
||||||
|
|||||||
@@ -19,9 +19,10 @@ internal class DesktopMagicSettings : INotifyPropertyChanged
|
|||||||
public ObservableCollection<Theme> Themes
|
public ObservableCollection<Theme> Themes
|
||||||
{
|
{
|
||||||
get => themes;
|
get => themes;
|
||||||
set
|
init
|
||||||
{
|
{
|
||||||
themes = value;
|
themes = value;
|
||||||
|
themes.CollectionChanged += (s, e) => CurrentLayout.UpdateTheme();
|
||||||
OnPropertyChanged();
|
OnPropertyChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,6 +33,8 @@ internal class DesktopMagicSettings : INotifyPropertyChanged
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
layouts = value;
|
layouts = value;
|
||||||
|
layouts.CollectionChanged += (s, e) => OnPropertyChanged(nameof(CurrentLayout));
|
||||||
|
layouts.CollectionChanged += (s, e) => OnPropertyChanged(nameof(CurrentLayoutName));
|
||||||
OnPropertyChanged();
|
OnPropertyChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,6 +55,14 @@ internal class DesktopMagicSettings : INotifyPropertyChanged
|
|||||||
|
|
||||||
public string? ModIoAccessToken { get; set; }
|
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)
|
protected void OnPropertyChanged([CallerMemberName] string? name = null)
|
||||||
{
|
{
|
||||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
|
||||||
|
|||||||
@@ -29,14 +29,13 @@ internal class Layout(string name) : INotifyPropertyChanged
|
|||||||
|
|
||||||
public string? CurrentThemeName
|
public string? CurrentThemeName
|
||||||
{
|
{
|
||||||
get => currentThemeName;
|
get => Theme.Name;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (currentThemeName != value)
|
if (currentThemeName != value)
|
||||||
{
|
{
|
||||||
currentThemeName = value;
|
currentThemeName = value;
|
||||||
OnPropertyChanged();
|
UpdateTheme();
|
||||||
OnPropertyChanged(nameof(Theme));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,6 +66,17 @@ internal class Layout(string name) : INotifyPropertyChanged
|
|||||||
OnPropertyChanged(nameof(Plugins));
|
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)
|
protected void OnPropertyChanged([CallerMemberName] string? propertyName = null)
|
||||||
{
|
{
|
||||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
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)
|
protected void OnPropertyChanged([CallerMemberName] string? propertyName = null)
|
||||||
{
|
{
|
||||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||||
|
|||||||
Reference in New Issue
Block a user