diff --git a/PrinterControls/PrinterConnections/AddConnectionWidget.cs b/PrinterControls/PrinterConnections/AddConnectionWidget.cs index e0a1b858a..a5f1236f1 100644 --- a/PrinterControls/PrinterConnections/AddConnectionWidget.cs +++ b/PrinterControls/PrinterConnections/AddConnectionWidget.cs @@ -31,7 +31,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections bool addNewPrinterFlag = false; - public EditConnectionWidget(ConnectionWindow windowController, GuiWidget containerWindowToClose, Printer activePrinter = null) + public EditConnectionWidget(ConnectionWindow windowController, GuiWidget containerWindowToClose, Printer activePrinter = null, object state = null) : base(windowController, containerWindowToClose) { textImageButtonFactory.normalTextColor = ActiveTheme.Instance.PrimaryTextColor; @@ -202,6 +202,11 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections enableAutoconnect.Checked = true; } + if (state as StateBeforeRefresh != null) + { + enableAutoconnect.Checked = ((StateBeforeRefresh)state).autoConnect; + } + ConnectionControlContainer.VAnchor = VAnchor.ParentBottomTop; ConnectionControlContainer.AddChild(printerNameLabel); ConnectionControlContainer.AddChild(printerNameInput); @@ -390,6 +395,16 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections return comPortOption; } + internal class StateBeforeRefresh + { + internal bool autoConnect; + + internal StateBeforeRefresh(bool autoConnect) + { + this.autoConnect = autoConnect; + } + } + void RefreshComPorts(object sender, MouseEventArgs mouseEvent) { try @@ -402,7 +417,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections { } - this.windowController.ChangedToEditPrinter(this.ActivePrinter); + this.windowController.ChangedToEditPrinter(this.ActivePrinter, new StateBeforeRefresh(enableAutoconnect.Checked)); } void ReloadCurrentWidget(object sender, MouseEventArgs mouseEvent) diff --git a/PrinterControls/PrinterConnections/ConnectionWindow.cs b/PrinterControls/PrinterConnections/ConnectionWindow.cs index c4ad56a0e..ddd056985 100644 --- a/PrinterControls/PrinterConnections/ConnectionWindow.cs +++ b/PrinterControls/PrinterConnections/ConnectionWindow.cs @@ -89,15 +89,15 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections this.Invalidate(); } - public void ChangedToEditPrinter(Printer activePrinter) + public void ChangedToEditPrinter(Printer activePrinter, object state = null) { this.activePrinter = activePrinter; - UiThread.RunOnIdle(DoChangeToEditPrinter); + UiThread.RunOnIdle(DoChangeToEditPrinter, state); } private void DoChangeToEditPrinter(object state) { - GuiWidget addConnectionWidget = new EditConnectionWidget(this, this, activePrinter); + GuiWidget addConnectionWidget = new EditConnectionWidget(this, this, activePrinter, state); this.RemoveAllChildren(); this.AddChild(addConnectionWidget); this.Invalidate();