Resolve "Component: Translation" #73

Merged
thorsten merged 23 commits from 12-component-translation into main 2022-09-21 20:53:39 +00:00
3 changed files with 36 additions and 6 deletions
Showing only changes of commit 24a7093674 - Show all commits

View File

@ -50,12 +50,6 @@ 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);
}
public async Task Configure(DataModel.Database.Translation translation)
{
this.isLoading = true;
@ -78,5 +72,16 @@ public sealed partial class Translation : UserControl
this.saveTimer.Stop();
this.saveTimer.Start();
if(this.ParentForm is UI_WinForms.Main main)
main.AddDeferredSaveOperation(this.currentTranslationId, () => this.SaveChanges(null, null));
}
private async void SaveChanges(object? sender, ElapsedEventArgs e)
{
if (this.currentTranslationId > -1)
await TranslationProcessor.SaveChangedTranslation(this.currentTranslationId, this.textBox.Text);
if(this.ParentForm is UI_WinForms.Main main)
main.RemoveDeferredSaveOperation(this.currentTranslationId);
}
}

View File

@ -52,6 +52,7 @@
this.Name = "Main";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "I18N Commander";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Main_FormClosing);
this.ResumeLayout(false);
}

View File

@ -2,8 +2,32 @@ namespace UI_WinForms;
public partial class Main : Form
{
private readonly Dictionary<int, Action> deferredSaveOperations = new();
public Main()
{
this.InitializeComponent();
}
private void Main_FormClosing(object sender, FormClosingEventArgs e)
{
foreach (var (_, action) in this.deferredSaveOperations)
action();
this.deferredSaveOperations.Clear();
}
internal void AddDeferredSaveOperation(int id, Action action)
{
if (this.deferredSaveOperations.ContainsKey(id))
this.deferredSaveOperations.Remove(id);
this.deferredSaveOperations.Add(id, action);
}
internal void RemoveDeferredSaveOperation(int id)
{
if (this.deferredSaveOperations.ContainsKey(id))
this.deferredSaveOperations.Remove(id);
}
}