Implemented automatic generators
This commit is contained in:
parent
274d3641eb
commit
c48466d91e
@ -3,12 +3,14 @@ using Processor;
|
|||||||
using Processor.Generators;
|
using Processor.Generators;
|
||||||
using UI_WinForms.Dialogs;
|
using UI_WinForms.Dialogs;
|
||||||
using UI_WinForms.Resources;
|
using UI_WinForms.Resources;
|
||||||
|
using Timer = System.Timers.Timer;
|
||||||
|
|
||||||
namespace UI_WinForms.Components;
|
namespace UI_WinForms.Components;
|
||||||
|
|
||||||
public partial class SectionTree : UserControl
|
public partial class SectionTree : UserControl
|
||||||
{
|
{
|
||||||
private static readonly Dictionary<TreeNode, EventHandler<DataModel.Database.Translation?>> NODE_PROGRESS_HANDLERS = new();
|
private static readonly Dictionary<TreeNode, EventHandler<DataModel.Database.Translation?>?> NODE_PROGRESS_HANDLERS = new();
|
||||||
|
private readonly Timer generatorTimer;
|
||||||
|
|
||||||
public SectionTree()
|
public SectionTree()
|
||||||
{
|
{
|
||||||
@ -27,9 +29,23 @@ public partial class SectionTree : UserControl
|
|||||||
// Set the image list to the tree view:
|
// Set the image list to the tree view:
|
||||||
this.treeView.ImageList = imgList;
|
this.treeView.ImageList = imgList;
|
||||||
|
|
||||||
|
// The generator timer:
|
||||||
|
this.generatorTimer = new Timer
|
||||||
|
{
|
||||||
|
Enabled = false, // disable timer for now,
|
||||||
|
Interval = 6_000, // 6 second interval,
|
||||||
|
AutoReset = false, // runs only once
|
||||||
|
};
|
||||||
|
|
||||||
|
this.generatorTimer.Elapsed += async (sender, args) => await this.PerformGenerators();
|
||||||
|
|
||||||
// Subscribe to the load event:
|
// Subscribe to the load event:
|
||||||
this.Load += this.LoadNodes;
|
this.Load += this.LoadNodes;
|
||||||
this.Load += (sender, args) => this.SetupGeneratorButton();
|
this.Load += (sender, args) => this.SetupGeneratorButton();
|
||||||
|
|
||||||
|
// Subscribe to all event for triggering the generators:
|
||||||
|
AppEvents.WhenTranslationChanged += (sender, translation) => this.GeneratorEvent();
|
||||||
|
AppEvents.WhenSettingsChanged += (sender, args) => this.GeneratorEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void SetupGeneratorButton()
|
private async void SetupGeneratorButton()
|
||||||
@ -294,8 +310,26 @@ public partial class SectionTree : UserControl
|
|||||||
selectedNode.Name = alteredSection.Result.DataKey; // [sic] name is the key
|
selectedNode.Name = alteredSection.Result.DataKey; // [sic] name is the key
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void buttonGenerate_Click(object sender, EventArgs e)
|
private async void buttonGenerate_Click(object sender, EventArgs e) => await this.PerformGenerators();
|
||||||
|
|
||||||
|
private async void GeneratorEvent()
|
||||||
{
|
{
|
||||||
|
if(await AppSettings.GetGeneratorMode() == SettingGeneratorMode.MANUAL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (this.generatorTimer.Enabled)
|
||||||
|
this.generatorTimer.Stop();
|
||||||
|
this.generatorTimer.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task PerformGenerators()
|
||||||
|
{
|
||||||
|
if (this.buttonGenerate.InvokeRequired)
|
||||||
|
{
|
||||||
|
await this.buttonGenerate.Invoke(this.PerformGenerators);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.buttonGenerate.Enabled = false;
|
this.buttonGenerate.Enabled = false;
|
||||||
await Generator.TriggerAllAsync();
|
await Generator.TriggerAllAsync();
|
||||||
this.buttonGenerate.Enabled = true;
|
this.buttonGenerate.Enabled = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user