Add enter key support to SetupWizards, ensure esc works with Focus()

- Issue MatterHackers/MCCentral#5109
Enter/esc keys have no effect in WizardPages
This commit is contained in:
jlewin 2019-03-01 17:43:04 -08:00
parent 1609aaca6b
commit 64090ab10c
2 changed files with 21 additions and 1 deletions

View file

@ -203,7 +203,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
"Measure the nozzle offset".Localize(),
"{0}:\n\n\t• {1}\n\n{2}\n\n{3}".FormatWith(
"To complete the next few steps you will need".Localize(),
"A standard sheet of paper".Localize(),
"A sheet of paper".Localize(),
"We will use this paper to measure the distance between the nozzle and the bed.".Localize(),
"Click 'Next' to continue.".Localize()));

View file

@ -93,15 +93,35 @@ namespace MatterHackers.MatterControl
wizardWindow.ChangeToPage(setupWizard.CurrentPage);
// Set focus to ensure Enter/Esc key handlers are caught
setupWizard.CurrentPage.Focus();
EventHandler windowClosed = null;
EventHandler<KeyEventArgs> windowKeyDown = null;
windowClosed = (s, e) =>
{
setupWizard.Dispose();
wizardWindow.Closed -= windowClosed;
wizardWindow.KeyDown -= windowKeyDown;
};
windowKeyDown = (s, e) =>
{
switch (e.KeyCode)
{
// Auto-advance to next page on enter key
case Keys.Enter:
if (setupWizard.CurrentPage.NextButton.Enabled)
{
UiThread.RunOnIdle(() => setupWizard.CurrentPage.NextButton.InvokeClick());
}
break;
}
};
wizardWindow.Closed += windowClosed;
wizardWindow.KeyDown += windowKeyDown;
return wizardWindow;
}