From ead20d12798928c085fd351052a3918be1e49405 Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Mon, 30 Dec 2024 16:54:04 +0100 Subject: [PATCH] Change GetLanguageDictionary method to LanguageDictionary property --- src/DesktopMagic/App.xaml.cs | 37 ++++++++++--------- .../DataContexts/PluginEntryDataContext.cs | 10 ++--- src/DesktopMagic/Dialogs/ColorDialog.xaml.cs | 2 +- src/DesktopMagic/Dialogs/InputDialog.xaml.cs | 2 +- src/DesktopMagic/MainWindow.xaml.cs | 18 ++++----- .../Plugins/PluginManager.xaml.cs | 2 +- 6 files changed, 37 insertions(+), 34 deletions(-) diff --git a/src/DesktopMagic/App.xaml.cs b/src/DesktopMagic/App.xaml.cs index 599b3df..55be20b 100644 --- a/src/DesktopMagic/App.xaml.cs +++ b/src/DesktopMagic/App.xaml.cs @@ -66,6 +66,26 @@ public partial class App : Application } }; + public static ResourceDictionary LanguageDictionary + { + get + { + ResourceDictionary dict = []; + string currentCulture = Thread.CurrentThread.CurrentUICulture.ToString(); + + if (currentCulture.Contains("de")) + { + dict.Source = new Uri("..\\Resources\\Strings\\StringResources.de.xaml", UriKind.Relative); + } + else + { + dict.Source = new Uri("..\\Resources\\Strings\\StringResources.en.xaml", UriKind.Relative); + } + + return dict; + } + } + private static string PreviousApplicationDataPath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "StoneRed", PreviousAppName); public App() @@ -98,23 +118,6 @@ public partial class App : Application } } - public static ResourceDictionary GetLanguageDictionary() - { - ResourceDictionary dict = []; - string currentCulture = Thread.CurrentThread.CurrentUICulture.ToString(); - - if (currentCulture.Contains("de")) - { - dict.Source = new Uri("..\\Resources\\Strings\\StringResources.de.xaml", UriKind.Relative); - } - else - { - dict.Source = new Uri("..\\Resources\\Strings\\StringResources.en.xaml", UriKind.Relative); - } - - return dict; - } - protected void CloseHandler(object sender, EventArgs e) { eventWaitHandle.Close(); diff --git a/src/DesktopMagic/DataContexts/PluginEntryDataContext.cs b/src/DesktopMagic/DataContexts/PluginEntryDataContext.cs index 500dda1..500f301 100644 --- a/src/DesktopMagic/DataContexts/PluginEntryDataContext.cs +++ b/src/DesktopMagic/DataContexts/PluginEntryDataContext.cs @@ -22,9 +22,9 @@ internal class PluginEntryDataContext(PluginMetadata pluginMetadata, ICommand co public string? Description => pluginMetadata.Description; - public string Author => pluginMetadata.Author ?? (string)App.GetLanguageDictionary()["unknown"]; + public string Author => pluginMetadata.Author ?? (string)App.LanguageDictionary["unknown"]; - public string? Version => pluginMetadata.Version ?? (string)App.GetLanguageDictionary()["unknown"]; + public string? Version => pluginMetadata.Version ?? (string)App.LanguageDictionary["unknown"]; public string? Logo => pluginMetadata.IconUri?.ToString(); @@ -43,7 +43,7 @@ internal class PluginEntryDataContext(PluginMetadata pluginMetadata, ICommand co { if (string.IsNullOrWhiteSpace(pluginMetadata.ProfileUri?.ToString())) { - return new(PackIconKind.FolderOutline, (string)App.GetLanguageDictionary()["folder"], path is not null, new CommandHandler(() => Process.Start("explorer.exe", path!))); + return new(PackIconKind.FolderOutline, (string)App.LanguageDictionary["folder"], path is not null, new CommandHandler(() => Process.Start("explorer.exe", path!))); } else { @@ -80,8 +80,8 @@ internal class PluginEntryDataContext(PluginMetadata pluginMetadata, ICommand co { return mode switch { - Mode.Install => (string)App.GetLanguageDictionary()["install"], - Mode.Uninstall => (string)App.GetLanguageDictionary()["uninstall"], + Mode.Install => (string)App.LanguageDictionary["install"], + Mode.Uninstall => (string)App.LanguageDictionary["uninstall"], _ => throw new NotImplementedException() }; } diff --git a/src/DesktopMagic/Dialogs/ColorDialog.xaml.cs b/src/DesktopMagic/Dialogs/ColorDialog.xaml.cs index 3a141bc..af9b60c 100644 --- a/src/DesktopMagic/Dialogs/ColorDialog.xaml.cs +++ b/src/DesktopMagic/Dialogs/ColorDialog.xaml.cs @@ -19,7 +19,7 @@ public partial class ColorDialog : Window { InitializeComponent(); - Resources.MergedDictionaries.Add(App.GetLanguageDictionary()); + Resources.MergedDictionaries.Add(App.LanguageDictionary); label.Content = content; Title = title; diff --git a/src/DesktopMagic/Dialogs/InputDialog.xaml.cs b/src/DesktopMagic/Dialogs/InputDialog.xaml.cs index bafad17..c0beac8 100644 --- a/src/DesktopMagic/Dialogs/InputDialog.xaml.cs +++ b/src/DesktopMagic/Dialogs/InputDialog.xaml.cs @@ -14,7 +14,7 @@ public partial class InputDialog : Window { InitializeComponent(); - Resources.MergedDictionaries.Add(App.GetLanguageDictionary()); + Resources.MergedDictionaries.Add(App.LanguageDictionary); label.Content = content; Title = title; diff --git a/src/DesktopMagic/MainWindow.xaml.cs b/src/DesktopMagic/MainWindow.xaml.cs index 6b41b14..5b58189 100644 --- a/src/DesktopMagic/MainWindow.xaml.cs +++ b/src/DesktopMagic/MainWindow.xaml.cs @@ -26,10 +26,10 @@ namespace DesktopMagic private readonly Dictionary builtInPlugins = new() { - {new((string)App.GetLanguageDictionary()["musicVisualizer"], 1), typeof(MusicVisualizerPlugin)}, - {new((string)App.GetLanguageDictionary()["time"],2), typeof(TimePlugin)}, - {new((string)App.GetLanguageDictionary()["date"],3), typeof(DatePlugin)}, - {new((string)App.GetLanguageDictionary()["cpuUsage"], 4), typeof(CpuMonitorPlugin)} + {new((string)App.LanguageDictionary["musicVisualizer"], 1), typeof(MusicVisualizerPlugin)}, + {new((string)App.LanguageDictionary["time"],2), typeof(TimePlugin)}, + {new((string)App.LanguageDictionary["date"],3), typeof(DatePlugin)}, + {new((string)App.LanguageDictionary["cpuUsage"], 4), typeof(CpuMonitorPlugin)} }; private bool loaded = false; @@ -58,17 +58,17 @@ namespace DesktopMagic { Items = { - new System.Windows.Forms.ToolStripMenuItem((string)App.GetLanguageDictionary()["open"], null, (s, e) => RestoreWindow()), - new System.Windows.Forms.ToolStripMenuItem((string)App.GetLanguageDictionary()["toggleEditMode"], null, (s, e) => { EditCheckBox.IsChecked = !EditCheckBox.IsChecked; EditCheckBox_Click(null, null); }), - new System.Windows.Forms.ToolStripMenuItem((string)App.GetLanguageDictionary()["pluginManager"], null, (s, e) => PluginManagerButton_Click(null!, null!)), + new System.Windows.Forms.ToolStripMenuItem((string)App.LanguageDictionary["open"], null, (s, e) => RestoreWindow()), + new System.Windows.Forms.ToolStripMenuItem((string)App.LanguageDictionary ["toggleEditMode"], null, (s, e) => { EditCheckBox.IsChecked = !EditCheckBox.IsChecked; EditCheckBox_Click(null, null); }), + new System.Windows.Forms.ToolStripMenuItem((string)App.LanguageDictionary["pluginManager"], null, (s, e) => PluginManagerButton_Click(null!, null!)), new System.Windows.Forms.ToolStripMenuItem("GitHub", null, (s, e) => GitHubButton_Click(null!, null!)), - new System.Windows.Forms.ToolStripMenuItem((string)App.GetLanguageDictionary()["quit"], null, (s, e) => Quit()), + new System.Windows.Forms.ToolStripMenuItem((string)App.LanguageDictionary["quit"], null, (s, e) => Quit()), } }; InitializeComponent(); - Resources.MergedDictionaries.Add(App.GetLanguageDictionary()); + Resources.MergedDictionaries.Add(App.LanguageDictionary); #if DEBUG Title = $"{App.AppName} - Dev {System.Windows.Forms.Application.ProductVersion}"; diff --git a/src/DesktopMagic/Plugins/PluginManager.xaml.cs b/src/DesktopMagic/Plugins/PluginManager.xaml.cs index 8672ee5..78d3cc2 100644 --- a/src/DesktopMagic/Plugins/PluginManager.xaml.cs +++ b/src/DesktopMagic/Plugins/PluginManager.xaml.cs @@ -44,7 +44,7 @@ public partial class PluginManager : Window { InitializeComponent(); - Resources.MergedDictionaries.Add(App.GetLanguageDictionary()); + Resources.MergedDictionaries.Add(App.LanguageDictionary); DataContext = pluginManagerDataContext; searchTimer.Tick += async (sender, e) =>