Added DeepL action setting
This commit is contained in:
parent
9cd735ad5c
commit
c211c9ef62
7
I18N Commander/DataModel/Database/SettingDeepLAction.cs
Normal file
7
I18N Commander/DataModel/Database/SettingDeepLAction.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace DataModel.Database;
|
||||||
|
|
||||||
|
public enum SettingDeepLAction
|
||||||
|
{
|
||||||
|
MANUAL,
|
||||||
|
AUTOMATIC_ALL,
|
||||||
|
}
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
public static class SettingNames
|
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_API_KEY = "DeepL API Key";
|
||||||
public static readonly string DEEPL_MODE = "DeepL Mode";
|
public static readonly string DEEPL_MODE = "DeepL Mode";
|
||||||
}
|
}
|
@ -113,4 +113,59 @@ public static class AppSettings
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#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<DataContext>();
|
||||||
|
|
||||||
|
// 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<SettingDeepLAction> GetDeepLAction()
|
||||||
|
{
|
||||||
|
// Get the database:
|
||||||
|
await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
|
||||||
|
|
||||||
|
// 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
|
||||||
}
|
}
|
@ -108,9 +108,51 @@ public sealed partial class Setting : UserControl
|
|||||||
|
|
||||||
return new Setting(settingData);
|
return new Setting(settingData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static async Task<Setting> 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<Task<Setting>> GetAllSettings()
|
public static IEnumerable<Task<Setting>> GetAllSettings()
|
||||||
{
|
{
|
||||||
|
yield return ShowDeepLActionSettingAsync();
|
||||||
yield return ShowDeepLAPIKeySettingAsync();
|
yield return ShowDeepLAPIKeySettingAsync();
|
||||||
yield return ShowDeepLModeSettingAsync();
|
yield return ShowDeepLModeSettingAsync();
|
||||||
}
|
}
|
||||||
|
@ -200,6 +200,16 @@ namespace UI_WinForms.Resources {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Bitmap icons8_play_512__2_ {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("icons8_play_512__2_", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -160,6 +160,9 @@
|
|||||||
<data name="icons8_open_file_under_cursor_512" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
<data name="icons8_open_file_under_cursor_512" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
<value>icons8-open-file-under-cursor-512.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
<value>icons8-open-file-under-cursor-512.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="icons8_play_512__2_" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>icons8-play-512 (2).png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
<data name="icons8_remove_tag_512" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
<data name="icons8_remove_tag_512" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
<value>icons8-remove-tag-512.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
<value>icons8-remove-tag-512.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
</data>
|
</data>
|
||||||
|
BIN
I18N Commander/UI WinForms/Resources/icons8-play-512 (2).png
Normal file
BIN
I18N Commander/UI WinForms/Resources/icons8-play-512 (2).png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.0 KiB |
Loading…
Reference in New Issue
Block a user