From e5c187c687fbc7921a9a2a6d367a9bc54cc17b2a Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Thu, 21 Jul 2016 13:49:22 -0700 Subject: [PATCH] Show com port wizard on desktop when can't connect Don't show com port wizard when setting up a printer Moved onload code (first draw) to ApplicationController getting android to have the same wizard logic as desktop Refactored setup wizard --- ActionBar/PrintActionRow.cs | 6 +- ActionBar/PrinterActionRow.cs | 4 +- ApplicationView/MainApplicationWidget.cs | 38 ++++++++++++ ApplicationView/MenuRow/MenuOptionFile.cs | 2 +- ControlElements/AttentionGetter.cs | 3 +- MatterControlApplication.cs | 31 +--------- .../PrinterConnectionAndCommunication.cs | 4 +- .../PrinterConnections/SetupStepComPortOne.cs | 8 ++- SetupWizard/WizardWindow.cs | 61 +++++++++---------- Submodules/MatterSlice | 2 +- Submodules/agg-sharp | 2 +- TextCreator/TextCreator.csproj | 3 + 12 files changed, 89 insertions(+), 75 deletions(-) diff --git a/ActionBar/PrintActionRow.cs b/ActionBar/PrintActionRow.cs index 0088846e3..a01e054df 100644 --- a/ActionBar/PrintActionRow.cs +++ b/ActionBar/PrintActionRow.cs @@ -436,11 +436,7 @@ namespace MatterHackers.MatterControl.ActionBar { if (ActiveSliceSettings.Instance == null) { -#if __ANDROID__ - WizardWindow.Show(); -#else - PrinterActionRow.OpenConnectionWindow(true); -#endif + WizardWindow.ShowPrinterSetup(); } else { diff --git a/ActionBar/PrinterActionRow.cs b/ActionBar/PrinterActionRow.cs index bf02440b0..3fdc8de06 100644 --- a/ActionBar/PrinterActionRow.cs +++ b/ActionBar/PrinterActionRow.cs @@ -61,7 +61,7 @@ namespace MatterHackers.MatterControl.ActionBar ActiveSliceSettings.ActivePrinterChanged.RegisterEvent(ConnectToActivePrinter, ref staticUnregisterEvents); } - WizardWindow.Show(); + WizardWindow.ShowPrinterSetup(); } public override void OnClosed(EventArgs e) @@ -143,7 +143,7 @@ namespace MatterHackers.MatterControl.ActionBar Cursor = Cursors.Hand, Margin = new BorderDouble(0, 6, rightMarginForWideScreenMode, 3) }; - printerSelector.AddPrinter += (s, e) => WizardWindow.Show(); + printerSelector.AddPrinter += (s, e) => WizardWindow.ShowPrinterSetup(); printerSelector.MinimumSize = new Vector2(printerSelector.MinimumSize.x, connectPrinterButton.MinimumSize.y); printerSelectorAndEditButton.AddChild(printerSelector); diff --git a/ApplicationView/MainApplicationWidget.cs b/ApplicationView/MainApplicationWidget.cs index 4e2100fc5..3fd8df75f 100644 --- a/ApplicationView/MainApplicationWidget.cs +++ b/ApplicationView/MainApplicationWidget.cs @@ -391,5 +391,43 @@ namespace MatterHackers.MatterControl { public bool IsAuthenticated { get; set; } } + + public void OnLoadActions() + { + ApplicationController.Instance.UserChanged(); + + if (false && UserSettings.Instance.get("SoftwareLicenseAccepted") != "true") + { + //UiThread.RunOnIdle(() => WizardWindow.Show("SoftwareLicense", "Software License Agreement")); + } + bool showAuthWindow = WizardWindow.ShouldShowAuthPanel?.Invoke() ?? false; + if (showAuthWindow) + { + //Launch window to prompt user to log in + UiThread.RunOnIdle(() => WizardWindow.ShowPrinterSetup()); + } + else + { //If user in logged in sync before checking to prompt to create printer + ApplicationController.SyncPrinterProfiles().ContinueWith((task) => + { + ApplicationController.Instance.ReloadAdvancedControlsPanel(); + if (!ProfileManager.Instance.ActiveProfiles.Any()) + { + // Start the setup wizard if no profiles exist + UiThread.RunOnIdle(() => WizardWindow.ShowPrinterSetup()); + } + }); + } + + if (ActiveSliceSettings.Instance.PrinterSelected + && ActiveSliceSettings.Instance.GetValue(SettingsKey.auto_connect)) + { + UiThread.RunOnIdle(() => + { + //PrinterConnectionAndCommunication.Instance.HaltConnectionThread(); + PrinterConnectionAndCommunication.Instance.ConnectToActivePrinter(); + }, 2); + } + } } } \ No newline at end of file diff --git a/ApplicationView/MenuRow/MenuOptionFile.cs b/ApplicationView/MenuRow/MenuOptionFile.cs index 61ecb94d4..de05c7b1d 100644 --- a/ApplicationView/MenuRow/MenuOptionFile.cs +++ b/ApplicationView/MenuRow/MenuOptionFile.cs @@ -34,7 +34,7 @@ namespace MatterHackers.MatterControl { return new List { - new MenuItemAction("Add Printer".Localize(), () => WizardWindow.Show()), + new MenuItemAction("Add Printer".Localize(), () => WizardWindow.ShowPrinterSetup()), new MenuItemAction("Add File To Queue".Localize(), importFile_Click), new MenuItemAction("Redeem Design Code".Localize(), () => RedeemDesignCode?.Invoke(this, null)), new MenuItemAction("Enter Share Code".Localize(), () => EnterShareCode?.Invoke(this, null)), diff --git a/ControlElements/AttentionGetter.cs b/ControlElements/AttentionGetter.cs index ed8614a33..5d7418773 100644 --- a/ControlElements/AttentionGetter.cs +++ b/ControlElements/AttentionGetter.cs @@ -60,7 +60,8 @@ namespace MatterHackers.MatterControl public static void GoToPrinterSettings(string widgetNameToHighlight) { if (PrinterConnectionAndCommunication.Instance?.ActivePrinter?.ID != null - && ActiveSliceSettings.Instance.PrinterSelected) + && ActiveSliceSettings.Instance.PrinterSelected + && !WizardWindow.IsOpen("PrinterSetup")) { UiThread.RunOnIdle(() => { diff --git a/MatterControlApplication.cs b/MatterControlApplication.cs index 46ac5f58b..c8da885b6 100644 --- a/MatterControlApplication.cs +++ b/MatterControlApplication.cs @@ -1,5 +1,5 @@ /* -Copyright (c) 2014, Lars Brubaker, Kevin Pope +Copyright (c) 2016, Lars Brubaker, Kevin Pope All rights reserved. Redistribution and use in source and binary forms, with or without @@ -62,7 +62,6 @@ namespace MatterHackers.MatterControl public class MatterControlApplication : SystemWindow { public static bool CameraPreviewActive = false; - public static Action AfterFirstDraw = null; public bool RestartOnClose = false; private static readonly Vector2 minSize = new Vector2(600, 600); private static MatterControlApplication instance; @@ -694,7 +693,7 @@ namespace MatterHackers.MatterControl TerminalWindow.ShowIfLeftOpen(); - ApplicationController.Instance.UserChanged(); + ApplicationController.Instance.OnLoadActions(); #if false { @@ -713,32 +712,6 @@ namespace MatterHackers.MatterControl }, 1); } #endif - - AfterFirstDraw?.Invoke(); - - if (false && UserSettings.Instance.get("SoftwareLicenseAccepted") != "true") - { - UiThread.RunOnIdle(() => WizardWindow.Show("SoftwareLicense", "Software License Agreement")); - } - bool showAuthWindow = WizardWindow.ShouldShowAuthPanel?.Invoke() ?? false; - if (showAuthWindow) - { - //Launch window to prompt user to log in - UiThread.RunOnIdle(() => WizardWindow.Show()); - } - else - { //If user in logged in sync before checking to prompt to create printer - ApplicationController.SyncPrinterProfiles().ContinueWith((task) => - { - ApplicationController.Instance.ReloadAdvancedControlsPanel(); - if (!ProfileManager.Instance.ActiveProfiles.Any()) - { - // Start the setup wizard if no profiles exist - UiThread.RunOnIdle(() => WizardWindow.Show()); - } - }); - } - } //msGraph.AddData("ms", totalDrawTime.ElapsedMilliseconds); diff --git a/PrinterCommunication/PrinterConnectionAndCommunication.cs b/PrinterCommunication/PrinterConnectionAndCommunication.cs index 4c79d405c..6d48c8544 100644 --- a/PrinterCommunication/PrinterConnectionAndCommunication.cs +++ b/PrinterCommunication/PrinterConnectionAndCommunication.cs @@ -2327,7 +2327,9 @@ namespace MatterHackers.MatterControl.PrinterCommunication OnConnectionFailed(null); - UiNavigation.GoToPrinterSettings("com_port Edit Field"); +#if !__ANDROID__ + WizardWindow.ShowComPortSetup(); +#endif } } diff --git a/PrinterControls/PrinterConnections/SetupStepComPortOne.cs b/PrinterControls/PrinterConnections/SetupStepComPortOne.cs index bd4fafc55..cb91d2554 100644 --- a/PrinterControls/PrinterConnections/SetupStepComPortOne.cs +++ b/PrinterControls/PrinterConnections/SetupStepComPortOne.cs @@ -77,7 +77,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections Button skipConnectionLink = linkButtonFactory.Generate(LocalizedString.Get("Skip Connection Setup")); skipConnectionLink.Margin = new BorderDouble(0, 8); - skipConnectionLink.Click += new EventHandler(SkipConnectionLink_Click); + skipConnectionLink.Click += SkipConnectionLink_Click; container.AddChild(printerMessageOne); container.AddChild(printerMessageTwo); @@ -94,8 +94,10 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections private void SkipConnectionLink_Click(object sender, EventArgs mouseEvent) { - PrinterConnectionAndCommunication.Instance.HaltConnectionThread(); - Parent.Close(); + UiThread.RunOnIdle(() => { + PrinterConnectionAndCommunication.Instance.HaltConnectionThread(); + Parent.Close(); + }); } } } \ No newline at end of file diff --git a/SetupWizard/WizardWindow.cs b/SetupWizard/WizardWindow.cs index 38b906fae..6bd5a5fa8 100644 --- a/SetupWizard/WizardWindow.cs +++ b/SetupWizard/WizardWindow.cs @@ -16,45 +16,19 @@ namespace MatterHackers.MatterControl public static Func ShouldShowAuthPanel { get; set; } public static Action ShowAuthDialog; public static Action ChangeToAccountCreate; - private static WizardWindow wizardWindow = null; private static Dictionary allWindows = new Dictionary(); private WizardWindow() : base(500 * GuiWidget.DeviceScale, 500 * GuiWidget.DeviceScale) { - this.AlwaysOnTopOfMain = true; this.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor; this.Padding = new BorderDouble(8); - this.ShowAsSystemWindow(); this.MinimumSize = new Vector2(350 * GuiWidget.DeviceScale, 400 * GuiWidget.DeviceScale); - } - private WizardWindow(bool openToHome = false) - : base(500 * GuiWidget.DeviceScale, 500 * GuiWidget.DeviceScale) - { - this.AlwaysOnTopOfMain = true; - - AlwaysOnTopOfMain = true; - this.Title = "Setup Wizard".Localize(); - - // Todo - detect wifi connectivity - bool WifiDetected = MatterControlApplication.Instance.IsNetworkConnected(); - if (!WifiDetected) - { - ChangeToPage(); - } - else - { - ChangeToSetupPrinterForm(); - } - - this.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor; - this.Padding = new BorderDouble(8); this.ShowAsSystemWindow(); - this.MinimumSize = new Vector2(350 * GuiWidget.DeviceScale, 400 * GuiWidget.DeviceScale); } public static void Close(string uri) @@ -81,19 +55,44 @@ namespace MatterHackers.MatterControl wizardWindow.ChangeToPage(wizardPage); } - public static void Show(bool openToHome = false) + public static void ShowPrinterSetup() { - if (wizardWindow == null) + WizardWindow wizardWindow = GetWindow("PrinterSetup"); + wizardWindow.Title = "Setup Wizard".Localize(); + + // Do the printer setup logic + // Todo - detect wifi connectivity + bool WifiDetected = MatterControlApplication.Instance.IsNetworkConnected(); + if (!WifiDetected) { - wizardWindow = new WizardWindow(openToHome); - wizardWindow.Closed += (s, e) => wizardWindow = null; + wizardWindow.ChangeToPage(); } else { - wizardWindow.BringToFront(); + wizardWindow.ChangeToSetupPrinterForm(); } } + public static void ShowComPortSetup() + { + WizardWindow wizardWindow = GetWindow("PrinterSetup"); + wizardWindow.Title = "Setup Wizard".Localize(); + + wizardWindow.ChangeToPage(); + } + + public static bool IsOpen(string uri) + { + WizardWindow wizardWindow; + + if (allWindows.TryGetValue(uri, out wizardWindow)) + { + return true; + } + + return false; + } + private static WizardWindow GetWindow(string uri) { WizardWindow wizardWindow; diff --git a/Submodules/MatterSlice b/Submodules/MatterSlice index 440bf80e8..9ba3b557b 160000 --- a/Submodules/MatterSlice +++ b/Submodules/MatterSlice @@ -1 +1 @@ -Subproject commit 440bf80e81ee5767b75834feeaa638c3fc6f092b +Subproject commit 9ba3b557b51ef7e84ed6b64e49c8dac2f9b1bbf1 diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 8bedcef1e..96e12d5bd 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 8bedcef1eab97b000e3d214366fb0fe1d587382a +Subproject commit 96e12d5bd3f5c1e04f6ce93eaa9ba85bd080c8d8 diff --git a/TextCreator/TextCreator.csproj b/TextCreator/TextCreator.csproj index 79026f9f4..4ee75d402 100644 --- a/TextCreator/TextCreator.csproj +++ b/TextCreator/TextCreator.csproj @@ -209,6 +209,9 @@ + + +