diff --git a/AboutPage/CheckForUpdatesPage.cs b/AboutPage/CheckForUpdatesPage.cs index eefb9c3ca..a6d951aea 100644 --- a/AboutPage/CheckForUpdatesPage.cs +++ b/AboutPage/CheckForUpdatesPage.cs @@ -137,8 +137,6 @@ namespace MatterHackers.MatterControl.AboutPage additionalInfoContainer.Visible = false; - cancelButton.Visible = true; - this.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor; } } diff --git a/ConfigurationPage/RunningMacroPage.cs b/ConfigurationPage/RunningMacroPage.cs index 962e8d669..4171613ac 100644 --- a/ConfigurationPage/RunningMacroPage.cs +++ b/ConfigurationPage/RunningMacroPage.cs @@ -57,11 +57,6 @@ namespace MatterHackers.MatterControl.PrinterControls this.WindowTitle = "Running Macro".Localize(); this.HeaderText = macroData.title; - cancelButton.Click += (s, e) => - { - printer.Connection.MacroCancel(); - }; - if (macroData.showMaterialSelector) { int extruderIndex = 0; @@ -122,6 +117,12 @@ namespace MatterHackers.MatterControl.PrinterControls } } + protected override void OnCancel(out bool abortCancel) + { + printer.Connection.MacroCancel(); + abortCancel = false; + } + private EventHandler unregisterEvents; public class MacroCommandData diff --git a/PrinterControls/PrinterConnections/SetupStepComPortManual.cs b/PrinterControls/PrinterConnections/SetupStepComPortManual.cs index a5dd820c6..986d7e162 100644 --- a/PrinterControls/PrinterConnections/SetupStepComPortManual.cs +++ b/PrinterControls/PrinterConnections/SetupStepComPortManual.cs @@ -61,8 +61,6 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections FlowLayoutWidget printerComPortContainer = createComPortContainer(); contentRow.AddChild(printerComPortContainer); - cancelButton.Click += (s, e) => printer.Connection.HaltConnectionThread(); - //Construct buttons nextButton = textImageButtonFactory.Generate("Done".Localize()); nextButton.Click += (s, e) => UiThread.RunOnIdle(Parent.Close); @@ -106,6 +104,12 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections printer.Connection.CommunicationStateChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents); } + protected override void OnCancel(out bool abortCancel) + { + printer.Connection.HaltConnectionThread(); + abortCancel = false; + } + public override void OnClosed(ClosedEventArgs e) { unregisterEvents?.Invoke(this, null); diff --git a/PrinterControls/PrinterConnections/SetupStepComPortTwo.cs b/PrinterControls/PrinterConnections/SetupStepComPortTwo.cs index a133a4410..affe75973 100644 --- a/PrinterControls/PrinterConnections/SetupStepComPortTwo.cs +++ b/PrinterControls/PrinterConnections/SetupStepComPortTwo.cs @@ -41,7 +41,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections public class SetupStepComPortTwo : WizardPage { private string[] startingPortNames; - private string[] currentPortNames; + private Button nextButton; private Button connectButton; private TextWidget printerErrorMessage; @@ -55,40 +55,43 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections startingPortNames = FrostedSerialPort.GetPortNames(); contentRow.AddChild(createPrinterConnectionMessageContainer()); + + //Construct buttons + nextButton = textImageButtonFactory.Generate("Done".Localize()); + nextButton.Click += (s, e) => UiThread.RunOnIdle(Parent.Close); + nextButton.Visible = false; + + connectButton = textImageButtonFactory.Generate("Connect".Localize()); + connectButton.Click += (s, e) => { - cancelButton.Click += (s, e) => printer.Connection.HaltConnectionThread(); - - //Construct buttons - nextButton = textImageButtonFactory.Generate("Done".Localize()); - nextButton.Click += (s, e) => UiThread.RunOnIdle(Parent.Close); - nextButton.Visible = false; - - connectButton = textImageButtonFactory.Generate("Connect".Localize()); - connectButton.Click += (s, e) => + // Select the first port that's in GetPortNames() but not in startingPortNames + string candidatePort = FrostedSerialPort.GetPortNames().Except(startingPortNames).FirstOrDefault(); + if (candidatePort == null) { - // Select the first port that's in GetPortNames() but not in startingPortNames - string candidatePort = FrostedSerialPort.GetPortNames().Except(startingPortNames).FirstOrDefault(); - if (candidatePort == null) - { - printerErrorMessage.TextColor = RGBA_Bytes.Red; - printerErrorMessage.Text = "Oops! Printer could not be detected ".Localize(); - } - else - { - printerErrorMessage.TextColor = ActiveTheme.Instance.PrimaryTextColor; - printerErrorMessage.Text = "Attempting to connect".Localize() + "..."; + printerErrorMessage.TextColor = RGBA_Bytes.Red; + printerErrorMessage.Text = "Oops! Printer could not be detected ".Localize(); + } + else + { + printerErrorMessage.TextColor = ActiveTheme.Instance.PrimaryTextColor; + printerErrorMessage.Text = "Attempting to connect".Localize() + "..."; - ActiveSliceSettings.Instance.Helpers.SetComPort(candidatePort); - printer.Connection.Connect(); - connectButton.Visible = false; - } - }; + ActiveSliceSettings.Instance.Helpers.SetComPort(candidatePort); + printer.Connection.Connect(); + connectButton.Visible = false; + } + }; - printer.Connection.CommunicationStateChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents); + printer.Connection.CommunicationStateChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents); - this.AddPageAction(nextButton); - this.AddPageAction(connectButton); - } + this.AddPageAction(nextButton); + this.AddPageAction(connectButton); + } + + protected override void OnCancel(out bool abortCancel) + { + printer.Connection.HaltConnectionThread(); + abortCancel = false; } public override void OnClosed(ClosedEventArgs e) diff --git a/PrinterControls/PrinterConnections/ShowAuthPanel.cs b/PrinterControls/PrinterConnections/ShowAuthPanel.cs index ab0a7537a..c0e29307c 100644 --- a/PrinterControls/PrinterConnections/ShowAuthPanel.cs +++ b/PrinterControls/PrinterConnections/ShowAuthPanel.cs @@ -27,6 +27,7 @@ of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project. */ +using System; using System.Linq; using MatterHackers.Agg.UI; using MatterHackers.Localizations; @@ -65,19 +66,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections ApplicationSettings.Instance.set(ApplicationSettingsKey.SuppressAuthPanel, rememberChoice.Checked.ToString()); }; - this.cancelButton.Name = "Connection Wizard Skip Sign In Button"; - this.cancelButton.Click += (s, e) => - { - if (!ProfileManager.Instance.ActiveProfiles.Any()) - { - abortCancel = true; - - UiThread.RunOnIdle(() => - { - WizardWindow.ChangeToPage(); - }); - } - }; + this.SetCancelButtonName("Connection Wizard Skip Sign In Button"); var createAccountButton = textImageButtonFactory.Generate("Create Account".Localize()); createAccountButton.Name = "Create Account From Connection Wizard Button"; @@ -106,6 +95,21 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections this.AddPageAction(signInButton); } + protected override void OnCancel(out bool abortCancel) + { + if (!ProfileManager.Instance.ActiveProfiles.Any()) + { + abortCancel = true; + + UiThread.RunOnIdle(() => + { + WizardWindow.ChangeToPage(); + }); + } + + abortCancel = false; + } + private void AddBulletPointAndDescription(FlowLayoutWidget contentRow, string v1, string v2) { contentRow.AddChild(new TextWidget("• " + v1) @@ -121,4 +125,5 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections }); } } -} \ No newline at end of file +} + \ No newline at end of file diff --git a/SetupWizard/AndroidNetworkTroubleshootingPage.cs b/SetupWizard/AndroidNetworkTroubleshootingPage.cs index 859a02a93..5cdda6e8d 100644 --- a/SetupWizard/AndroidNetworkTroubleshootingPage.cs +++ b/SetupWizard/AndroidNetworkTroubleshootingPage.cs @@ -59,8 +59,6 @@ namespace MatterHackers.MatterControl //Add buttons to buttonContainer AddPageAction(configureButton); - - cancelButton.Visible = true; } } } diff --git a/SetupWizard/CopyGuestProfilesToUser.cs b/SetupWizard/CopyGuestProfilesToUser.cs index 5029075d4..c66e8727e 100644 --- a/SetupWizard/CopyGuestProfilesToUser.cs +++ b/SetupWizard/CopyGuestProfilesToUser.cs @@ -27,23 +27,22 @@ of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project. */ -using System; -using MatterHackers.Agg.Platform; +using System.Collections.Generic; +using System.IO; +using MatterHackers.Agg; using MatterHackers.Agg.UI; using MatterHackers.Localizations; -using MatterHackers.MatterControl; -using MatterHackers.Agg; -using System.Collections.Generic; using MatterHackers.MatterControl.SlicerConfiguration; -using System.IO; namespace MatterHackers.MatterControl { public class CopyGuestProfilesToUser : WizardPage { - string importMessage = "It's time to copy your existing printer settings to your MatterHackers account. Once copied, these printers will be available whenever you sign in to MatterControl. Printers that are not copied will only be available when not signed in.".Localize(); + private string importMessage = "It's time to copy your existing printer settings to your MatterHackers account. Once copied, these printers will be available whenever you sign in to MatterControl. Printers that are not copied will only be available when not signed in.".Localize(); - List checkBoxes = new List(); + private CheckBox rememberChoice; + + private List checkBoxes = new List(); public CopyGuestProfilesToUser() : base("Close") @@ -132,24 +131,24 @@ namespace MatterHackers.MatterControl }); }; - CheckBox rememberChoice = new CheckBox("Don't remind me again".Localize(), ActiveTheme.Instance.PrimaryTextColor); + rememberChoice = new CheckBox("Don't remind me again".Localize(), ActiveTheme.Instance.PrimaryTextColor); contentRow.AddChild(rememberChoice); syncButton.Visible = true; - cancelButton.Visible = true; - - // Close the window and update the PrintersImported flag - cancelButton.Click += (s, e) => UiThread.RunOnIdle(() => - { - WizardWindow.Close(); - if (rememberChoice.Checked) - { - ProfileManager.Instance.PrintersImported = true; - ProfileManager.Instance.Save(); - } - }); this.AddPageAction(syncButton); } + + protected override void OnCancel(out bool abortCancel) + { + // If "Don't remind me" checked, update the PrintersImported flag on close + if (rememberChoice.Checked) + { + ProfileManager.Instance.PrintersImported = true; + ProfileManager.Instance.Save(); + } + + abortCancel = false; + } } } \ No newline at end of file diff --git a/SetupWizard/ExportSettingsPage.cs b/SetupWizard/ExportSettingsPage.cs index cd8940650..94a2d8b6e 100644 --- a/SetupWizard/ExportSettingsPage.cs +++ b/SetupWizard/ExportSettingsPage.cs @@ -102,7 +102,6 @@ namespace MatterHackers.MatterControl exportButton.Click += (s, e) => UiThread.RunOnIdle(exportButton_Click); exportButton.Visible = true; - cancelButton.Visible = true; this.AddPageAction(exportButton); } diff --git a/SetupWizard/ImportSettingsPage.cs b/SetupWizard/ImportSettingsPage.cs index 8c7b9453f..feece498a 100644 --- a/SetupWizard/ImportSettingsPage.cs +++ b/SetupWizard/ImportSettingsPage.cs @@ -364,7 +364,6 @@ namespace MatterHackers.MatterControl }); importButton.Visible = true; - cancelButton.Visible = true; this.AddPageAction(importButton); } diff --git a/SetupWizard/LicenseAgreementPage.cs b/SetupWizard/LicenseAgreementPage.cs index 64a2e2274..7e315101d 100644 --- a/SetupWizard/LicenseAgreementPage.cs +++ b/SetupWizard/LicenseAgreementPage.cs @@ -63,11 +63,15 @@ public class LicenseAgreementPage : WizardPage }; acceptButton.Visible = true; - cancelButton.Visible = true; - - // Exit if EULA is not accepted - cancelButton.Click += (s, e) => UiThread.RunOnIdle(MatterControlApplication.Instance.Close); this.AddPageAction(acceptButton); } + + protected override void OnCancel(out bool abortCancel) + { + // Exit if EULA is not accepted + UiThread.RunOnIdle(MatterControlApplication.Instance.Close); + + abortCancel = false; + } } diff --git a/SetupWizard/PublishPartToMatterHackers.cs b/SetupWizard/PublishPartToMatterHackers.cs index 02bffdaf9..7ab07f646 100644 --- a/SetupWizard/PublishPartToMatterHackers.cs +++ b/SetupWizard/PublishPartToMatterHackers.cs @@ -135,7 +135,6 @@ namespace MatterHackers.MatterControl contentRow.AddChild(CreateRequiredCheckBox("", new HtmlWidget(html, textColor))); publishButton.Visible = true; - cancelButton.Visible = true; this.AddPageAction(publishButton); } diff --git a/SetupWizard/SetupWizardTroubleshooting.cs b/SetupWizard/SetupWizardTroubleshooting.cs index 6633143c9..012cd6136 100644 --- a/SetupWizard/SetupWizardTroubleshooting.cs +++ b/SetupWizard/SetupWizardTroubleshooting.cs @@ -44,12 +44,6 @@ namespace MatterHackers.MatterControl RefreshStatus(); - cancelButton.Click += (s, e) => UiThread.RunOnIdle(() => - { - abortCancel = true; - this.WizardWindow.ChangeToPage(); - }); - nextButton = textImageButtonFactory.Generate("Continue".Localize()); nextButton.Click += (sender, e) => UiThread.RunOnIdle(this.WizardWindow.Close); nextButton.Visible = false; @@ -69,6 +63,16 @@ namespace MatterHackers.MatterControl } } + protected override void OnCancel(out bool abortCancel) + { + abortCancel = true; + + UiThread.RunOnIdle(() => + { + this.WizardWindow.ChangeToPage(); + }); + } + public override void OnClosed(ClosedEventArgs e) { if(checkForPermissionTimer != null) diff --git a/SetupWizard/WizardPage.cs b/SetupWizard/WizardPage.cs index a5613f162..8d9590ae8 100644 --- a/SetupWizard/WizardPage.cs +++ b/SetupWizard/WizardPage.cs @@ -43,7 +43,7 @@ namespace MatterHackers.MatterControl private FlowLayoutWidget footerRow; private WrappedTextWidget headerLabel; - protected Button cancelButton { get; } + private Button cancelButton; public Vector2 WindowSize { get; set; } @@ -58,8 +58,6 @@ namespace MatterHackers.MatterControl private GuiWidget mainContainer; - protected bool abortCancel = false; - public WizardPage(string unlocalizedTextForCancelButton = "Cancel") { if (!UserSettings.Instance.IsTouchScreen) @@ -143,11 +141,23 @@ namespace MatterHackers.MatterControl footerRow.AddChild(button); } + protected void SetCancelButtonName(string newName) + { + cancelButton.Name = newName; + } + + protected void HideCancelButton() + { + cancelButton.Visible = false; + } + public override void OnLoad(EventArgs args) { // Add 'Close' event listener after derived types have had a chance to register event listeners cancelButton.Click += (s, e) => { + this.OnCancel(out bool abortCancel); + if (!abortCancel) { UiThread.RunOnIdle(() => WizardWindow?.Close()); @@ -160,6 +170,11 @@ namespace MatterHackers.MatterControl base.OnLoad(args); } + protected virtual void OnCancel(out bool abortCancel) + { + abortCancel = false; + } + public virtual void PageIsBecomingActive() { } diff --git a/Tests/MatterControl.AutomationTests/LibraryActionTests.cs b/Tests/MatterControl.AutomationTests/LibraryActionTests.cs index c8ed9c0e0..7021a24df 100644 --- a/Tests/MatterControl.AutomationTests/LibraryActionTests.cs +++ b/Tests/MatterControl.AutomationTests/LibraryActionTests.cs @@ -152,11 +152,9 @@ namespace MatterHackers.MatterControl.Tests.Automation { testRunner.CloseSignInAndPrinterSelect(); - SystemWindow systemWindow; - testRunner.ClickByName("Queue... Menu"); - var exportButton = testRunner.GetWidgetByName(" Export to Zip Menu Item", out systemWindow, 5); + var exportButton = testRunner.GetWidgetByName(" Export to Zip Menu Item", out _, 5); Assert.IsNotNull(exportButton, "Export button should exist"); Assert.IsTrue(exportButton.Enabled, "Export button should be enabled");