From efe22f8dfd2d089babec9dbd9b233dd06823121a Mon Sep 17 00:00:00 2001 From: John Lewin Date: Wed, 10 Oct 2018 14:58:37 -0700 Subject: [PATCH] Move event registration to bottom of constructor --- .../PartPreviewWindow/PartPreviewContent.cs | 70 +++++++++---------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/MatterControlLib/PartPreviewWindow/PartPreviewContent.cs b/MatterControlLib/PartPreviewWindow/PartPreviewContent.cs index e7781db15..228bcb9f5 100644 --- a/MatterControlLib/PartPreviewWindow/PartPreviewContent.cs +++ b/MatterControlLib/PartPreviewWindow/PartPreviewContent.cs @@ -199,43 +199,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow tabControl.TabBar.ActionArea.AddChild(updateAvailableButton); - UpdateControlData.Instance.UpdateStatusChanged.RegisterEvent((s, e) => - { - SetLinkButtonsVisibility(s, new StringEventArgs("Unknown")); - }, ref unregisterEvents); - this.AddChild(tabControl); - PrinterSettings.SettingChanged.RegisterEvent((s, e) => - { - var activePrinter = ApplicationController.Instance.ActivePrinter; - - if (e is StringEventArgs stringEvent - && stringEvent.Data == SettingsKey.printer_name - && printerTab != null) - { - printerTab.Text = activePrinter.Settings.GetValue(SettingsKey.printer_name); - } - - }, ref unregisterEvents); - - ApplicationController.Instance.ActivePrinterChanged.RegisterEvent((s, e) => - { - var activePrinter = ApplicationController.Instance.ActivePrinter; - - // If ActivePrinter has been nulled and a printer tab is open, close it - var tab1 = tabControl.AllTabs.Skip(1).FirstOrDefault(); - if ((activePrinter == null || !activePrinter.Settings.PrinterSelected) - && tab1?.TabContent is PrinterTabPage) - { - tabControl.RemoveTab(tab1); - } - else - { - this.CreatePrinterTab(activePrinter, theme); - } - }, ref unregisterEvents); - ApplicationController.Instance.NotifyPrintersTabRightElement(extensionArea); // Add a tab for the current printer @@ -292,6 +257,41 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { this.CreatePartTab("New Part", bed, theme); } + + UpdateControlData.Instance.UpdateStatusChanged.RegisterEvent((s, e) => + { + SetLinkButtonsVisibility(s, new StringEventArgs("Unknown")); + }, ref unregisterEvents); + + PrinterSettings.SettingChanged.RegisterEvent((s, e) => + { + var activePrinter = ApplicationController.Instance.ActivePrinter; + + if (e is StringEventArgs stringEvent + && stringEvent.Data == SettingsKey.printer_name + && printerTab != null) + { + printerTab.Text = activePrinter.Settings.GetValue(SettingsKey.printer_name); + } + + }, ref unregisterEvents); + + ApplicationController.Instance.ActivePrinterChanged.RegisterEvent((s, e) => + { + var activePrinter = ApplicationController.Instance.ActivePrinter; + + // If ActivePrinter has been nulled and a printer tab is open, close it + var tab1 = tabControl.AllTabs.Skip(1).FirstOrDefault(); + if ((activePrinter == null || !activePrinter.Settings.PrinterSelected) + && tab1?.TabContent is PrinterTabPage) + { + tabControl.RemoveTab(tab1); + } + else + { + this.CreatePrinterTab(activePrinter, theme); + } + }, ref unregisterEvents); } public ChromeTabs TabControl => tabControl;