Add abort calibration confirmation via DialogWindow OnClosing

This commit is contained in:
jlewin 2019-05-09 13:28:37 -07:00
parent 2d3f71ba28
commit f2bf0c5005

View file

@ -32,6 +32,7 @@ using System.Collections.Generic;
using System.Linq;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
namespace MatterHackers.MatterControl
{
@ -46,6 +47,7 @@ namespace MatterHackers.MatterControl
private Dictionary<ISetupWizard, WizardStageRow> rowsByStage = new Dictionary<ISetupWizard, WizardStageRow>();
private IStagedSetupWizard setupWizard;
private bool closeConfirmed;
public ISetupWizard ActiveStage
{
@ -147,6 +149,24 @@ namespace MatterHackers.MatterControl
this.AddChild(row);
}
public override void OnClosing(ClosingEventArgs eventArgs)
{
if (this.ActiveStage != null
&& !closeConfirmed)
{
// We need to show an interactive dialog to determine if the original Close request should be honored, thus cancel the current Close request
eventArgs.Cancel = true;
ConditionalAbort("Are you sure you want to abort calibration?".Localize(), () =>
{
closeConfirmed = true;
this.CloseOnIdle();
});
}
base.OnClosing(eventArgs);
}
private void ConditionalAbort(string message, Action exitConfirmedAction)
{
UiThread.RunOnIdle(() =>