From 5ced6c3107d7f6d3c76b86e9685a97f55bb36a3c Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sat, 17 Sep 2022 21:48:13 +0200 Subject: [PATCH] Defined a component for any single translation --- .../Components/Translation.Designer.cs | 123 ++++++++++++++++++ .../UI WinForms/Components/Translation.cs | 55 ++++++++ .../UI WinForms/Components/Translation.resx | 63 +++++++++ 3 files changed, 241 insertions(+) create mode 100644 I18N Commander/UI WinForms/Components/Translation.Designer.cs create mode 100644 I18N Commander/UI WinForms/Components/Translation.cs create mode 100644 I18N Commander/UI WinForms/Components/Translation.resx diff --git a/I18N Commander/UI WinForms/Components/Translation.Designer.cs b/I18N Commander/UI WinForms/Components/Translation.Designer.cs new file mode 100644 index 0000000..f5878d2 --- /dev/null +++ b/I18N Commander/UI WinForms/Components/Translation.Designer.cs @@ -0,0 +1,123 @@ +namespace UI_WinForms.Components +{ + sealed partial class Translation + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.tableLayout = new System.Windows.Forms.TableLayoutPanel(); + this.labelHead = new System.Windows.Forms.Label(); + this.textBox = new System.Windows.Forms.TextBox(); + this.buttonDeepL = new System.Windows.Forms.Button(); + this.toolTip = new System.Windows.Forms.ToolTip(this.components); + this.tableLayout.SuspendLayout(); + this.SuspendLayout(); + // + // tableLayout + // + this.tableLayout.ColumnCount = 2; + this.tableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 366F)); + 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.Dock = System.Windows.Forms.DockStyle.Fill; + this.tableLayout.Location = new System.Drawing.Point(0, 0); + this.tableLayout.Name = "tableLayout"; + this.tableLayout.RowCount = 2; + this.tableLayout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 66F)); + this.tableLayout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayout.Size = new System.Drawing.Size(820, 279); + this.tableLayout.TabIndex = 0; + // + // labelHead + // + this.labelHead.Dock = System.Windows.Forms.DockStyle.Fill; + this.labelHead.Location = new System.Drawing.Point(3, 0); + this.labelHead.Name = "labelHead"; + this.labelHead.Size = new System.Drawing.Size(360, 66); + this.labelHead.TabIndex = 0; + this.labelHead.Text = "header"; + this.labelHead.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // textBox + // + this.tableLayout.SetColumnSpan(this.textBox, 2); + this.textBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.textBox.Location = new System.Drawing.Point(3, 69); + this.textBox.Multiline = true; + this.textBox.Name = "textBox"; + this.textBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; + this.textBox.Size = new System.Drawing.Size(814, 207); + this.textBox.TabIndex = 1; + this.textBox.TextChanged += new System.EventHandler(this.textBox_TextChanged); + // + // buttonDeepL + // + this.buttonDeepL.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDeepL.AutoSize = true; + 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.Name = "buttonDeepL"; + this.buttonDeepL.Size = new System.Drawing.Size(60, 60); + this.buttonDeepL.TabIndex = 2; + this.toolTip.SetToolTip(this.buttonDeepL, "Auto-generate this text by using DeepL"); + this.buttonDeepL.UseVisualStyleBackColor = true; + // + // toolTip + // + this.toolTip.AutoPopDelay = 30000; + this.toolTip.InitialDelay = 500; + this.toolTip.ReshowDelay = 100; + this.toolTip.ToolTipIcon = System.Windows.Forms.ToolTipIcon.Info; + this.toolTip.ToolTipTitle = "Help"; + // + // Translation + // + this.AutoScaleDimensions = new System.Drawing.SizeF(120F, 120F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; + this.Controls.Add(this.tableLayout); + this.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.Name = "Translation"; + this.Size = new System.Drawing.Size(820, 279); + this.tableLayout.ResumeLayout(false); + this.tableLayout.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private TableLayoutPanel tableLayout; + private Label labelHead; + private TextBox textBox; + private Button buttonDeepL; + private ToolTip toolTip; + } +} diff --git a/I18N Commander/UI WinForms/Components/Translation.cs b/I18N Commander/UI WinForms/Components/Translation.cs new file mode 100644 index 0000000..e1f009c --- /dev/null +++ b/I18N Commander/UI WinForms/Components/Translation.cs @@ -0,0 +1,55 @@ +using System.Timers; +using Processor; +using Timer = System.Timers.Timer; + +namespace UI_WinForms.Components; + +public sealed partial class Translation : UserControl +{ + private readonly string culture = "en-US"; + private readonly Timer saveTimer; + + private int currentTranslationId = -1; + + public Translation() + { + this.InitializeComponent(); + this.Dock = DockStyle.Top; + } + + public Translation(string cultureCode) + { + this.InitializeComponent(); + this.culture = cultureCode; + this.labelHead.Text = $"Culture: {cultureCode}"; + this.Dock = DockStyle.Top; + this.saveTimer = new Timer + { + Enabled = false, // disable timer for now, + Interval = 1_000, // 1 second + AutoReset = false, // runs only once + }; + this.saveTimer.Elapsed += this.SaveChanges; + } + + private async void SaveChanges(object? sender, ElapsedEventArgs e) + { + if (this.currentTranslationId > -1) + await TranslationProcessor.SaveChangedTranslation(this.currentTranslationId, this.textBox.Text); + } + + public void Configure(DataModel.Database.Translation translation) + { + this.currentTranslationId = translation.Id; + this.textBox.Multiline = translation.TextElement.IsMultiLine; + this.textBox.Text = translation.Text; + } + + private async void textBox_TextChanged(object sender, EventArgs e) + { + if(this.saveTimer.Enabled) + this.saveTimer.Stop(); + + this.saveTimer.Start(); + } +} \ No newline at end of file diff --git a/I18N Commander/UI WinForms/Components/Translation.resx b/I18N Commander/UI WinForms/Components/Translation.resx new file mode 100644 index 0000000..99de901 --- /dev/null +++ b/I18N Commander/UI WinForms/Components/Translation.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file