From bbca065e18cadf6ec9dc2bed62c98ef53d99a33e Mon Sep 17 00:00:00 2001 From: larsbrubaker Date: Fri, 8 Aug 2014 10:25:44 -0700 Subject: [PATCH] New weak event rooted event. Fixed color theme changing in 3d view. Fixe bed shape and size changing on printer change. --- AboutPage/ContactForm.cs | 22 ++++++------- ActionBar/ActionBarPlus.cs | 24 +++++++++----- ActionBar/PrintActionRow.cs | 18 ++++++++--- ActionBar/TemperatureWidgetBase.cs | 14 +++++++-- ApplicationView/MainApplicationWidget.cs | 17 ++++++++-- ConfigurationPage/PrinterConfigurationPage.cs | 8 ----- ControlElements/ThemeFactory.cs | 2 +- CustomWidgets/PartThumbnailWidget.cs | 30 +++++++++++------- CustomWidgets/PluginChooserWindow.cs | 17 +++++++--- CustomWidgets/PrintProgressBarWidget.cs | 21 ++++++++----- .../BaseClasses/PartPreview3DWidget.cs | 1 + PartPreviewWindow/PartPreviewMainWindow.cs | 22 ++++++++----- PartPreviewWindow/View3DTransfromPart.cs | 18 ++++++++++- PartPreviewWindow/ViewControls3D.cs | 31 +++++++++++-------- PrintHistory/PrintHistoryListItem.cs | 24 ++++++-------- PrintLibrary/LibraryRowItem.cs | 17 +++++++--- PrintQueue/QueueRowItem.cs | 30 +++++++++++------- PrinterControls/ManualPrinterControls.cs | 8 ----- .../BaseConnectionWidget.cs | 30 +++++++----------- 19 files changed, 214 insertions(+), 140 deletions(-) diff --git a/AboutPage/ContactForm.cs b/AboutPage/ContactForm.cs index c6a86ea28..d1c53279f 100644 --- a/AboutPage/ContactForm.cs +++ b/AboutPage/ContactForm.cs @@ -309,7 +309,7 @@ namespace MatterHackers.MatterControl.ContactForm } } - public class ContactFormWindow : SystemWindow + public class ContactFormWindow : SystemWindow, IReceiveRootedWeakEvent { static ContactFormWindow contactFormWindow; static bool contactFormIsOpen; @@ -349,25 +349,23 @@ namespace MatterHackers.MatterControl.ContactForm MinimumSize = new Vector2(500, 550); } - event EventHandler unregisterEvents; private void AddHandlers() { - ActiveTheme.Instance.ThemeChanged.RegisterEvent(Instance_ThemeChanged, ref unregisterEvents); + ActiveTheme.Instance.ThemeChanged.Register(this, "ThemeChanged"); contactFormWidget.Closed += (sender, e) => { Close(); }; } - public override void OnClosed(EventArgs e) + public void RootedEvent(string eventType, EventArgs e) { - if (unregisterEvents != null) + switch (eventType) { - unregisterEvents(this, null); - } - base.OnClosed(e); - } + case "ThemeChanged": + this.Invalidate(); + break; - void Instance_ThemeChanged(object sender, EventArgs e) - { - Invalidate(); + default: + throw new NotImplementedException(); + } } } } diff --git a/ActionBar/ActionBarPlus.cs b/ActionBar/ActionBarPlus.cs index 944420de5..d33d2882d 100644 --- a/ActionBar/ActionBarPlus.cs +++ b/ActionBar/ActionBarPlus.cs @@ -17,7 +17,7 @@ using MatterHackers.MatterControl.PrinterControls.PrinterConnections; namespace MatterHackers.MatterControl { - public class ActionBarPlus : FlowLayoutWidget + public class ActionBarPlus : FlowLayoutWidget, IReceiveRootedWeakEvent { QueueDataView queueDataView; @@ -41,7 +41,21 @@ namespace MatterHackers.MatterControl this.Padding = new BorderDouble(bottom: 6); // Add Handlers - ActiveTheme.Instance.ThemeChanged.RegisterEvent(onThemeChanged, ref unregisterEvents); + ActiveTheme.Instance.ThemeChanged.Register(this, "ThemeChanged"); + } + + public void RootedEvent(string eventType, EventArgs e) + { + switch (eventType) + { + case "ThemeChanged": + this.BackgroundColor = ActiveTheme.Instance.PrimaryAccentColor; + this.Invalidate(); + break; + + default: + throw new NotImplementedException(); + } } public override void OnClosed(EventArgs e) @@ -52,12 +66,6 @@ namespace MatterHackers.MatterControl } base.OnClosed(e); } - - private void onThemeChanged(object sender, EventArgs e) - { - this.BackgroundColor = ActiveTheme.Instance.PrimaryAccentColor; - this.Invalidate(); - } } class MessageActionRow : ActionRowBase diff --git a/ActionBar/PrintActionRow.cs b/ActionBar/PrintActionRow.cs index f0d634ec4..7b897c809 100644 --- a/ActionBar/PrintActionRow.cs +++ b/ActionBar/PrintActionRow.cs @@ -14,7 +14,7 @@ using MatterHackers.MatterControl.PrinterCommunication; namespace MatterHackers.MatterControl.ActionBar { - class PrintActionRow : ActionRowBase + class PrintActionRow : ActionRowBase, IReceiveRootedWeakEvent { Stopwatch timeSincePrintStarted = new Stopwatch(); @@ -148,7 +148,7 @@ namespace MatterHackers.MatterControl.ActionBar cancelConnectButton.Click += (sender, e) => { UiThread.RunOnIdle(CancelConnectionButton_Click); }; reprintButton.Click += new ButtonBase.ButtonEventHandler(onReprintButton_Click); doneWithCurrentPartButton.Click += new ButtonBase.ButtonEventHandler(onDoneWithCurrentPartButton_Click); - ActiveTheme.Instance.ThemeChanged.RegisterEvent(onThemeChanged, ref unregisterEvents); + ActiveTheme.Instance.ThemeChanged.Register(this, "ThemeChanged"); } public override void OnClosed(EventArgs e) @@ -160,9 +160,17 @@ namespace MatterHackers.MatterControl.ActionBar base.OnClosed(e); } - private void onThemeChanged(object sender, EventArgs e) - { - this.Invalidate(); + public void RootedEvent(string eventType, EventArgs e) + { + switch (eventType) + { + case "ThemeChanged": + this.Invalidate(); + break; + + default: + throw new NotImplementedException(); + } } void onAddButton_Click(object sender, MouseEventArgs mouseEvent) diff --git a/ActionBar/TemperatureWidgetBase.cs b/ActionBar/TemperatureWidgetBase.cs index 813881579..791e8b344 100644 --- a/ActionBar/TemperatureWidgetBase.cs +++ b/ActionBar/TemperatureWidgetBase.cs @@ -35,7 +35,7 @@ using MatterHackers.MatterControl.PrinterCommunication; namespace MatterHackers.MatterControl.ActionBar { - class TemperatureWidgetBase : GuiWidget + class TemperatureWidgetBase : GuiWidget, IReceiveRootedWeakEvent { protected TextWidget indicatorTextWidget; protected TextWidget labelTextWidget; @@ -117,7 +117,7 @@ namespace MatterHackers.MatterControl.ActionBar this.AddChild(container); - ActiveTheme.Instance.ThemeChanged.RegisterEvent(onThemeChanged, ref unregisterEvents); + ActiveTheme.Instance.ThemeChanged.Register(this, "ThemeChanged"); this.MouseEnterBounds += onEnterBounds; this.MouseLeaveBounds += onLeaveBounds; @@ -133,10 +133,18 @@ namespace MatterHackers.MatterControl.ActionBar base.OnClosed(e); } - private void onThemeChanged(object sender, EventArgs e) + public void RootedEvent(string eventType, EventArgs e) { + switch (eventType) + { + case "ThemeChanged": this.indicatorTextWidget.TextColor = ActiveTheme.Instance.PrimaryAccentColor; this.Invalidate(); + break; + + default: + throw new NotImplementedException(); + } } void onEnterBounds(Object sender, EventArgs e) diff --git a/ApplicationView/MainApplicationWidget.cs b/ApplicationView/MainApplicationWidget.cs index 3a3781800..15da45966 100644 --- a/ApplicationView/MainApplicationWidget.cs +++ b/ApplicationView/MainApplicationWidget.cs @@ -50,7 +50,7 @@ using MatterHackers.Localizations; namespace MatterHackers.MatterControl { - public class ApplicationWidget : GuiWidget + public class ApplicationWidget : GuiWidget, IReceiveRootedWeakEvent { static ApplicationWidget globalInstance; public RootedObjectEventHandler ReloadAdvancedControlsPanelTrigger = new RootedObjectEventHandler(); @@ -66,7 +66,20 @@ namespace MatterHackers.MatterControl public ApplicationWidget() { Name = "MainSlidePanel"; - ActiveTheme.Instance.ThemeChanged.RegisterEvent(ReloadAll, ref unregisterEvents); + ActiveTheme.Instance.ThemeChanged.Register(this, "ThemeChanged"); + } + + public void RootedEvent(string eventType, EventArgs e) + { + switch (eventType) + { + case "ThemeChanged": + ReloadAll(null, null); + break; + + default: + throw new NotImplementedException(); + } } WidescreenPanel widescreenPanel; diff --git a/ConfigurationPage/PrinterConfigurationPage.cs b/ConfigurationPage/PrinterConfigurationPage.cs index c9ff04dfa..a5e2b16ea 100644 --- a/ConfigurationPage/PrinterConfigurationPage.cs +++ b/ConfigurationPage/PrinterConfigurationPage.cs @@ -769,7 +769,6 @@ namespace MatterHackers.MatterControl event EventHandler unregisterEvents; private void AddHandlers() { - ActiveTheme.Instance.ThemeChanged.RegisterEvent(onThemeChanged, ref unregisterEvents); PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents); PrinterConnectionAndCommunication.Instance.EnableChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents); } @@ -780,13 +779,6 @@ namespace MatterHackers.MatterControl this.Invalidate(); } - private void onThemeChanged(object sender, EventArgs e) - { - //this.BackgroundColor = ActiveTheme.Instance.PrimaryAccentColor; - // SetVisibleControls(); - //this.Invalidate(); - } - public delegate void EnableCloudMonitor(object state); public static EnableCloudMonitor enableCloudMonitorFunction = null; void enableCloudMonitor_Click(object sender, MouseEventArgs mouseEvent) diff --git a/ControlElements/ThemeFactory.cs b/ControlElements/ThemeFactory.cs index 94a2b95cc..8ee26cbea 100644 --- a/ControlElements/ThemeFactory.cs +++ b/ControlElements/ThemeFactory.cs @@ -53,7 +53,7 @@ namespace MatterHackers.MatterControl private int defaultThemeIndex = 1; private int activeThemeIndex = -1; - public RootedObjectEventHandler ThemeChanged = new RootedObjectEventHandler(); + public RootedObjectWeakEventHandler ThemeChanged = new RootedObjectWeakEventHandler(); public List AvailableThemes { diff --git a/CustomWidgets/PartThumbnailWidget.cs b/CustomWidgets/PartThumbnailWidget.cs index 4eb6b0b0c..b48c683f7 100644 --- a/CustomWidgets/PartThumbnailWidget.cs +++ b/CustomWidgets/PartThumbnailWidget.cs @@ -45,7 +45,7 @@ using MatterHackers.VectorMath; namespace MatterHackers.MatterControl { - public class PartThumbnailWidget : ClickWidget + public class PartThumbnailWidget : ClickWidget, IReceiveRootedWeakEvent { static BackgroundWorker createThumbnailWorker = null; @@ -131,7 +131,7 @@ namespace MatterHackers.MatterControl this.Click += new ButtonEventHandler(OnMouseClick); this.MouseEnterBounds += new EventHandler(onEnter); this.MouseLeaveBounds += new EventHandler(onExit); - ActiveTheme.Instance.ThemeChanged.RegisterEvent(onThemeChanged, ref unregisterEvents); + ActiveTheme.Instance.ThemeChanged.Register(this, "ThemeChanged"); } void item_FileHasChanged(object sender, EventArgs e) @@ -326,17 +326,25 @@ namespace MatterHackers.MatterControl createThumbnailWorker = null; } - private void onThemeChanged(object sender, EventArgs e) + public void RootedEvent(string eventType, EventArgs e) { - //Set background color to new theme - this.normalBackgroundColor = ActiveTheme.Instance.PrimaryAccentColor; - this.BackgroundColor = ActiveTheme.Instance.PrimaryAccentColor; + switch (eventType) + { + case "ThemeChanged": + //Set background color to new theme + this.normalBackgroundColor = ActiveTheme.Instance.PrimaryAccentColor; + this.BackgroundColor = ActiveTheme.Instance.PrimaryAccentColor; - //Regenerate thumbnails - // The thumbnail color is currently white and does not change with this change. - // If we eventually change the thumbnail color with the theme we will need to change this. - //this.thumbNailHasBeenRequested = false; - this.Invalidate(); + //Regenerate thumbnails + // The thumbnail color is currently white and does not change with this change. + // If we eventually change the thumbnail color with the theme we will need to change this. + //this.thumbNailHasBeenRequested = false; + this.Invalidate(); + break; + + default: + throw new NotImplementedException(); + } } private void OnMouseClick(object sender, MouseEventArgs e) diff --git a/CustomWidgets/PluginChooserWindow.cs b/CustomWidgets/PluginChooserWindow.cs index 8713f146a..ac7990205 100644 --- a/CustomWidgets/PluginChooserWindow.cs +++ b/CustomWidgets/PluginChooserWindow.cs @@ -40,7 +40,7 @@ using MatterHackers.VectorMath; namespace MatterHackers.MatterControl.CreatorPlugins { - public class PluginChooserWindow : SystemWindow + public class PluginChooserWindow : SystemWindow, IReceiveRootedWeakEvent { protected TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory(); protected TextImageButtonFactory unlockButtonFactory = new TextImageButtonFactory(); @@ -66,13 +66,20 @@ namespace MatterHackers.MatterControl.CreatorPlugins event EventHandler unregisterEvents; protected void AddHandlers() { - ActiveTheme.Instance.ThemeChanged.RegisterEvent(Instance_ThemeChanged, ref unregisterEvents); + ActiveTheme.Instance.ThemeChanged.Register(this, "ThemeChanged"); } - - protected void Instance_ThemeChanged(object sender, EventArgs e) + public void RootedEvent(string eventType, EventArgs e) { - UiThread.RunOnIdle(Reload); + switch (eventType) + { + case "ThemeChanged": + UiThread.RunOnIdle(Reload); + break; + + default: + throw new NotImplementedException(); + } } public void TriggerReload(object sender, EventArgs e) diff --git a/CustomWidgets/PrintProgressBarWidget.cs b/CustomWidgets/PrintProgressBarWidget.cs index 933758321..5708f6ca3 100644 --- a/CustomWidgets/PrintProgressBarWidget.cs +++ b/CustomWidgets/PrintProgressBarWidget.cs @@ -11,7 +11,7 @@ using MatterHackers.MatterControl.PrinterCommunication; namespace MatterHackers.MatterControl { - public class PrintProgressBar : GuiWidget + public class PrintProgressBar : GuiWidget, IReceiveRootedWeakEvent { double currentPercent = 0; Stopwatch timeSinceLastUpdate = new Stopwatch(); @@ -61,7 +61,7 @@ namespace MatterHackers.MatterControl PrinterConnectionAndCommunication.Instance.WroteLine.RegisterEvent(Instance_WroteLine, ref unregisterEvents); PrinterConnectionAndCommunication.Instance.ActivePrintItemChanged.RegisterEvent(Instance_PrintItemChanged, ref unregisterEvents); PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent(Instance_PrintItemChanged, ref unregisterEvents); - ActiveTheme.Instance.ThemeChanged.RegisterEvent(onThemeChanged, ref unregisterEvents); + ActiveTheme.Instance.ThemeChanged.Register(this, "ThemeChanged"); } public override void OnClosed(EventArgs e) @@ -80,13 +80,20 @@ namespace MatterHackers.MatterControl this.BackgroundColor = ActiveTheme.Instance.SecondaryAccentColor; } - private void onThemeChanged(object sender, EventArgs e) + public void RootedEvent(string eventType, EventArgs e) { - //Set background color to new theme - SetThemedColors(); - this.Invalidate(); - } + switch (eventType) + { + case "ThemeChanged": + //Set background color to new theme + SetThemedColors(); + this.Invalidate(); + break; + default: + throw new NotImplementedException(); + } + } void Instance_PrintItemChanged(object sender, EventArgs e) { diff --git a/PartPreviewWindow/BaseClasses/PartPreview3DWidget.cs b/PartPreviewWindow/BaseClasses/PartPreview3DWidget.cs index 8dc4a76f9..cab449a03 100644 --- a/PartPreviewWindow/BaseClasses/PartPreview3DWidget.cs +++ b/PartPreviewWindow/BaseClasses/PartPreview3DWidget.cs @@ -57,6 +57,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow public PartPreview3DWidget() { SliceSettingsWidget.PartPreviewSettingsChanged.RegisterEvent(RecreateBedAndPartPosition, ref unregisterEvents); + ActivePrinterProfile.Instance.ActivePrinterChanged.RegisterEvent(RecreateBedAndPartPosition, ref unregisterEvents); } void RecreateBedAndPartPosition(object sender, EventArgs e) diff --git a/PartPreviewWindow/PartPreviewMainWindow.cs b/PartPreviewWindow/PartPreviewMainWindow.cs index f677bcccb..ebe492e9c 100644 --- a/PartPreviewWindow/PartPreviewMainWindow.cs +++ b/PartPreviewWindow/PartPreviewMainWindow.cs @@ -41,7 +41,7 @@ using MatterHackers.VectorMath; namespace MatterHackers.MatterControl.PartPreviewWindow { - public class PartPreviewMainWindow : SystemWindow + public class PartPreviewMainWindow : SystemWindow, IReceiveRootedWeakEvent { View3DTransformPart view3DTransformPart; ViewGcodeBasic viewGcodeBasic; @@ -112,11 +112,24 @@ namespace MatterHackers.MatterControl.PartPreviewWindow event EventHandler unregisterEvents; private void AddHandlers() { - ActiveTheme.Instance.ThemeChanged.RegisterEvent(Instance_ThemeChanged, ref unregisterEvents); + ActiveTheme.Instance.ThemeChanged.Register(this, "ThemeChanged"); view3DTransformPart.Closed += (sender, e) => { Close(); }; viewGcodeBasic.Closed += (sender, e) => { Close(); }; } + public void RootedEvent(string eventType, EventArgs e) + { + switch (eventType) + { + case "ThemeChanged": + this.Invalidate(); + break; + + default: + throw new NotImplementedException(); + } + } + public override void OnClosed(EventArgs e) { if (unregisterEvents != null) @@ -125,10 +138,5 @@ namespace MatterHackers.MatterControl.PartPreviewWindow } base.OnClosed(e); } - - void Instance_ThemeChanged(object sender, EventArgs e) - { - Invalidate(); - } } } diff --git a/PartPreviewWindow/View3DTransfromPart.cs b/PartPreviewWindow/View3DTransfromPart.cs index f7f2697e6..1a2e6925e 100644 --- a/PartPreviewWindow/View3DTransfromPart.cs +++ b/PartPreviewWindow/View3DTransfromPart.cs @@ -60,7 +60,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow } } - public class View3DTransformPart : PartPreview3DWidget + public class View3DTransformPart : PartPreview3DWidget, IReceiveRootedWeakEvent { public WindowType windowType { get; set; } @@ -470,8 +470,24 @@ namespace MatterHackers.MatterControl.PartPreviewWindow } } } + + ActiveTheme.Instance.ThemeChanged.Register(this, "ThemeChanged"); } + public void RootedEvent(string eventType, EventArgs e) + { + switch (eventType) + { + case "ThemeChanged": + processingProgressControl.fillColor = ActiveTheme.Instance.PrimaryAccentColor; + break; + + default: + throw new NotImplementedException(); + } + } + + void SetEditControlsBasedOnPrinterState(object sender, EventArgs e) { if (windowType == WindowType.Embeded) diff --git a/PartPreviewWindow/ViewControls3D.cs b/PartPreviewWindow/ViewControls3D.cs index e1d30f61f..43ece4413 100644 --- a/PartPreviewWindow/ViewControls3D.cs +++ b/PartPreviewWindow/ViewControls3D.cs @@ -12,7 +12,7 @@ using MatterHackers.VectorMath; namespace MatterHackers.MatterControl.PartPreviewWindow { - public class ViewControls3D : FlowLayoutWidget + public class ViewControls3D : FlowLayoutWidget, IReceiveRootedWeakEvent { GuiWidget partSelectSeparator; MeshViewerWidget meshViewerWidget; @@ -95,23 +95,28 @@ namespace MatterHackers.MatterControl.PartPreviewWindow SetMeshViewerDisplayTheme(); partSelectButton.CheckedStateChanged += SetMeshViewerDisplayTheme; + + ActiveTheme.Instance.ThemeChanged.Register(this, "ThemeChanged"); + } + + public void RootedEvent(string eventType, EventArgs e) + { + switch (eventType) + { + case "ThemeChanged": + SetMeshViewerDisplayTheme(null, null); + break; + + default: + throw new NotImplementedException(); + } } protected void SetMeshViewerDisplayTheme(object sender = null, EventArgs e = null) { meshViewerWidget.TrackballTumbleWidget.RotationHelperCircleColor = ActiveTheme.Instance.PrimaryBackgroundColor; - //if (partSelectButton.Checked) - { - meshViewerWidget.PartColor = RGBA_Bytes.White; - meshViewerWidget.SelectedPartColor = ActiveTheme.Instance.PrimaryAccentColor; - } -#if false - else - { - meshViewerWidget.PartColor = ActiveTheme.Instance.PrimaryAccentColor; - meshViewerWidget.SelectedPartColor = ActiveTheme.Instance.PrimaryAccentColor; - } -#endif + + meshViewerWidget.PartColor = RGBA_Bytes.White; meshViewerWidget.SelectedPartColor = ActiveTheme.Instance.PrimaryAccentColor; meshViewerWidget.BuildVolumeColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryAccentColor.Red0To255, ActiveTheme.Instance.PrimaryAccentColor.Green0To255, ActiveTheme.Instance.PrimaryAccentColor.Blue0To255, 50); } diff --git a/PrintHistory/PrintHistoryListItem.cs b/PrintHistory/PrintHistoryListItem.cs index 5ef33d163..767f833eb 100644 --- a/PrintHistory/PrintHistoryListItem.cs +++ b/PrintHistory/PrintHistoryListItem.cs @@ -54,7 +54,7 @@ namespace MatterHackers.MatterControl.PrintHistory { - public class PrintHistoryListItem : FlowLayoutWidget + public class PrintHistoryListItem : FlowLayoutWidget, IReceiveRootedWeakEvent { public PrintTask printTask; public RGBA_Bytes WidgetTextColor; @@ -240,26 +240,22 @@ namespace MatterHackers.MatterControl.PrintHistory this.Margin = new BorderDouble(6, 0, 6, 6); } - event EventHandler unregisterEvents; void AddHandlers() { - ActiveTheme.Instance.ThemeChanged.RegisterEvent(onThemeChanged, ref unregisterEvents); + ActiveTheme.Instance.ThemeChanged.Register(this, "ThemeChanged"); } - private void onThemeChanged(object sender, EventArgs e) + public void RootedEvent(string eventType, EventArgs e) { - //Set background and text color to new theme - this.Invalidate(); - } - - - public override void OnClosed(EventArgs e) - { - if (unregisterEvents != null) + switch (eventType) { - unregisterEvents(this, null); + case "ThemeChanged": + this.Invalidate(); + break; + + default: + throw new NotImplementedException(); } - base.OnClosed(e); } public override void OnDraw(Graphics2D graphics2D) diff --git a/PrintLibrary/LibraryRowItem.cs b/PrintLibrary/LibraryRowItem.cs index 7aa462562..0408fc2de 100644 --- a/PrintLibrary/LibraryRowItem.cs +++ b/PrintLibrary/LibraryRowItem.cs @@ -51,7 +51,7 @@ using MatterHackers.PolygonMesh.Processors; namespace MatterHackers.MatterControl.PrintLibrary { - public class LibraryRowItem : ClickWidget + public class LibraryRowItem : ClickWidget, IReceiveRootedWeakEvent { public PrintItemWrapper printItemWrapper; public RGBA_Bytes WidgetTextColor; @@ -209,7 +209,7 @@ namespace MatterHackers.MatterControl.PrintLibrary event EventHandler unregisterEvents; void AddHandlers() { - ActiveTheme.Instance.ThemeChanged.RegisterEvent(onThemeChanged, ref unregisterEvents); + ActiveTheme.Instance.ThemeChanged.Register(this, "ThemeChanged"); //this.Click += new ButtonEventHandler(PrintLibraryListItem_Click); viewLink.Click += new ButtonBase.ButtonEventHandler(onViewLinkClick); removeLink.Click += new ButtonBase.ButtonEventHandler(onRemoveLinkClick); @@ -315,10 +315,17 @@ namespace MatterHackers.MatterControl.PrintLibrary } } - private void onThemeChanged(object sender, EventArgs e) + public void RootedEvent(string eventType, EventArgs e) { - //Set background and text color to new theme - this.Invalidate(); + switch (eventType) + { + case "ThemeChanged": + this.Invalidate(); + break; + + default: + throw new NotImplementedException(); + } } public override void OnDraw(Graphics2D graphics2D) diff --git a/PrintQueue/QueueRowItem.cs b/PrintQueue/QueueRowItem.cs index 4bdc4f306..68bc4ad75 100644 --- a/PrintQueue/QueueRowItem.cs +++ b/PrintQueue/QueueRowItem.cs @@ -50,7 +50,7 @@ using MatterHackers.PolygonMesh; namespace MatterHackers.MatterControl.PrintQueue { - public class QueueRowItem : GuiWidget + public class QueueRowItem : GuiWidget, IReceiveRootedWeakEvent { public PrintItemWrapper PrintItemWrapper { get; set; } public RGBA_Bytes WidgetTextColor; @@ -316,7 +316,7 @@ namespace MatterHackers.MatterControl.PrintQueue event EventHandler unregisterEvents; void AddHandlers() { - ActiveTheme.Instance.ThemeChanged.RegisterEvent(onThemeChanged, ref unregisterEvents); + ActiveTheme.Instance.ThemeChanged.Register(this, "ThemeChanged"); PrintItemWrapper.SlicingOutputMessage.RegisterEvent(PrintItem_SlicingOutputMessage, ref unregisterEvents); @@ -468,16 +468,24 @@ namespace MatterHackers.MatterControl.PrintQueue }); } - private void onThemeChanged(object sender, EventArgs e) + public void RootedEvent(string eventType, EventArgs e) { - if (this.isActivePrint) - { - //Set background and text color to new theme - this.BackgroundColor = ActiveTheme.Instance.PrimaryAccentColor; - this.partLabel.TextColor = RGBA_Bytes.White; - this.partStatus.TextColor = RGBA_Bytes.White; - this.Invalidate(); - } + switch (eventType) + { + case "ThemeChanged": + if (this.isActivePrint) + { + //Set background and text color to new theme + this.BackgroundColor = ActiveTheme.Instance.PrimaryAccentColor; + this.partLabel.TextColor = RGBA_Bytes.White; + this.partStatus.TextColor = RGBA_Bytes.White; + this.Invalidate(); + } + break; + + default: + throw new NotImplementedException(); + } } public void SetTextColors(RGBA_Bytes color) diff --git a/PrinterControls/ManualPrinterControls.cs b/PrinterControls/ManualPrinterControls.cs index 5941478ee..0d2ff88f8 100644 --- a/PrinterControls/ManualPrinterControls.cs +++ b/PrinterControls/ManualPrinterControls.cs @@ -752,7 +752,6 @@ namespace MatterHackers.MatterControl event EventHandler unregisterEvents; private void AddHandlers() { - ActiveTheme.Instance.ThemeChanged.RegisterEvent(onThemeChanged, ref unregisterEvents); PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents); PrinterConnectionAndCommunication.Instance.EnableChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents); } @@ -763,13 +762,6 @@ namespace MatterHackers.MatterControl this.Invalidate(); } - private void onThemeChanged(object sender, EventArgs e) - { - //this.BackgroundColor = ActiveTheme.Instance.PrimaryAccentColor; - //SetVisibleControls(); - //this.Invalidate(); - } - void disableMotors_Click(object sender, MouseEventArgs mouseEvent) { PrinterConnectionAndCommunication.Instance.ReleaseMotors(); diff --git a/PrinterControls/PrinterConnections/BaseConnectionWidget.cs b/PrinterControls/PrinterConnections/BaseConnectionWidget.cs index 6825aa14b..811242735 100644 --- a/PrinterControls/PrinterConnections/BaseConnectionWidget.cs +++ b/PrinterControls/PrinterConnections/BaseConnectionWidget.cs @@ -243,7 +243,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections } - public class ConnectionWidgetBase : GuiWidget + public class ConnectionWidgetBase : GuiWidget, IReceiveRootedWeakEvent { protected GuiWidget containerWindowToClose; protected RGBA_Bytes defaultTextColor = ActiveTheme.Instance.PrimaryTextColor; @@ -260,7 +260,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections { this.windowController = windowController; this.containerWindowToClose = containerWindowToClose; - AddHandlers(); + ActiveTheme.Instance.ThemeChanged.Register(this, "ThemeChanged"); } public int GetPrinterRecordCount() @@ -268,26 +268,18 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections return Datastore.Instance.RecordCount("Printer"); } - event EventHandler unregisterEvents; - private void AddHandlers() + public void RootedEvent(string eventType, EventArgs e) { - ActiveTheme.Instance.ThemeChanged.RegisterEvent(onThemeChanged, ref unregisterEvents); - } - - public override void OnClosed(EventArgs e) - { - if (unregisterEvents != null) + switch (eventType) { - unregisterEvents(this, null); + case "ThemeChanged": + this.linkTextColor = ActiveTheme.Instance.PrimaryAccentColor; + this.Invalidate(); + break; + + default: + throw new NotImplementedException(); } - base.OnClosed(e); } - - private void onThemeChanged(object sender, EventArgs e) - { - this.linkTextColor = ActiveTheme.Instance.PrimaryAccentColor; - this.Invalidate(); - } - } }