diff --git a/I18N Commander/DataModel/Database/SettingGeneratorMode.cs b/I18N Commander/DataModel/Database/SettingGeneratorMode.cs new file mode 100644 index 0000000..bcfab42 --- /dev/null +++ b/I18N Commander/DataModel/Database/SettingGeneratorMode.cs @@ -0,0 +1,7 @@ +namespace DataModel.Database; + +public enum SettingGeneratorMode +{ + AUTOMATIC, + MANUAL, +} \ No newline at end of file diff --git a/I18N Commander/DataModel/Database/SettingNames.cs b/I18N Commander/DataModel/Database/SettingNames.cs index d4ee3fb..734eaed 100644 --- a/I18N Commander/DataModel/Database/SettingNames.cs +++ b/I18N Commander/DataModel/Database/SettingNames.cs @@ -2,9 +2,10 @@ public static class SettingNames { - public static readonly string DEEPL_SOURCE_CULTURE = "DeepL Source Culture"; public static readonly string CULTURE = "Culture"; public static readonly string DEEPL_ACTION = "DeepL Action"; public static readonly string DEEPL_API_KEY = "DeepL API Key"; + public static readonly string DEEPL_SOURCE_CULTURE = "DeepL Source Culture"; public static readonly string DEEPL_MODE = "DeepL Mode"; + public static readonly string GENERATOR_MODE = "Generator Mode"; } \ No newline at end of file diff --git a/I18N Commander/Processor/AppSettings.cs b/I18N Commander/Processor/AppSettings.cs index 9b75cb0..8526d7a 100644 --- a/I18N Commander/Processor/AppSettings.cs +++ b/I18N Commander/Processor/AppSettings.cs @@ -460,4 +460,82 @@ public static class AppSettings #endregion #endregion + + #region Generator Settings + + #region Generator Mode + + private static SettingGeneratorMode CACHE_GENERATOR_MODE = SettingGeneratorMode.MANUAL; + private static bool CACHE_GENERATOR_MODE_IS_LOADED = false; + + public static async Task GetGeneratorMode() + { + // When possible, use the cache: + if (CACHE_GENERATOR_MODE_IS_LOADED) + return CACHE_GENERATOR_MODE; + + var generatorMode = SettingGeneratorMode.MANUAL; + try + { + // Get the database: + await using var db = ProcessorMeta.ServiceProvider.GetRequiredService(); + + // Check, if the setting is already set: + if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.GENERATOR_MODE) is { } existingSetting) + { + generatorMode = (SettingGeneratorMode) existingSetting.IntegerValue; + return generatorMode; + } + + // Does not exist, so create it: + var setting = new Setting + { + Code = SettingNames.GENERATOR_MODE, + IntegerValue = (int) generatorMode, + }; + + await db.Settings.AddAsync(setting); + await db.SaveChangesAsync(); + return generatorMode; + } + finally + { + CACHE_GENERATOR_MODE_IS_LOADED = true; + CACHE_GENERATOR_MODE = generatorMode; + } + } + + public static async Task SetGeneratorMode(SettingGeneratorMode mode) + { + // Update the cache: + CACHE_GENERATOR_MODE = mode; + CACHE_GENERATOR_MODE_IS_LOADED = true; + + // Get the database: + await using var db = ProcessorMeta.ServiceProvider.GetRequiredService(); + + // Check, if the setting is already set: + if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.GENERATOR_MODE) is { } existingSetting) + { + existingSetting.IntegerValue = (int) mode; + await db.SaveChangesAsync(); + } + + // Does not exist, so create it: + else + { + var setting = new Setting + { + Code = SettingNames.GENERATOR_MODE, + IntegerValue = (int) mode, + }; + + await db.Settings.AddAsync(setting); + await db.SaveChangesAsync(); + } + } + + #endregion + + #endregion } \ No newline at end of file diff --git a/I18N Commander/UI WinForms/Components/Setting.cs b/I18N Commander/UI WinForms/Components/Setting.cs index 2bee739..c354430 100644 --- a/I18N Commander/UI WinForms/Components/Setting.cs +++ b/I18N Commander/UI WinForms/Components/Setting.cs @@ -388,9 +388,55 @@ public sealed partial class Setting : UserControl cultureIndices.Remove(innerLoopIndex); } } + + private static async Task ShowGeneratorModeSettingAsync() + { + var currentSetting = await AppSettings.GetGeneratorMode(); + + var settingData = new SettingUIData( + Icon: Icons.icons8_code_512, + SettingName: () => "Generator Mode", + ChangeNeedsRestart: false, + SettingExplanation: () => "The generator mode determines how the translation files are generated.", + SettingExplanationLink: () => (string.Empty, string.Empty), + SetupDataControl: (changeTrigger) => + { + // We set up a combo box with the available actions: + var dropdown = new ComboBox(); + dropdown.Items.Add("Automatic generation"); + dropdown.Items.Add("Manual generation"); + dropdown.SelectedIndex = currentSetting switch + { + SettingGeneratorMode.AUTOMATIC => 0, + SettingGeneratorMode.MANUAL => 1, + + _ => 0, + }; + + // Setup the change event handler: + dropdown.SelectedValueChanged += (sender, args) => changeTrigger(); + dropdown.SelectedValueChanged += async (sender, args) => await AppSettings.SetGeneratorMode(dropdown.SelectedIndex switch + { + 0 => SettingGeneratorMode.AUTOMATIC, + 1 => SettingGeneratorMode.MANUAL, + + _ => SettingGeneratorMode.AUTOMATIC, + }); + + // Apply the desired layout: + dropdown.Dock = DockStyle.Fill; + dropdown.DropDownStyle = ComboBoxStyle.DropDownList; + + return dropdown; + } + ); + + return new Setting(settingData); + } public static IEnumerable> GetAllSettings() { + yield return ShowGeneratorModeSettingAsync(); yield return ShowDeepLSourceCultureSettingAsync(); foreach (var setting in ShowCultureSettingsAsync()) { diff --git a/I18N Commander/UI WinForms/Resources/Icons.Designer.cs b/I18N Commander/UI WinForms/Resources/Icons.Designer.cs index cedf6c1..95a9b6e 100644 --- a/I18N Commander/UI WinForms/Resources/Icons.Designer.cs +++ b/I18N Commander/UI WinForms/Resources/Icons.Designer.cs @@ -140,6 +140,16 @@ namespace UI_WinForms.Resources { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap icons8_code_512 { + get { + object obj = ResourceManager.GetObject("icons8_code_512", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/I18N Commander/UI WinForms/Resources/Icons.resx b/I18N Commander/UI WinForms/Resources/Icons.resx index 9cfa843..15f9723 100644 --- a/I18N Commander/UI WinForms/Resources/Icons.resx +++ b/I18N Commander/UI WinForms/Resources/Icons.resx @@ -142,6 +142,9 @@ icons8-chat-bubble-512.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + icons8-code-512.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + icons8-collectibles-512.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a diff --git a/I18N Commander/UI WinForms/Resources/icons8-code-512.png b/I18N Commander/UI WinForms/Resources/icons8-code-512.png new file mode 100644 index 0000000..00d10eb Binary files /dev/null and b/I18N Commander/UI WinForms/Resources/icons8-code-512.png differ