Extract AllowCancel

This commit is contained in:
jlewin 2019-05-09 13:21:17 -07:00
parent a7a53c6712
commit 2d3f71ba28

View file

@ -186,11 +186,7 @@ namespace MatterHackers.MatterControl
// Add 'Close' event listener after derived types have had a chance to register event listeners
cancelButton.Click += (s, e) =>
{
this.OnCancel(out bool pageAbortCancel);
this.DialogWindow.OnCancel(out bool windowAbortCancel);
if (!pageAbortCancel
&& !windowAbortCancel)
if (this.AllowCancel())
{
this.DialogWindow?.ClosePage();
}
@ -205,6 +201,22 @@ namespace MatterHackers.MatterControl
base.OnLoad(args);
}
public bool AllowCancel()
{
bool windowAbortCancel = false;
this.OnCancel(out bool pageAbortCancel);
if (!pageAbortCancel)
{
this.DialogWindow.OnCancel(out windowAbortCancel);
}
// Allow cancel if page and DialogWindow do not abort
return !pageAbortCancel
&& !windowAbortCancel;
}
protected virtual void OnCancel(out bool abortCancel)
{
abortCancel = false;