Add mechanism to DialogPage to start and show SetupWizards

- Remove special behavior in each SetupWizard for showing Dialogs
- Move initialization code in old Start method into constructors
This commit is contained in:
John Lewin 2019-02-16 13:55:27 -08:00 committed by jlewin
parent 843b353bbb
commit bae0bf9020
10 changed files with 63 additions and 76 deletions

View file

@ -65,24 +65,20 @@ namespace MatterHackers.MatterControl.ActionBar
var loadButton = theme.CreateDialogButton("Load".Localize());
loadButton.ToolTipText = "Load filament".Localize();
loadButton.Name = "Load Filament Button";
loadButton.Click += (s, e) =>
loadButton.Click += (s, e) =>UiThread.RunOnIdle(() =>
{
UiThread.RunOnIdle(() =>
{
LoadFilamentWizard.Start(printer, theme, extruderIndex, false);
});
};
DialogWindow.Show(
new LoadFilamentWizard(printer, extruderIndex, showAlreadyLoadedButton: false));
});
loadUnloadButtonRow.AddChild(loadButton);
var unloadButton = theme.CreateDialogButton("Unload".Localize());
unloadButton.ToolTipText = "Unload filament".Localize();
unloadButton.Click += (s, e) =>
unloadButton.Click += (s, e) => UiThread.RunOnIdle(() =>
{
UiThread.RunOnIdle(() =>
{
UnloadFilamentWizard.Start(printer, theme, extruderIndex);
});
};
DialogWindow.Show(new UnloadFilamentWizard(printer, extruderIndex));
});
loadUnloadButtonRow.AddChild(unloadButton);
this.AddChild(new SettingsItem("Filament".Localize(), loadUnloadButtonRow, theme, enforceGutter: false));

View file

@ -1630,7 +1630,7 @@ namespace MatterHackers.MatterControl
{
UiThread.RunOnIdle(() =>
{
ProbeCalibrationWizard.Start(printer, theme);
DialogWindow.Show(new ProbeCalibrationWizard(printer));
});
return true;
}
@ -1640,7 +1640,7 @@ namespace MatterHackers.MatterControl
{
UiThread.RunOnIdle(() =>
{
PrintLevelingWizard.Start(printer, theme);
DialogWindow.Show(new PrintLevelingWizard(printer));
});
return true;
}
@ -1650,7 +1650,8 @@ namespace MatterHackers.MatterControl
{
UiThread.RunOnIdle(() =>
{
LoadFilamentWizard.Start(printer, theme, 0, true);
DialogWindow.Show(
new LoadFilamentWizard(printer, extruderIndex: 0, showAlreadyLoadedButton: true));
});
return true;
}
@ -1660,7 +1661,8 @@ namespace MatterHackers.MatterControl
{
UiThread.RunOnIdle(() =>
{
LoadFilamentWizard.Start(printer, theme, 1, true);
DialogWindow.Show(
new LoadFilamentWizard(printer, extruderIndex: 1, showAlreadyLoadedButton: true));
});
return true;
}

View file

@ -53,18 +53,12 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
this.showAlreadyLoadedButton = showAlreadyLoadedButton;
this.WindowTitle = $"{ApplicationController.Instance.ProductName} - " + "Load Filament Wizard".Localize();
// Initialize - store startup temp and extruder index
this.TemperatureAtStart = printer.Connection.GetTargetHotendTemperature(extruderIndex);
this.extruderIndex = extruderIndex;
pages = this.GetPages();
pages.MoveNext();
TemperatureAtStart = printer.Connection.GetTargetHotendTemperature(extruderIndex);
this.extruderIndex = extruderIndex;
}
public static void Start(PrinterConfig printer, ThemeConfig theme, int extruderIndex, bool showAlreadyLoadedButton)
{
var loadFilamentWizard = new LoadFilamentWizard(printer, extruderIndex, showAlreadyLoadedButton);
DialogWindow.Show(loadFilamentWizard.CurrentPage);
}
public override void Dispose()
@ -392,7 +386,9 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
loadFilament2Button.Click += (s, e) =>
{
loadFilament2Button.Parents<SystemWindow>().First().Close();
LoadFilamentWizard.Start(printer, theme, 1, true);
DialogWindow.Show(
new LoadFilamentWizard(printer, extruderIndex: 1, showAlreadyLoadedButton: true));
};
theme.ApplyPrimaryActionStyle(loadFilament2Button);

View file

@ -53,13 +53,6 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
return UsingZProbe(printer) && !printer.Settings.GetValue<bool>(SettingsKey.probe_has_been_calibrated);
}
public static void Start(PrinterConfig printer, ThemeConfig theme)
{
var nozzleWizard = new NozzleCalibrationWizard(printer);
DialogWindow.Show(nozzleWizard.CurrentPage);
}
public override void Dispose()
{
}

View file

