diff --git a/I18N Commander/DataModel/Database/SettingDeepLAction.cs b/I18N Commander/DataModel/Database/SettingDeepLAction.cs new file mode 100644 index 0000000..50312d7 --- /dev/null +++ b/I18N Commander/DataModel/Database/SettingDeepLAction.cs @@ -0,0 +1,7 @@ +namespace DataModel.Database; + +public enum SettingDeepLAction +{ + MANUAL, + AUTOMATIC_ALL, +} \ No newline at end of file diff --git a/I18N Commander/DataModel/Database/SettingNames.cs b/I18N Commander/DataModel/Database/SettingNames.cs index 7a41b64..d507d63 100644 --- a/I18N Commander/DataModel/Database/SettingNames.cs +++ b/I18N Commander/DataModel/Database/SettingNames.cs @@ -2,6 +2,7 @@ public static class SettingNames { + public static readonly string DEEPL_ACTION = "DeepL Action"; public static readonly string DEEPL_API_KEY = "DeepL API Key"; public static readonly string DEEPL_MODE = "DeepL Mode"; } \ No newline at end of file diff --git a/I18N Commander/Processor/AppSettings.cs b/I18N Commander/Processor/AppSettings.cs index 63f28f5..1d97a66 100644 --- a/I18N Commander/Processor/AppSettings.cs +++ b/I18N Commander/Processor/AppSettings.cs @@ -113,4 +113,59 @@ public static class AppSettings } #endregion + + #region DeepL Action + + public static async Task SetDeepLAction(SettingDeepLAction action) + { + // Convert the enum to its int value: + var intValue = (int)action; + + // 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.DEEPL_ACTION) is {} existingSetting) + { + existingSetting.IntegerValue = intValue; + await db.SaveChangesAsync(); + } + + // Does not exist, so create it: + else + { + var setting = new Setting + { + Code = SettingNames.DEEPL_ACTION, + IntegerValue = intValue, + }; + + await db.Settings.AddAsync(setting); + await db.SaveChangesAsync(); + } + } + + public static async Task GetDeepLAction() + { + // 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.DEEPL_ACTION) is { } existingSetting) + return (SettingDeepLAction) existingSetting.IntegerValue; + + // Does not exist, so create it: + var setting = new Setting + { + Code = SettingNames.DEEPL_ACTION, + IntegerValue = (int)SettingDeepLAction.MANUAL, + }; + + await db.Settings.AddAsync(setting); + await db.SaveChangesAsync(); + + return (SettingDeepLAction) setting.IntegerValue; + } + + #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 e7a6966..6bff82f 100644 --- a/I18N Commander/UI WinForms/Components/Setting.cs +++ b/I18N Commander/UI WinForms/Components/Setting.cs @@ -108,9 +108,51 @@ public sealed partial class Setting : UserControl return new Setting(settingData); } + + private static async Task ShowDeepLActionSettingAsync() + { + var currentSetting = await AppSettings.GetDeepLAction(); + var settingData = new SettingUIData( + Icon: Icons.icons8_play_512__2_, + SettingName: () => "DeepL Operation", + SettingExplanation: () => "Should the missing translations be automatically completed by DeepL? This can lead to higher costs. By default, DeepL is only applied manually.", + SetupDataControl: () => + { + // We set up a combo box with the available actions: + var dropdown = new ComboBox(); + dropdown.Items.Add("Manual"); + dropdown.Items.Add("Automatic"); + dropdown.SelectedIndex = currentSetting switch + { + SettingDeepLAction.MANUAL => 0, + SettingDeepLAction.AUTOMATIC_ALL => 1, + + _ => 0, + }; + + // Setup the change event handler: + dropdown.SelectedValueChanged += async (sender, args) => await AppSettings.SetDeepLAction(dropdown.SelectedIndex switch + { + 0 => SettingDeepLAction.MANUAL, + 1 => SettingDeepLAction.AUTOMATIC_ALL, + + _ => SettingDeepLAction.MANUAL, + }); + + // Apply the desired layout: + dropdown.Dock = DockStyle.Fill; + dropdown.DropDownStyle = ComboBoxStyle.DropDownList; + + return dropdown; + } + ); + + return new Setting(settingData); + } public static IEnumerable> GetAllSettings() { + yield return ShowDeepLActionSettingAsync(); yield return ShowDeepLAPIKeySettingAsync(); yield return ShowDeepLModeSettingAsync(); } diff --git a/I18N Commander/UI WinForms/Resources/Icons.Designer.cs b/I18N Commander/UI WinForms/Resources/Icons.Designer.cs index bb5ab78..f0d5fcd 100644 --- a/I18N Commander/UI WinForms/Resources/Icons.Designer.cs +++ b/I18N Commander/UI WinForms/Resources/Icons.Designer.cs @@ -200,6 +200,16 @@ namespace UI_WinForms.Resources { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap icons8_play_512__2_ { + get { + object obj = ResourceManager.GetObject("icons8_play_512__2_", 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 e4db609..a18a78c 100644 --- a/I18N Commander/UI WinForms/Resources/Icons.resx +++ b/I18N Commander/UI WinForms/Resources/Icons.resx @@ -160,6 +160,9 @@ icons8-open-file-under-cursor-512.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + icons8-play-512 (2).png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + icons8-remove-tag-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-play-512 (2).png b/I18N Commander/UI WinForms/Resources/icons8-play-512 (2).png new file mode 100644 index 0000000..03d329f Binary files /dev/null and b/I18N Commander/UI WinForms/Resources/icons8-play-512 (2).png differ