diff --git a/src/DesktopMagic/DesktopMagic.csproj b/src/DesktopMagic/DesktopMagic.csproj
index 6f82e04..7177fd5 100644
--- a/src/DesktopMagic/DesktopMagic.csproj
+++ b/src/DesktopMagic/DesktopMagic.csproj
@@ -7,11 +7,11 @@
icon.ico
OnBuildSuccess
Stone_Red
- 1.1.0.0
+ 1.2.0.0
https://github.com/Stone-Red-Code/DesktopMagic
https://github.com/Stone-Red-Code/DesktopMagic
- 1.1.0.0
- 1.1.0.0
+ 1.2.0.0
+ 1.2.0.0
net8.0-windows7.0
win-x64
enable
diff --git a/src/DesktopMagic/Dialogs/ThemeDialog.xaml b/src/DesktopMagic/Dialogs/ThemeDialog.xaml
new file mode 100644
index 0000000..4611d40
--- /dev/null
+++ b/src/DesktopMagic/Dialogs/ThemeDialog.xaml
@@ -0,0 +1,76 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/DesktopMagic/Dialogs/ThemeDialog.xaml.cs b/src/DesktopMagic/Dialogs/ThemeDialog.xaml.cs
new file mode 100644
index 0000000..d922c03
--- /dev/null
+++ b/src/DesktopMagic/Dialogs/ThemeDialog.xaml.cs
@@ -0,0 +1,143 @@
+using DesktopMagic.Helpers;
+using DesktopMagic.Plugins;
+
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Media;
+
+namespace DesktopMagic.Dialogs;
+
+///
+/// Interaction logic for ColorDialog.xaml
+///
+public partial class ThemeDialog : Window
+{
+ private readonly Theme theme;
+
+ public ThemeDialog(string content, Theme theme, string title = App.AppName)
+ {
+ this.theme = theme;
+
+ InitializeComponent();
+
+ Resources.MergedDictionaries.Add(App.LanguageDictionary);
+
+ cornerRadiusTextBox.Text = theme.CornerRadius.ToString();
+ marginTextBox.Text = theme.Margin.ToString();
+ primaryColorRechtangle.Fill = new SolidColorBrush(MultiColorConverter.ConvertToMediaColor(theme.PrimaryColor));
+ secondaryColorRechtangle.Fill = new SolidColorBrush(MultiColorConverter.ConvertToMediaColor(theme.SecondaryColor));
+ backgroundColorRechtangle.Fill = new SolidColorBrush(MultiColorConverter.ConvertToMediaColor(theme.BackgroundColor));
+
+ label.Content = content;
+ Title = title;
+ }
+
+ private void OkButton_Click(object sender, RoutedEventArgs e)
+ {
+ DialogResult = true;
+ }
+
+ private void CancelButton_Click(object sender, RoutedEventArgs e)
+ {
+ DialogResult = false;
+ }
+
+ private void TextBlock_Loaded(object sender, RoutedEventArgs e)
+ {
+ int index = 0;
+ foreach (FontFamily ff in Fonts.SystemFontFamilies)
+ {
+ ComboBoxItem comboBoxItem = new()
+ {
+ FontFamily = ff,
+ Content = ff.ToString()
+ };
+ _ = fontComboBox.Items.Add(comboBoxItem);
+
+ if (ff.ToString() == theme.Font)
+ {
+ fontComboBox.SelectedIndex = index;
+ }
+ index++;
+ }
+ if (fontComboBox.SelectedIndex == -1)
+ {
+ fontComboBox.SelectedIndex = 0;
+ }
+ }
+
+ private void FontComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ theme.Font = fontComboBox.SelectedValue.ToString()!.Replace("System.Windows.Controls.ComboBoxItem: ", "");
+ }
+
+ private void ChangePrimaryColorButton_Click(object sender, RoutedEventArgs e)
+ {
+ ColorDialog colorDialog = new ColorDialog("Set Primary Color", theme.PrimaryColor)
+ {
+ Owner = this
+ };
+
+ if (colorDialog.ShowDialog() == true)
+ {
+ theme.PrimaryColor = colorDialog.ResultColor;
+ primaryColorRechtangle.Fill = colorDialog.ResultBrush;
+ }
+ }
+
+ private void ChangeSecondaryColorButton_Click(object sender, RoutedEventArgs e)
+ {
+ ColorDialog colorDialog = new ColorDialog("Set Secondary Color", theme.SecondaryColor)
+ {
+ Owner = this
+ };
+
+ if (colorDialog.ShowDialog() == true)
+ {
+ theme.SecondaryColor = colorDialog.ResultColor;
+ secondaryColorRechtangle.Fill = colorDialog.ResultBrush;
+ }
+ }
+
+ private void ChangeBackgroundColorButton_Click(object sender, RoutedEventArgs e)
+ {
+ ColorDialog colorDialog = new ColorDialog("Set Background Color", theme.BackgroundColor)
+ {
+ Owner = this
+ };
+
+ if (colorDialog.ShowDialog() == true)
+ {
+ theme.BackgroundColor = colorDialog.ResultColor;
+ backgroundColorRechtangle.Fill = colorDialog.ResultBrush;
+ }
+ }
+
+ private void CornerRadiusTextBox_TextChanged(object? sender, TextChangedEventArgs? e)
+ {
+ bool success = int.TryParse(cornerRadiusTextBox.Text, out int cornerRadius);
+ if (success)
+ {
+ cornerRadiusTextBox.Foreground = Brushes.Black;
+ theme.CornerRadius = cornerRadius;
+ }
+ else
+ {
+ cornerRadiusTextBox.Foreground = Brushes.Red;
+ }
+ }
+
+ private void MarginTextBox_TextChanged(object? sender, TextChangedEventArgs? e)
+ {
+ bool success = int.TryParse(marginTextBox.Text, out int margin);
+ if (success)
+ {
+ marginTextBox.Foreground = Brushes.Black;
+ theme.Margin = margin;
+ }
+ else
+ {
+ marginTextBox.Foreground = Brushes.Red;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/DesktopMagic/Helpers/SettingElementGenerator.cs b/src/DesktopMagic/Helpers/SettingElementGenerator.cs
index c4c7810..3327a7b 100644
--- a/src/DesktopMagic/Helpers/SettingElementGenerator.cs
+++ b/src/DesktopMagic/Helpers/SettingElementGenerator.cs
@@ -206,7 +206,8 @@ internal class SettingElementGenerator(ComboBox optionsComboBox)
{
try
{
- eComboBox.Value = comboBox.SelectedItem.ToString() ?? string.Empty;
+ comboBox.SelectedItem ??= eComboBox.Value;
+ eComboBox.Value = comboBox.SelectedItem?.ToString() ?? eComboBox.Value;
}
catch (Exception ex)
{
diff --git a/src/DesktopMagic/MainWindow.xaml b/src/DesktopMagic/MainWindow.xaml
index a2aef8b..1c1b7be 100644
--- a/src/DesktopMagic/MainWindow.xaml
+++ b/src/DesktopMagic/MainWindow.xaml
@@ -24,7 +24,7 @@
-
+
@@ -38,7 +38,7 @@
-
+
@@ -75,53 +75,26 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
diff --git a/src/DesktopMagic/MainWindow.xaml.cs b/src/DesktopMagic/MainWindow.xaml.cs
index fb861ca..4cc4f42 100644
--- a/src/DesktopMagic/MainWindow.xaml.cs
+++ b/src/DesktopMagic/MainWindow.xaml.cs
@@ -11,10 +11,8 @@ using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.Json;
-using System.Threading;
using System.Windows;
using System.Windows.Controls;
-using System.Windows.Media;
namespace DesktopMagic
{
@@ -301,9 +299,49 @@ namespace DesktopMagic
#region Options
- private void FontComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ private void AddThemeButton_Click(object sender, RoutedEventArgs e)
{
- Settings.CurrentLayout.Theme.Font = fontComboBox.SelectedValue.ToString()!.Replace("System.Windows.Controls.ComboBoxItem: ", "");
+ 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;
+
+ ThemeDialog themeDialog = new(theme.Name, theme, App.AppName)
+ {
+ Owner = this
+ };
+
+ themeDialog.ShowDialog();
}
private void OptionsComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
@@ -381,100 +419,6 @@ namespace DesktopMagic
e.Handled = true;
}
- private void TextBlock_Loaded(object sender, RoutedEventArgs e)
- {
- int index = 0;
- foreach (FontFamily ff in Fonts.SystemFontFamilies)
- {
- ComboBoxItem comboBoxItem = new()
- {
- FontFamily = ff,
- Content = ff.ToString()
- };
- _ = fontComboBox.Items.Add(comboBoxItem);
-
- if (ff.ToString() == Settings.CurrentLayout.Theme.Font)
- {
- fontComboBox.SelectedIndex = index;
- }
- index++;
- }
- if (fontComboBox.SelectedIndex == -1)
- {
- fontComboBox.SelectedIndex = 0;
- }
- }
-
- private void ChangePrimaryColorButton_Click(object sender, RoutedEventArgs e)
- {
- ColorDialog colorDialog = new ColorDialog("Set Primary Color", Settings.CurrentLayout.Theme.PrimaryColor)
- {
- Owner = this
- };
-
- if (colorDialog.ShowDialog() == true)
- {
- Settings.CurrentLayout.Theme.PrimaryColor = colorDialog.ResultColor;
- primaryColorRechtangle.Fill = colorDialog.ResultBrush;
- }
- }
-
- private void ChangeSecondaryColorButton_Click(object sender, RoutedEventArgs e)
- {
- ColorDialog colorDialog = new ColorDialog("Set Secondary Color", Settings.CurrentLayout.Theme.SecondaryColor)
- {
- Owner = this
- };
-
- if (colorDialog.ShowDialog() == true)
- {
- Settings.CurrentLayout.Theme.SecondaryColor = colorDialog.ResultColor;
- secondaryColorRechtangle.Fill = colorDialog.ResultBrush;
- }
- }
-
- private void ChangeBackgroundColorButton_Click(object sender, RoutedEventArgs e)
- {
- ColorDialog colorDialog = new ColorDialog("Set Background Color", Settings.CurrentLayout.Theme.BackgroundColor)
- {
- Owner = this
- };
-
- if (colorDialog.ShowDialog() == true)
- {
- Settings.CurrentLayout.Theme.BackgroundColor = colorDialog.ResultColor;
- backgroundColorRechtangle.Fill = colorDialog.ResultBrush;
- }
- }
-
- private void CornerRadiusTextBox_TextChanged(object? sender, TextChangedEventArgs? e)
- {
- bool success = int.TryParse(cornerRadiusTextBox.Text, out int cornerRadius);
- if (success)
- {
- cornerRadiusTextBox.Foreground = Brushes.Black;
- Settings.CurrentLayout.Theme.CornerRadius = cornerRadius;
- }
- else
- {
- cornerRadiusTextBox.Foreground = Brushes.Red;
- }
- }
-
- private void MarginTextBox_TextChanged(object? sender, TextChangedEventArgs? e)
- {
- bool success = int.TryParse(marginTextBox.Text, out int margin);
- if (success)
- {
- marginTextBox.Foreground = Brushes.Black;
- Settings.CurrentLayout.Theme.Margin = margin;
- }
- else
- {
- marginTextBox.Foreground = Brushes.Red;
- }
- }
-
#region Layout
private readonly JsonSerializerOptions jsonSettingsOptions = new()
@@ -517,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();
}
@@ -536,42 +486,34 @@ namespace DesktopMagic
{
if (!File.Exists(Path.Combine(App.ApplicationDataPath, "settings.json")))
{
- Settings = new DesktopMagicSettings()
- {
- Layouts =
- [
- new Layout((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(json, jsonSettingsOptions) ?? new DesktopMagicSettings()
+ Settings = JsonSerializer.Deserialize(json, jsonSettingsOptions) ?? new DesktopMagicSettings();
+
+ if(Settings.Layouts.Count == 0)
{
- Layouts =
- [
- new Layout((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)
{
mainWindowDataContext.IsLoading = true;
- cornerRadiusTextBox.Text = Settings.CurrentLayout.Theme.CornerRadius.ToString();
- marginTextBox.Text = Settings.CurrentLayout.Theme.Margin.ToString();
blockWindowsClosing = false;
- primaryColorRechtangle.Fill = new SolidColorBrush(MultiColorConverter.ConvertToMediaColor(Settings.CurrentLayout.Theme.PrimaryColor));
- secondaryColorRechtangle.Fill = new SolidColorBrush(MultiColorConverter.ConvertToMediaColor(Settings.CurrentLayout.Theme.SecondaryColor));
- backgroundColorRechtangle.Fill = new SolidColorBrush(MultiColorConverter.ConvertToMediaColor(Settings.CurrentLayout.Theme.BackgroundColor));
-
- CornerRadiusTextBox_TextChanged(null, null);
- MarginTextBox_TextChanged(null, null);
-
foreach (Window window in Windows)
{
window.Close();
diff --git a/src/DesktopMagic/Plugins/PluginData.cs b/src/DesktopMagic/Plugins/PluginData.cs
index 19162d3..6a39238 100644
--- a/src/DesktopMagic/Plugins/PluginData.cs
+++ b/src/DesktopMagic/Plugins/PluginData.cs
@@ -9,7 +9,7 @@ internal class PluginData(PluginWindow window, PluginSettings pluginSettings) :
{
private readonly PluginWindow window = window;
- public ITheme Theme { get; } = pluginSettings.Theme;
+ public ITheme Theme => pluginSettings.Theme;
public Size WindowSize => new Size((int)window.ActualWidth, (int)window.ActualHeight);
diff --git a/src/DesktopMagic/Plugins/PluginWindow.xaml.cs b/src/DesktopMagic/Plugins/PluginWindow.xaml.cs
index 86a097e..097ee17 100644
--- a/src/DesktopMagic/Plugins/PluginWindow.xaml.cs
+++ b/src/DesktopMagic/Plugins/PluginWindow.xaml.cs
@@ -1,6 +1,7 @@
using DesktopMagic.Api;
using DesktopMagic.Api.Drawing;
using DesktopMagic.Api.Settings;
+using DesktopMagic.DataContexts;
using DesktopMagic.Helpers;
using DesktopMagic.Plugins;
using DesktopMagic.Settings;
@@ -56,7 +57,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;
@@ -240,9 +251,15 @@ public partial class PluginWindow : Window
{
SetHorizontalAlignment();
SetVerticalAlignment();
+ SetThemeOverride();
+ SetThemeOverrideItems();
pluginClassInstance.horizontalAlignment.OnValueChanged += SetHorizontalAlignment;
pluginClassInstance.verticalAlignment.OnValueChanged += SetVerticalAlignment;
+ pluginClassInstance.themeOverride.OnValueChanged += SetThemeOverride;
+
+ DesktopMagicSettings desktopMagicSettings = MainWindowDataContext.GetSettings();
+ desktopMagicSettings.Themes.CollectionChanged += (s, e) => SetThemeOverrideItems();
});
void SetVerticalAlignment()
@@ -272,6 +289,31 @@ public partial class PluginWindow : Window
viewBox.HorizontalAlignment = horizontalAlignment;
border.HorizontalAlignment = horizontalAlignment;
}
+
+ void SetThemeOverride()
+ {
+ if (pluginClassInstance.themeOverride.Value == "")
+ {
+ settings.CurrentThemeName = null;
+ }
+ else
+ {
+ settings.CurrentThemeName = pluginClassInstance.themeOverride.Value;
+ }
+ }
+
+ void SetThemeOverrideItems()
+ {
+ DesktopMagicSettings desktopMagicSettings = MainWindowDataContext.GetSettings();
+
+ pluginClassInstance.themeOverride.Items.Clear();
+ pluginClassInstance.themeOverride.Items.Add("");
+
+ foreach (Theme theme in desktopMagicSettings.Themes)
+ {
+ pluginClassInstance.themeOverride.Items.Add(theme.Name);
+ }
+ }
}
private void LoadOptions(object instance)
diff --git a/src/DesktopMagic/Plugins/Theme.cs b/src/DesktopMagic/Plugins/Theme.cs
index 2ed05d5..9f96709 100644
--- a/src/DesktopMagic/Plugins/Theme.cs
+++ b/src/DesktopMagic/Plugins/Theme.cs
@@ -11,17 +11,27 @@ using Color = System.Drawing.Color;
namespace DesktopMagic.Plugins;
-public class Theme : ITheme, INotifyPropertyChanged
+public class Theme(string name) : ITheme, INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;
private Color primaryColor = Color.White;
- private Color secondaryColor = Color.White;
+ private Color secondaryColor = Color.LightGray;
private Color backgroundColor = Color.Transparent;
private string font = "Segoe UI";
private int cornerRadius;
private int margin;
+ public string Name
+ {
+ get => name;
+ set
+ {
+ name = value;
+ OnPropertyChanged();
+ }
+ }
+
public Color PrimaryColor
{
get => primaryColor;
diff --git a/src/DesktopMagic/Resources/Strings/StringResources.de.xaml b/src/DesktopMagic/Resources/Strings/StringResources.de.xaml
index e3180a4..910d844 100644
--- a/src/DesktopMagic/Resources/Strings/StringResources.de.xaml
+++ b/src/DesktopMagic/Resources/Strings/StringResources.de.xaml
@@ -26,7 +26,7 @@
Standard
Wollen sie das Programm wirklich schließen?
Keine Optionen!
- Bearbeiten
+ Layout Bearbeiten
Uhrzeit
Datum
CPU Auslastung
@@ -34,10 +34,15 @@
Signalverstärkung:
Neues Layout
Layout Löschen
+ Neues Theme
+ Theme Löschen
+ Theme Ändern
Ok
Abbrechen
Layoutnamen eingeben:
Layout existiert bereits!
+ Themenamen eingeben:
+ Theme existiert bereits!
Installieren
Deinstallieren
Entfernen
diff --git a/src/DesktopMagic/Resources/Strings/StringResources.en.xaml b/src/DesktopMagic/Resources/Strings/StringResources.en.xaml
index e4e5d3c..d19026b 100644
--- a/src/DesktopMagic/Resources/Strings/StringResources.en.xaml
+++ b/src/DesktopMagic/Resources/Strings/StringResources.en.xaml
@@ -26,7 +26,7 @@
Default
Do you really want to close the program?
No Options!
- Edit
+ Edit Layout
Time
Date
CPU Usage
@@ -34,10 +34,17 @@
Signal Amplification:
New Layout
Delete Layout
+ New Theme
+ Delete Theme
+ Change Theme
Ok
Cancel
Enter layout name
Layout already exists!
+ Can't delete last layout!
+ Enter theme name
+ Theme already exists!
+ Can't delete last theme!
Install
Uninstall
Remove
diff --git a/src/DesktopMagic/Settings/DesktopMagicSettings.cs b/src/DesktopMagic/Settings/DesktopMagicSettings.cs
index 035699a..62409e8 100644
--- a/src/DesktopMagic/Settings/DesktopMagicSettings.cs
+++ b/src/DesktopMagic/Settings/DesktopMagicSettings.cs
@@ -1,4 +1,6 @@
-using System.Collections.ObjectModel;
+using DesktopMagic.Plugins;
+
+using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
@@ -11,14 +13,28 @@ internal class DesktopMagicSettings : INotifyPropertyChanged
public event PropertyChangedEventHandler? PropertyChanged;
private ObservableCollection layouts = [];
+ private ObservableCollection themes = [];
private string? currentLayoutName;
+ public ObservableCollection Themes
+ {
+ get => themes;
+ init
+ {
+ themes = value;
+ themes.CollectionChanged += (s, e) => CurrentLayout.UpdateTheme();
+ OnPropertyChanged();
+ }
+ }
+
public ObservableCollection Layouts
{
get => layouts;
set
{
layouts = value;
+ layouts.CollectionChanged += (s, e) => OnPropertyChanged(nameof(CurrentLayout));
+ layouts.CollectionChanged += (s, e) => OnPropertyChanged(nameof(CurrentLayoutName));
OnPropertyChanged();
}
}
@@ -39,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));
diff --git a/src/DesktopMagic/Settings/Layout.cs b/src/DesktopMagic/Settings/Layout.cs
index 03a42d9..420f746 100644
--- a/src/DesktopMagic/Settings/Layout.cs
+++ b/src/DesktopMagic/Settings/Layout.cs
@@ -1,9 +1,11 @@
-using DesktopMagic.Plugins;
+using DesktopMagic.DataContexts;
+using DesktopMagic.Plugins;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
+using System.Text.Json.Serialization;
namespace DesktopMagic.Settings;
@@ -12,16 +14,29 @@ internal class Layout(string name) : INotifyPropertyChanged
public event PropertyChangedEventHandler? PropertyChanged;
private string name = name;
- private Theme theme = new Theme();
+ private string? currentThemeName = null;
private Dictionary plugins = [];
+ [JsonIgnore]
public Theme Theme
{
- get => theme;
+ get
+ {
+ DesktopMagicSettings settings = MainWindowDataContext.GetSettings();
+ return settings.Themes.FirstOrDefault(theme => theme.Name == currentThemeName) ?? settings.Themes.FirstOrDefault() ?? new Theme("ERROR");
+ }
+ }
+
+ public string? CurrentThemeName
+ {
+ get => Theme.Name;
set
{
- theme = value;
- OnPropertyChanged();
+ if (currentThemeName != value)
+ {
+ currentThemeName = value;
+ UpdateTheme();
+ }
}
}
@@ -47,7 +62,19 @@ internal class Layout(string name) : INotifyPropertyChanged
public void UpdatePlugins()
{
- Plugins = Plugins.ToDictionary();
+ plugins = plugins.ToDictionary();
+ 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)
diff --git a/src/DesktopMagic/Settings/PluginSettings.cs b/src/DesktopMagic/Settings/PluginSettings.cs
index b9ae278..8261f7b 100644
--- a/src/DesktopMagic/Settings/PluginSettings.cs
+++ b/src/DesktopMagic/Settings/PluginSettings.cs
@@ -3,6 +3,7 @@ using DesktopMagic.Plugins;
using System.Collections.Generic;
using System.ComponentModel;
+using System.Linq;
using System.Runtime.CompilerServices;
using System.Text.Json.Serialization;
using System.Windows;
@@ -13,19 +14,40 @@ public class PluginSettings : INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;
- private readonly Theme? theme;
+ private string? currentThemeName;
private List settings = [];
private bool enabled = false;
private Point position = new Point(100, 100);
private Point size = new Point(300, 300);
- [JsonIgnore]
- public Theme Theme => theme is null ? MainWindowDataContext.GetSettings().CurrentLayout.Theme : theme;
-
// Only for internal use to show the name of the plugin in the main window
[JsonIgnore]
public string Name { get; set; } = string.Empty;
+ [JsonIgnore]
+ public Theme Theme
+ {
+ get
+ {
+ DesktopMagicSettings settings = MainWindowDataContext.GetSettings();
+ return settings.Themes.FirstOrDefault(t => t.Name == currentThemeName) ?? settings.CurrentLayout.Theme;
+ }
+ }
+
+ public string? CurrentThemeName
+ {
+ get => currentThemeName;
+ set
+ {
+ if (currentThemeName != value)
+ {
+ currentThemeName = value;
+ OnPropertyChanged();
+ OnPropertyChanged(nameof(Theme));
+ }
+ }
+ }
+
public List Settings
{
get => settings;
@@ -78,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));
diff --git a/src/DesktopMagicPluginAPI/Plugin.cs b/src/DesktopMagicPluginAPI/Plugin.cs
index eaaa47e..911db6c 100644
--- a/src/DesktopMagicPluginAPI/Plugin.cs
+++ b/src/DesktopMagicPluginAPI/Plugin.cs
@@ -17,6 +17,9 @@ public abstract class Plugin
[Setting("desktopmagic-vertical-alignment", "Vertical Alignment", -998)]
internal ComboBox verticalAlignment = new ComboBox("Center", "Top", "Bottom");
+ [Setting("theme-override", "Theme Override", -997)]
+ internal ComboBox themeOverride = new ComboBox("");
+
private IPluginData application = null!;
///
diff --git a/src/MsixPackaging/Package.appxmanifest b/src/MsixPackaging/Package.appxmanifest
index 9345989..09355a6 100644
--- a/src/MsixPackaging/Package.appxmanifest
+++ b/src/MsixPackaging/Package.appxmanifest
@@ -9,7 +9,7 @@
+ Version="1.2.0.0" />
Desktop Magic