@ -41,19 +41,18 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
private LevelingPlan levelingPlan;
public PrintLevelingWizard(LevelingPlan levelingPlan, PrinterConfig printer)
public PrintLevelingWizard(PrinterConfig printer)
: base(printer)
{
this.levelingPlan = levelingPlan;
this.WindowTitle = string.Format("{0} - {1}", ApplicationController.Instance.ProductName, "Print Leveling Wizard".Localize());
this.Initialize();
pages = this.GetPages();
pages.MoveNext();
}
public bool WindowHasBeenClosed { get; private set; }
public static void Start(PrinterConfig printer, ThemeConfig theme)
private void Initialize()
{
// turn off print leveling
printer.Connection.AllowLeveling = false;
@ -69,8 +68,6 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
printer.Connection.QueueLine("T0");
LevelingPlan levelingPlan;
switch (levelingData.LevelingSystem)
{
case LevelingSystem.Probe3Points:
@ -108,12 +105,10 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
default:
throw new NotImplementedException();
}
var levelingWizard = new PrintLevelingWizard(levelingPlan, printer);
DialogWindow.Show(levelingWizard.CurrentPage);
}
public bool WindowHasBeenClosed { get; private set; }
public override void Dispose()
{
// If leveling was on when we started, make sure it is on when we are done.

View file

@ -43,6 +43,9 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
this.WindowTitle = $"{ApplicationController.Instance.ProductName} - " + "Probe Calibration Wizard".Localize();
// Initialize - turn off print leveling
printer.Connection.AllowLeveling = false;
pages = this.GetPages();
pages.MoveNext();
}
@ -53,16 +56,6 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
return UsingZProbe(printer) && !printer.Settings.GetValue<bool>(SettingsKey.probe_has_been_calibrated);
}
public static void Start(PrinterConfig printer, ThemeConfig theme)
{
// turn off print leveling
printer.Connection.AllowLeveling = false;
var probeWizard = new ProbeCalibrationWizard(printer);
DialogWindow.Show(probeWizard.CurrentPage);
}
public override void Dispose()
{
// If leveling was on when we started, make sure it is on when we are done.

View file

@ -48,19 +48,10 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
: base(printer)
{
this.WindowTitle = $"{ApplicationController.Instance.ProductName} - " + "Unload Filament Wizard".Localize();
this.extruderIndex = extruderIndex;
pages = this.GetPages();
pages.MoveNext();
this.extruderIndex = extruderIndex;
}
public static void Start(PrinterConfig printer, ThemeConfig theme, int extruderIndex)
{
// turn off print leveling
var unloadWizard = new UnloadFilamentWizard(printer, extruderIndex);
DialogWindow.Show(unloadWizard.CurrentPage);
}
public override void Dispose()
@ -239,7 +230,9 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
loadFilamentButton.Click += (s, e) =>
{
loadFilamentButton.Parents<SystemWindow>().First().Close();
LoadFilamentWizard.Start(printer, theme, extruderIndex, false);
DialogWindow.Show(
new LoadFilamentWizard(printer, extruderIndex, showAlreadyLoadedButton: false));
};
theme.ApplyPrimaryActionStyle(loadFilamentButton);

View file

@ -267,14 +267,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
Margin = new BorderDouble(10, 10, 0, 15)
};
unloadFilamentButton.Click += (s, e2) =>
unloadFilamentButton.Click += (s, e2) => UiThread.RunOnIdle(() =>
{
UiThread.RunOnIdle(() =>
{
unloadFilamentButton.Parents<SystemWindow>().First().Close();
UnloadFilamentWizard.Start(printer, theme, 0);
});
};
unloadFilamentButton.Parents<SystemWindow>().First().Close();
DialogWindow.Show(new UnloadFilamentWizard(printer, extruderIndex: 0));
});
theme.ApplyPrimaryActionStyle(unloadFilamentButton);

View file

@ -72,7 +72,7 @@ namespace MatterHackers.MatterControl.PrinterControls
{
UiThread.RunOnIdle(() =>
{
PrintLevelingWizard.Start(printer, theme);
DialogWindow.Show(new PrintLevelingWizard(printer));
});
};
settingsRow.AddChild(runWizardButton);
@ -117,7 +117,7 @@ namespace MatterHackers.MatterControl.PrinterControls
};
runCalibrateProbeButton.Click += (s, e) => UiThread.RunOnIdle(() =>
{
ProbeCalibrationWizard.Start(printer, theme);
DialogWindow.Show(new ProbeCalibrationWizard(printer));
});
settingsRow.BorderColor = Color.Transparent;
@ -141,7 +141,7 @@ namespace MatterHackers.MatterControl.PrinterControls
calibrateButton.Click += (s, e) => UiThread.RunOnIdle(() =>
{
NozzleCalibrationWizard.Start(printer, theme);
DialogWindow.Show(new NozzleCalibrationWizard(printer));
});
settingsRow.BorderColor = Color.Transparent;

View file

@ -84,6 +84,28 @@ namespace MatterHackers.MatterControl
return wizardWindow;
}
public static DialogWindow Show(ISetupWizard setupWizard)
{
DialogWindow wizardWindow = GetWindow(setupWizard.GetType());
wizardWindow.Title = setupWizard.WindowTitle;
SetSizeAndShow(wizardWindow, setupWizard.CurrentPage);
wizardWindow.ChangeToPage(setupWizard.CurrentPage);
EventHandler windowClosed = null;
windowClosed = (s, e) =>
{
setupWizard.Dispose();
wizardWindow.Closed -= windowClosed;
};
wizardWindow.Closed += windowClosed;
return wizardWindow;
}
// Allow the WizardPage MinimumSize to override our MinimumSize
public override Vector2 MinimumSize
{