Add optional manual mode per translation and culture
This commit is contained in:
8 files changed
+326
-8
No files matched your search
+34
-2
@@ -32,9 +32,12 @@
|
||||
this.tableLayout = new System.Windows.Forms.TableLayoutPanel();
|
||||
this.labelHead = new System.Windows.Forms.Label();
|
||||
this.textBox = new System.Windows.Forms.TextBox();
|
||||
this.flowLayoutHeaderTools = new System.Windows.Forms.FlowLayoutPanel();
|
||||
this.buttonDeepL = new System.Windows.Forms.Button();
|
||||
this.checkBoxManual = new System.Windows.Forms.CheckBox();
|
||||
this.toolTip = new System.Windows.Forms.ToolTip(this.components);
|
||||
this.tableLayout.SuspendLayout();
|
||||
this.flowLayoutHeaderTools.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// tableLayout
|
||||
@@ -44,7 +47,7 @@
|
||||
this.tableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
|
||||
this.tableLayout.Controls.Add(this.labelHead, 0, 0);
|
||||
this.tableLayout.Controls.Add(this.textBox, 0, 1);
|
||||
this.tableLayout.Controls.Add(this.buttonDeepL, 1, 0);
|
||||
this.tableLayout.Controls.Add(this.flowLayoutHeaderTools, 1, 0);
|
||||
this.tableLayout.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.tableLayout.Location = new System.Drawing.Point(0, 0);
|
||||
this.tableLayout.Name = "tableLayout";
|
||||
@@ -76,6 +79,18 @@
|
||||
this.textBox.TabIndex = 1;
|
||||
this.textBox.TextChanged += new System.EventHandler(this.textBox_TextChanged);
|
||||
//
|
||||
// flowLayoutHeaderTools
|
||||
//
|
||||
this.flowLayoutHeaderTools.Controls.Add(this.buttonDeepL);
|
||||
this.flowLayoutHeaderTools.Controls.Add(this.checkBoxManual);
|
||||
this.flowLayoutHeaderTools.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.flowLayoutHeaderTools.FlowDirection = System.Windows.Forms.FlowDirection.RightToLeft;
|
||||
this.flowLayoutHeaderTools.Location = new System.Drawing.Point(366, 0);
|
||||
this.flowLayoutHeaderTools.Margin = new System.Windows.Forms.Padding(0);
|
||||
this.flowLayoutHeaderTools.Name = "flowLayoutHeaderTools";
|
||||
this.flowLayoutHeaderTools.Size = new System.Drawing.Size(454, 66);
|
||||
this.flowLayoutHeaderTools.TabIndex = 3;
|
||||
//
|
||||
// buttonDeepL
|
||||
//
|
||||
this.buttonDeepL.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
@@ -83,7 +98,7 @@
|
||||
this.buttonDeepL.FlatAppearance.BorderSize = 0;
|
||||
this.buttonDeepL.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
this.buttonDeepL.Image = global::UI_WinForms.Resources.Icons.icons8_bot_512;
|
||||
this.buttonDeepL.Location = new System.Drawing.Point(757, 3);
|
||||
this.buttonDeepL.Location = new System.Drawing.Point(391, 3);
|
||||
this.buttonDeepL.Name = "buttonDeepL";
|
||||
this.buttonDeepL.Size = new System.Drawing.Size(60, 60);
|
||||
this.buttonDeepL.TabIndex = 2;
|
||||
@@ -91,6 +106,19 @@
|
||||
this.buttonDeepL.UseVisualStyleBackColor = true;
|
||||
this.buttonDeepL.Click += new System.EventHandler(this.buttonDeepL_Click);
|
||||
//
|
||||
// checkBoxManual
|
||||
//
|
||||
this.checkBoxManual.AutoSize = true;
|
||||
this.checkBoxManual.Location = new System.Drawing.Point(188, 3);
|
||||
this.checkBoxManual.Name = "checkBoxManual";
|
||||
this.checkBoxManual.Padding = new System.Windows.Forms.Padding(0, 14, 0, 14);
|
||||
this.checkBoxManual.Size = new System.Drawing.Size(197, 60);
|
||||
this.checkBoxManual.TabIndex = 0;
|
||||
this.checkBoxManual.Text = "Manual translation";
|
||||
this.toolTip.SetToolTip(this.checkBoxManual, "Never overwrites this translation automatically");
|
||||
this.checkBoxManual.UseVisualStyleBackColor = true;
|
||||
this.checkBoxManual.CheckedChanged += new System.EventHandler(this.checkBoxManual_CheckedChanged);
|
||||
//
|
||||
// toolTip
|
||||
//
|
||||
this.toolTip.AutoPopDelay = 30000;
|
||||
@@ -109,6 +137,8 @@
|
||||
this.Size = new System.Drawing.Size(820, 279);
|
||||
this.tableLayout.ResumeLayout(false);
|
||||
this.tableLayout.PerformLayout();
|
||||
this.flowLayoutHeaderTools.ResumeLayout(false);
|
||||
this.flowLayoutHeaderTools.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
@@ -120,5 +150,7 @@
|
||||
private TextBox textBox;
|
||||
private Button buttonDeepL;
|
||||
private ToolTip toolTip;
|
||||
private FlowLayoutPanel flowLayoutHeaderTools;
|
||||
private CheckBox checkBoxManual;
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ public sealed partial class Translation : UserControl
|
||||
private bool isLoading = false;
|
||||
private int currentTranslationId = -1;
|
||||
private bool isDeepLSourceCulture = false;
|
||||
private bool isManualOnlyMode = false;
|
||||
private Translation? mainCultureTranslation = null;
|
||||
|
||||
public Translation()
|
||||
@@ -50,6 +51,7 @@ public sealed partial class Translation : UserControl
|
||||
{
|
||||
this.isDeepLSourceCulture = await AppSettings.GetDeepLSourceCultureIndex() == cultureInfo.Index;
|
||||
this.textBox.ReadOnly = !(this.isDeepLSourceCulture || await AppSettings.GetDeepLAction() == SettingDeepLAction.MANUAL);
|
||||
this.checkBoxManual.Visible = !this.isDeepLSourceCulture;
|
||||
this.buttonDeepL.Visible = await AppSettings.GetDeepLMode() != SettingDeepLMode.DISABLED;
|
||||
this.buttonDeepL.Image = this.isDeepLSourceCulture ? Icons.icons8_trigger_1__svg : Icons.deepl_logo_icon_170284;
|
||||
|
||||
@@ -66,9 +68,21 @@ public sealed partial class Translation : UserControl
|
||||
{
|
||||
this.isLoading = true;
|
||||
|
||||
this.isManualOnlyMode = this.checkBoxManual.Checked = translation.TranslateManual;
|
||||
this.currentTranslationId = translation.Id;
|
||||
this.textBox.Text = translation.Text;
|
||||
this.textBox.Multiline = translation.TextElement.IsMultiLine;
|
||||
|
||||
try
|
||||
{
|
||||
this.textBox.Text = translation.Text;
|
||||
this.textBox.Multiline = translation.TextElement.IsMultiLine;
|
||||
this.textBox.ReadOnly = !(this.isDeepLSourceCulture || await AppSettings.GetDeepLAction() == SettingDeepLAction.MANUAL);
|
||||
if (this.isManualOnlyMode)
|
||||
this.textBox.ReadOnly = false;
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
}
|
||||
|
||||
this.Height = translation.TextElement.IsMultiLine ? 280 : 106;
|
||||
this.buttonDeepL.Visible = await AppSettings.GetDeepLMode() != SettingDeepLMode.DISABLED;
|
||||
|
||||
@@ -110,10 +124,12 @@ public sealed partial class Translation : UserControl
|
||||
private async void SaveChanges(object? sender, ElapsedEventArgs e)
|
||||
{
|
||||
if (this.currentTranslationId > -1)
|
||||
await TranslationProcessor.SaveChangedTranslation(this.currentTranslationId, this.textBox.Text);
|
||||
await TranslationProcessor.SaveChangedTranslation(this.currentTranslationId, this.textBox.Text, this.checkBoxManual.Checked);
|
||||
|
||||
if(this.ParentForm is UI_WinForms.Main main)
|
||||
main.RemoveDeferredSaveOperation(this.currentTranslationId);
|
||||
|
||||
this.isManualOnlyMode = this.checkBoxManual.Checked;
|
||||
}
|
||||
|
||||
private async void TriggerTranslateNow(object? sender, ElapsedEventArgs e)
|
||||
@@ -129,11 +145,14 @@ public sealed partial class Translation : UserControl
|
||||
|
||||
internal string GetCurrentText() => this.textBox.Text;
|
||||
|
||||
internal async Task Translate()
|
||||
internal async Task Translate(bool wasManualTriggered = false)
|
||||
{
|
||||
if (this.mainCultureTranslation is null)
|
||||
return;
|
||||
|
||||
if(this.isManualOnlyMode && !wasManualTriggered)
|
||||
return;
|
||||
|
||||
var text = await Processor.DeepL.Translate(this.mainCultureTranslation.GetCurrentText(), this.culture);
|
||||
if (this.textBox.InvokeRequired)
|
||||
this.textBox.Invoke(() => this.textBox.Text = text);
|
||||
@@ -146,6 +165,17 @@ public sealed partial class Translation : UserControl
|
||||
if (this.isDeepLSourceCulture)
|
||||
this.TriggerTranslateNow(null, null);
|
||||
else
|
||||
await this.Translate();
|
||||
await this.Translate(wasManualTriggered: true);
|
||||
}
|
||||
|
||||
private async void checkBoxManual_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
if(this.isLoading)
|
||||
return;
|
||||
|
||||
this.SaveChanges(null, null);
|
||||
this.textBox.ReadOnly = !(this.isDeepLSourceCulture || await AppSettings.GetDeepLAction() == SettingDeepLAction.MANUAL);
|
||||
if (this.isManualOnlyMode)
|
||||
this.textBox.ReadOnly = false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user