Ensured, that last minute changes are written to disk
This commit is contained in:
parent
97f3226d17
commit
24a7093674
@ -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);
|
||||
}
|
||||
}
|
1
I18N Commander/UI WinForms/Main.Designer.cs
generated
1
I18N Commander/UI WinForms/Main.Designer.cs
generated
@ -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);
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user