From e936fe98f7935ff0901f7fc62a6727b27a084614 Mon Sep 17 00:00:00 2001 From: kevinepope Date: Tue, 21 Oct 2014 21:20:09 -0700 Subject: [PATCH] Change message confirmation dialogs from modal to async w/callback. --- AboutPage/UpdateControlData.cs | 28 +++++++----- ActionBar/PrintActionRow.cs | 43 +++++++++++++------ ActionBar/PrinterActionRow.cs | 25 +++++------ ActionBar/TemperatureWidgetBed.cs | 2 +- ActionBar/TemperatureWidgetExtruder.cs | 2 +- ApplicationView/ApplicationMenuRow.cs | 2 +- .../PrintLeveling/PrintLevelPages.cs | 2 +- ConfigurationPage/PrinterConfigurationPage.cs | 4 +- .../PrinterSettings/PrinterSettingsView.cs | 4 +- ControlElements/StyledMessageBoxWindow.cs | 34 +++++++++------ DataStorage/Datastore.cs | 2 +- MatterControlApplication.cs | 23 ++++++---- PartPreviewWindow/View3D/View3DWidget.cs | 4 +- PrintHistory/PrintHistoryListItem.cs | 15 +++++-- PrintLibrary/LibraryRowItem.cs | 13 ++++-- PrintQueue/OptionsMenu/QueueOptionsMenu.cs | 2 +- PrintQueue/QueueRowItem.cs | 31 +++++++++---- PrinterControls/TemperatureIndicator.cs | 4 +- SlicerConfiguration/ActiveSliceSettings.cs | 14 +++--- Utilities/ProjectFileHandler.cs | 2 +- 20 files changed, 158 insertions(+), 98 deletions(-) diff --git a/AboutPage/UpdateControlData.cs b/AboutPage/UpdateControlData.cs index 2aecd343d..52e5abb02 100644 --- a/AboutPage/UpdateControlData.cs +++ b/AboutPage/UpdateControlData.cs @@ -186,23 +186,29 @@ namespace MatterHackers.MatterControl { UiThread.RunOnIdle((state) => { + StyledMessageBox.ShowMessageBox(ProcessDialogResponse, updateAvailableMessage, updateAvailableTitle, StyledMessageBox.MessageType.YES_NO, downloadNow, remindMeLater); // show a dialog to tell the user there is an update - if (StyledMessageBox.ShowMessageBox(updateAvailableMessage, updateAvailableTitle, StyledMessageBox.MessageType.YES_NO, downloadNow, remindMeLater)) - { - InitiateUpdateDownload(); - // Switch to the about page so we can see the download progress. - GuiWidget aboutTabWidget = FindNamedWidgetRecursive(ApplicationController.Instance.MainView, "About Tab"); - Tab aboutTab = aboutTabWidget as Tab; - if (aboutTab != null) - { - aboutTab.TabBarContaningTab.SelectTab(aboutTab); - } - } + }); } } } + void ProcessDialogResponse(bool messageBoxResponse) + { + if (messageBoxResponse) + { + InitiateUpdateDownload(); + // Switch to the about page so we can see the download progress. + GuiWidget aboutTabWidget = FindNamedWidgetRecursive(ApplicationController.Instance.MainView, "About Tab"); + Tab aboutTab = aboutTabWidget as Tab; + if (aboutTab != null) + { + aboutTab.TabBarContaningTab.SelectTab(aboutTab); + } + } + } + static GuiWidget FindNamedWidgetRecursive(GuiWidget root, string name) { foreach (GuiWidget child in root.Children) diff --git a/ActionBar/PrintActionRow.cs b/ActionBar/PrintActionRow.cs index 04767b4bf..22715d7d1 100644 --- a/ActionBar/PrintActionRow.cs +++ b/ActionBar/PrintActionRow.cs @@ -264,11 +264,7 @@ namespace MatterHackers.MatterControl.ActionBar ApplicationSettings.Instance.set("HideGCodeWarning", null); } }; - if (!StyledMessageBox.ShowMessageBox(gcodeWarningMessage, "Warning GCode file".Localize(), new GuiWidget[] { hideGCodeWaringCheckBox }, StyledMessageBox.MessageType.YES_NO)) - { - // the user selected 'no' they don't want to print the file - return; - } + StyledMessageBox.ShowMessageBox(onConfirmPrint, gcodeWarningMessage, "Warning - GCode file".Localize(), new GuiWidget[] { hideGCodeWaringCheckBox }, StyledMessageBox.MessageType.YES_NO); } PrinterConnectionAndCommunication.Instance.CommunicationState = PrinterConnectionAndCommunication.CommunicationStates.PreparingToPrint; @@ -279,14 +275,30 @@ namespace MatterHackers.MatterControl.ActionBar else { string message = String.Format(removeFromQueueMessage, pathAndFile); - if (StyledMessageBox.ShowMessageBox(message, itemNotFoundMessage, StyledMessageBox.MessageType.YES_NO)) - { - QueueData.Instance.RemoveAt(queueDataView.SelectedIndex); - } + StyledMessageBox.ShowMessageBox(onRemoveMessageConfirm, message, itemNotFoundMessage, StyledMessageBox.MessageType.YES_NO); } } } + void onConfirmPrint(bool messageBoxResponse) + { + if (!messageBoxResponse) + { + PrinterConnectionAndCommunication.Instance.CommunicationState = PrinterConnectionAndCommunication.CommunicationStates.PreparingToPrint; + PrintItemWrapper partToPrint = PrinterConnectionAndCommunication.Instance.ActivePrintItem; + SlicingQueue.Instance.QueuePartForSlicing(partToPrint); + partToPrint.SlicingDone.RegisterEvent(partToPrint_SliceDone, ref unregisterEvents); + } + } + + void onRemoveMessageConfirm(bool messageBoxResponse) + { + if (messageBoxResponse) + { + QueueData.Instance.RemoveAt(queueDataView.SelectedIndex); + } + } + void onStartButton_Click(object sender, MouseEventArgs mouseEvent) { UiThread.RunOnIdle((state) => @@ -327,10 +339,7 @@ namespace MatterHackers.MatterControl.ActionBar { if (timeSincePrintStarted.IsRunning && timeSincePrintStarted.ElapsedMilliseconds > (2 * 60 * 1000)) { - if (StyledMessageBox.ShowMessageBox(cancelCurrentPrintMessage, cancelCurrentPrintTitle, StyledMessageBox.MessageType.YES_NO)) - { - CancelPrinting(); - } + StyledMessageBox.ShowMessageBox(onConfirmCancelPrint, cancelCurrentPrintMessage, cancelCurrentPrintTitle, StyledMessageBox.MessageType.YES_NO); } else { @@ -338,6 +347,14 @@ namespace MatterHackers.MatterControl.ActionBar } } + void onConfirmCancelPrint(bool messageBoxResponse) + { + if (messageBoxResponse) + { + CancelPrinting(); + } + } + void CancelConnectionButton_Click(object state) { CancelPrinting(); diff --git a/ActionBar/PrinterActionRow.cs b/ActionBar/PrinterActionRow.cs index 73191b751..c9c6ac1a4 100644 --- a/ActionBar/PrinterActionRow.cs +++ b/ActionBar/PrinterActionRow.cs @@ -207,27 +207,28 @@ namespace MatterHackers.MatterControl.ActionBar string disconnectAndCancelMessage = "Disconnect and cancel the current print?".Localize(); string disconnectAndCancelTitle = "WARNING: Disconnecting will cancel the current print.\n\nDo you want to disconnect?".Localize(); void OnIdleDisconnect(object state) - { - bool doCancel = true; + { if (PrinterConnectionAndCommunication.Instance.PrinterIsPrinting) { - if (StyledMessageBox.ShowMessageBox(disconnectAndCancelMessage, disconnectAndCancelTitle, StyledMessageBox.MessageType.YES_NO)) - { - PrinterConnectionAndCommunication.Instance.Stop(); - } - else - { - doCancel = false; - } + StyledMessageBox.ShowMessageBox(onConfirmStopPrint, disconnectAndCancelMessage, disconnectAndCancelTitle, StyledMessageBox.MessageType.YES_NO); } - - if (doCancel) + else { PrinterConnectionAndCommunication.Instance.Disable(); selectActivePrinterButton.Invalidate(); } } + void onConfirmStopPrint(bool messageBoxResponse) + { + if (messageBoxResponse) + { + PrinterConnectionAndCommunication.Instance.Stop(); + PrinterConnectionAndCommunication.Instance.Disable(); + selectActivePrinterButton.Invalidate(); + } + } + void SetConnectionButtonVisibleState(object state) { diff --git a/ActionBar/TemperatureWidgetBed.cs b/ActionBar/TemperatureWidgetBed.cs index a377d5074..26738c9b2 100644 --- a/ActionBar/TemperatureWidgetBed.cs +++ b/ActionBar/TemperatureWidgetBed.cs @@ -117,7 +117,7 @@ namespace MatterHackers.MatterControl.ActionBar && goalTemp != PrinterConnectionAndCommunication.Instance.TargetBedTemperature) { string message = string.Format(waitingForBedToHeatMessage, PrinterConnectionAndCommunication.Instance.TargetBedTemperature, sliceSettingsNote); - StyledMessageBox.ShowMessageBox(message, waitingForBedToHeatTitle); + StyledMessageBox.ShowMessageBox(null, message, waitingForBedToHeatTitle); } else { diff --git a/ActionBar/TemperatureWidgetExtruder.cs b/ActionBar/TemperatureWidgetExtruder.cs index 07051625e..fb4dcc6d9 100644 --- a/ActionBar/TemperatureWidgetExtruder.cs +++ b/ActionBar/TemperatureWidgetExtruder.cs @@ -117,7 +117,7 @@ namespace MatterHackers.MatterControl.ActionBar && goalTemp != PrinterConnectionAndCommunication.Instance.GetTargetExtruderTemperature(extruderNumber - 1)) { string message = string.Format(waitingForeExtruderToHeatMessage, PrinterConnectionAndCommunication.Instance.GetTargetExtruderTemperature(extruderNumber - 1), sliceSettingsNote); - StyledMessageBox.ShowMessageBox(message, waitingForeExtruderToHeatTitle); + StyledMessageBox.ShowMessageBox(null, message, waitingForeExtruderToHeatTitle); } else { diff --git a/ApplicationView/ApplicationMenuRow.cs b/ApplicationView/ApplicationMenuRow.cs index 8dc0ed25f..95fb8762b 100644 --- a/ApplicationView/ApplicationMenuRow.cs +++ b/ApplicationView/ApplicationMenuRow.cs @@ -177,7 +177,7 @@ namespace MatterHackers.MatterControl if(PrinterConnectionAndCommunication.Instance.PrinterIsPrinting) { - StyledMessageBox.ShowMessageBox(cannotExitWhileActiveMessage, cannotExitWhileActiveTitle); + StyledMessageBox.ShowMessageBox(null, cannotExitWhileActiveMessage, cannotExitWhileActiveTitle); } else { diff --git a/ConfigurationPage/PrintLeveling/PrintLevelPages.cs b/ConfigurationPage/PrintLeveling/PrintLevelPages.cs index 8724fdf81..421e26c30 100644 --- a/ConfigurationPage/PrintLeveling/PrintLevelPages.cs +++ b/ConfigurationPage/PrintLeveling/PrintLevelPages.cs @@ -274,7 +274,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling { UiThread.RunOnIdle( (state) => { - StyledMessageBox.ShowMessageBox(zIsTooLowMessage, zTooLowTitle, StyledMessageBox.MessageType.OK); + StyledMessageBox.ShowMessageBox(null, zIsTooLowMessage, zTooLowTitle, StyledMessageBox.MessageType.OK); }); // don't move the bed lower it will not work when we print. return; diff --git a/ConfigurationPage/PrinterConfigurationPage.cs b/ConfigurationPage/PrinterConfigurationPage.cs index 9dfd69531..ebad66776 100644 --- a/ConfigurationPage/PrinterConfigurationPage.cs +++ b/ConfigurationPage/PrinterConfigurationPage.cs @@ -443,7 +443,7 @@ namespace MatterHackers.MatterControl static EePromMarlinWidget openEePromMarlinWidget = null; static EePromRepetierWidget openEePromRepetierWidget = null; string noEepromMappingMessage = "Oops! There is no eeprom mapping for your printer's firmware.".Localize(); - string noEepromMappingTitle = "Warning no eeprom mapping".Localize(); + string noEepromMappingTitle = "Warning - No EEProm Mapping".Localize(); string groupBoxTitle = "EEProm Settings".Localize(); private void AddEePromControls(FlowLayoutWidget controlsTopToBottomLayout) { @@ -508,7 +508,7 @@ namespace MatterHackers.MatterControl default: UiThread.RunOnIdle((state) => { - StyledMessageBox.ShowMessageBox(noEepromMappingMessage, noEepromMappingTitle, StyledMessageBox.MessageType.OK); + StyledMessageBox.ShowMessageBox(null, noEepromMappingMessage, noEepromMappingTitle, StyledMessageBox.MessageType.OK); } ); break; diff --git a/ConfigurationPage/PrinterSettings/PrinterSettingsView.cs b/ConfigurationPage/PrinterSettings/PrinterSettingsView.cs index bf6b1b036..b2bf4a62c 100644 --- a/ConfigurationPage/PrinterSettings/PrinterSettingsView.cs +++ b/ConfigurationPage/PrinterSettings/PrinterSettingsView.cs @@ -175,7 +175,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage static EePromMarlinWidget openEePromMarlinWidget = null; static EePromRepetierWidget openEePromRepetierWidget = null; string noEepromMappingMessage = "Oops! There is no eeprom mapping for your printer's firmware.".Localize(); - string noEepromMappingTitle = "Warning no eeprom mapping".Localize(); + string noEepromMappingTitle = "Warning - No EEProm Mapping".Localize(); string groupBoxTitle = "EEProm Settings".Localize(); private FlowLayoutWidget GetEEPromControl() { @@ -257,7 +257,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage break; default: - StyledMessageBox.ShowMessageBox(noEepromMappingMessage, noEepromMappingTitle, StyledMessageBox.MessageType.OK); + StyledMessageBox.ShowMessageBox(null, noEepromMappingMessage, noEepromMappingTitle, StyledMessageBox.MessageType.OK); break; } #endif diff --git a/ControlElements/StyledMessageBoxWindow.cs b/ControlElements/StyledMessageBoxWindow.cs index 3c270dfe4..38a25c07d 100644 --- a/ControlElements/StyledMessageBoxWindow.cs +++ b/ControlElements/StyledMessageBoxWindow.cs @@ -17,28 +17,29 @@ namespace MatterHackers.MatterControl String unwrappedMessage; TextWidget messageContainer; FlowLayoutWidget middleRowContainer; - public EventHandler ClickedOk; TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory(); + public delegate void MessageBoxDelegate(bool response); + MessageBoxDelegate responseCallback; + public enum MessageType { OK, YES_NO }; - public static bool ShowMessageBox(String message, string caption, MessageType messageType = MessageType.OK, string yesOk = "", string no = "") + public static void ShowMessageBox(MessageBoxDelegate callback, String message, string caption, MessageType messageType = MessageType.OK, string yesOk = "", string no = "") { - return ShowMessageBox(message, caption, null, messageType, yesOk, no); + ShowMessageBox(callback, message, caption, null, messageType, yesOk, no); } - public static bool ShowMessageBox(string message, string caption, GuiWidget[] extraWidgetsToAdd, MessageType messageType, string yesOk = "", string no = "") + public static void ShowMessageBox(MessageBoxDelegate callback, string message, string caption, GuiWidget[] extraWidgetsToAdd, MessageType messageType, string yesOk = "", string no = "") { - StyledMessageBox messageBox = new StyledMessageBox(message, caption, messageType, extraWidgetsToAdd, 400, 300, yesOk, no); - bool okClicked = false; - messageBox.ClickedOk += (sender, e) => { okClicked = true; }; + StyledMessageBox messageBox = new StyledMessageBox(callback, message, caption, messageType, extraWidgetsToAdd, 400, 300, yesOk, no); messageBox.ShowAsSystemWindow(); - return okClicked; + } - public StyledMessageBox(String message, string windowTitle, MessageType messageType, GuiWidget[] extraWidgetsToAdd, double width, double height, string yesOk, string no) + public StyledMessageBox(MessageBoxDelegate callback, String message, string windowTitle, MessageType messageType, GuiWidget[] extraWidgetsToAdd, double width, double height, string yesOk, string no) : base(width, height) { + responseCallback = callback; unwrappedMessage = message; FlowLayoutWidget topToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom); topToBottom.AnchorAll(); @@ -182,17 +183,22 @@ namespace MatterHackers.MatterControl } void noButton_Click(object sender, MouseEventArgs mouseEvent) - { + { UiThread.RunOnIdle(CloseOnIdle); + if (responseCallback != null) + { + responseCallback(false); + } } void okButton_Click(object sender, MouseEventArgs mouseEvent) { - if (ClickedOk != null) - { - ClickedOk(this, null); - } UiThread.RunOnIdle(CloseOnIdle); + if (responseCallback != null) + { + responseCallback(true); + } + } void CloseOnIdle(object state) diff --git a/DataStorage/Datastore.cs b/DataStorage/Datastore.cs index c9afa3d32..5e847023a 100644 --- a/DataStorage/Datastore.cs +++ b/DataStorage/Datastore.cs @@ -272,7 +272,7 @@ namespace MatterHackers.MatterControl.DataStorage GenerateSampleData sampleData = new GenerateSampleData(); } else - { + { ValidateSchema(); } StartSession(); diff --git a/MatterControlApplication.cs b/MatterControlApplication.cs index 2b19af990..8a2815218 100644 --- a/MatterControlApplication.cs +++ b/MatterControlApplication.cs @@ -373,24 +373,29 @@ namespace MatterHackers.MatterControl if (PrinterConnectionAndCommunication.Instance.PrinterIsPrinting) { - StyledMessageBox.ShowMessageBox(unableToExitMessage, unableToExitTitle); + StyledMessageBox.ShowMessageBox(null, unableToExitMessage, unableToExitTitle); CancelClose = true; } else if (PartsSheet.IsSaving()) { - if (!StyledMessageBox.ShowMessageBox(savePartsSheetExitAnywayMessage, confirmExit, StyledMessageBox.MessageType.YES_NO)) - { - CancelClose = true; - } - else - { - base.OnClosing(out CancelClose); - } + StyledMessageBox.ShowMessageBox(onConfirmExit, savePartsSheetExitAnywayMessage, confirmExit, StyledMessageBox.MessageType.YES_NO); + CancelClose = true; } else { base.OnClosing(out CancelClose); } } + + bool cancelClose; + void onConfirmExit(bool messageBoxResponse) + { + bool CancelClose; + if (messageBoxResponse) + { + base.OnClosing(out CancelClose); + } + + } } } diff --git a/PartPreviewWindow/View3D/View3DWidget.cs b/PartPreviewWindow/View3D/View3DWidget.cs index 8f9462a65..ee0f5b401 100644 --- a/PartPreviewWindow/View3D/View3DWidget.cs +++ b/PartPreviewWindow/View3D/View3DWidget.cs @@ -1693,11 +1693,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow catch (System.UnauthorizedAccessException) { //Do something special when unauthorized? - StyledMessageBox.ShowMessageBox("Oops! Unable to save changes.", "Unable to save"); + StyledMessageBox.ShowMessageBox(null, "Oops! Unable to save changes.", "Unable to save"); } catch { - StyledMessageBox.ShowMessageBox("Oops! Unable to save changes.", "Unable to save"); + StyledMessageBox.ShowMessageBox(null, "Oops! Unable to save changes.", "Unable to save"); } } diff --git a/PrintHistory/PrintHistoryListItem.cs b/PrintHistory/PrintHistoryListItem.cs index 4e6b6dc23..bbd752ab5 100644 --- a/PrintHistory/PrintHistoryListItem.cs +++ b/PrintHistory/PrintHistoryListItem.cs @@ -314,6 +314,7 @@ namespace MatterHackers.MatterControl.PrintHistory public void ShowCantFindFileMessage(PrintItemWrapper printItemWrapper) { + itemToRemove = printItemWrapper; UiThread.RunOnIdle((state) => { string maxLengthName = printItemWrapper.FileLocation; @@ -328,12 +329,18 @@ namespace MatterHackers.MatterControl.PrintHistory string notFoundMessage = LocalizedString.Get("Oops! Could not find this file:"); string message = "{0}:\n'{1}'".FormatWith(notFoundMessage, maxLengthName); string titleLabel = LocalizedString.Get("Item not Found"); - if (StyledMessageBox.ShowMessageBox(message, titleLabel, StyledMessageBox.MessageType.OK)) - { - QueueData.Instance.RemoveIndexOnIdle(QueueData.Instance.GetIndex(printItemWrapper)); - } + StyledMessageBox.ShowMessageBox(onConfirmRemove, message, titleLabel, StyledMessageBox.MessageType.OK); }); } + PrintItemWrapper itemToRemove; + + void onConfirmRemove(bool messageBoxResponse) + { + if (messageBoxResponse) + { + QueueData.Instance.RemoveIndexOnIdle(QueueData.Instance.GetIndex(itemToRemove)); + } + } PartPreviewMainWindow partPreviewWindow; private void OpenPartPreviewWindow(PrintItem printItem, View3DWidget.AutoRotate autoRotate) diff --git a/PrintLibrary/LibraryRowItem.cs b/PrintLibrary/LibraryRowItem.cs index 956a43a81..57a408eff 100644 --- a/PrintLibrary/LibraryRowItem.cs +++ b/PrintLibrary/LibraryRowItem.cs @@ -383,10 +383,15 @@ namespace MatterHackers.MatterControl.PrintLibrary else { string message = String.Format("Cannot find\n'{0}'.\nWould you like to remove it from the library?", pathAndFile); - if (StyledMessageBox.ShowMessageBox(message, "Item not found", StyledMessageBox.MessageType.YES_NO)) - { - libraryDataView.RemoveChild(this); - } + StyledMessageBox.ShowMessageBox(null, message, "Item not found", StyledMessageBox.MessageType.YES_NO); + } + } + + void onConfirmRemove(bool messageBoxResponse) + { + if (messageBoxResponse) + { + libraryDataView.RemoveChild(this); } } diff --git a/PrintQueue/OptionsMenu/QueueOptionsMenu.cs b/PrintQueue/OptionsMenu/QueueOptionsMenu.cs index 6bfaaa7e1..215877611 100644 --- a/PrintQueue/OptionsMenu/QueueOptionsMenu.cs +++ b/PrintQueue/OptionsMenu/QueueOptionsMenu.cs @@ -181,7 +181,7 @@ namespace MatterHackers.MatterControl.PrintQueue string pleaseSelectPrinterTitle = "Please select a printer"; void MustSelectPrinterMessage(object state) { - StyledMessageBox.ShowMessageBox(pleaseSelectPrinterMessage, pleaseSelectPrinterTitle); + StyledMessageBox.ShowMessageBox(null, pleaseSelectPrinterMessage, pleaseSelectPrinterTitle); } bool exportGCodeToFolderButton_Click() diff --git a/PrintQueue/QueueRowItem.cs b/PrintQueue/QueueRowItem.cs index 87207ef77..10603c5f6 100644 --- a/PrintQueue/QueueRowItem.cs +++ b/PrintQueue/QueueRowItem.cs @@ -517,11 +517,7 @@ namespace MatterHackers.MatterControl.PrintQueue { if (PrintItemWrapper.PrintItem.FileLocation == QueueData.SdCardFileName) { - if (StyledMessageBox.ShowMessageBox(alsoRemoveFromSdCardMessage, alsoRemoveFromSdCardTitle, StyledMessageBox.MessageType.YES_NO)) - { - // The firmware only understands the names when lowercase. - PrinterConnectionAndCommunication.Instance.DeleteFileFromSdCard(PrintItemWrapper.PrintItem.Name); - } + StyledMessageBox.ShowMessageBox(onDeleteFileConfirm, alsoRemoveFromSdCardMessage, alsoRemoveFromSdCardTitle, StyledMessageBox.MessageType.YES_NO); } int thisIndexInQueue = QueueData.Instance.GetIndex(PrintItemWrapper); @@ -529,8 +525,18 @@ namespace MatterHackers.MatterControl.PrintQueue } + void onDeleteFileConfirm(bool messageBoxResponse) + { + if (messageBoxResponse) + { + // The firmware only understands the names when lowercase. + PrinterConnectionAndCommunication.Instance.DeleteFileFromSdCard(PrintItemWrapper.PrintItem.Name); + } + } + public static void ShowCantFindFileMessage(PrintItemWrapper printItemWrapper) { + itemToRemove = printItemWrapper; UiThread.RunOnIdle((state) => { string maxLengthName = printItemWrapper.FileLocation; @@ -546,13 +552,20 @@ namespace MatterHackers.MatterControl.PrintQueue string notFoundMessageEnd = LocalizedString.Get("Would you like to remove it from the queue"); string message = "{0}:\n'{1}'\n\n{2}?".FormatWith(notFoundMessage, maxLengthName,notFoundMessageEnd); string titleLabel = LocalizedString.Get("Item not Found"); - if (StyledMessageBox.ShowMessageBox(message, titleLabel, StyledMessageBox.MessageType.YES_NO)) - { - QueueData.Instance.RemoveIndexOnIdle(QueueData.Instance.GetIndex(printItemWrapper)); - } + StyledMessageBox.ShowMessageBox(onConfirmRemove, message, titleLabel, StyledMessageBox.MessageType.YES_NO); + }); } + static PrintItemWrapper itemToRemove; + static void onConfirmRemove(bool messageBoxResponse) + { + if (messageBoxResponse) + { + QueueData.Instance.RemoveIndexOnIdle(QueueData.Instance.GetIndex(itemToRemove)); + } + } + public void ThemeChanged(object sender, EventArgs e) { if (this.isActivePrint) diff --git a/PrinterControls/TemperatureIndicator.cs b/PrinterControls/TemperatureIndicator.cs index 5e7241d49..5f2e218fd 100644 --- a/PrinterControls/TemperatureIndicator.cs +++ b/PrinterControls/TemperatureIndicator.cs @@ -525,7 +525,7 @@ namespace MatterHackers.MatterControl { string sliceSettingsNote = "Note: Slice Settings are applied before the print actually starts. Changes while printing will not effect the active print."; string message = string.Format("The extruder is currently heating and its target temperature cannot be changed until it reaches {0}°C.\n\nYou can set the starting extruder temperature in 'Slice Settings' -> 'Filament'.\n\n{1}", PrinterConnectionAndCommunication.Instance.GetTargetExtruderTemperature(extruderIndex0Based), sliceSettingsNote); - StyledMessageBox.ShowMessageBox(message, "Waiting For Extruder To Heat"); + StyledMessageBox.ShowMessageBox(null, message, "Waiting For Extruder To Heat"); } else { @@ -620,7 +620,7 @@ namespace MatterHackers.MatterControl { string sliceSettingsNote = "Note: Slice Settings are applied before the print actually starts. Changes while printing will not effect the active print."; string message = string.Format("The bed is currently heating and its target temperature cannot be changed until it reaches {0}°C.\n\nYou can set the starting bed temperature in 'Slice Settings' -> 'Filament'.\n\n{1}", PrinterConnectionAndCommunication.Instance.TargetBedTemperature, sliceSettingsNote); - StyledMessageBox.ShowMessageBox(message, "Waiting For Bed To Heat"); + StyledMessageBox.ShowMessageBox(null, message, "Waiting For Bed To Heat"); } else { diff --git a/SlicerConfiguration/ActiveSliceSettings.cs b/SlicerConfiguration/ActiveSliceSettings.cs index 71a163c78..bd23bda2d 100644 --- a/SlicerConfiguration/ActiveSliceSettings.cs +++ b/SlicerConfiguration/ActiveSliceSettings.cs @@ -747,7 +747,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration string error = LocalizedString.Get("'Layer Height' must be less than or equal to the 'Nozzle Diameter'."); string details = string.Format("Layer Height = {0}\nNozzle Diameter = {1}", LayerHeight, NozzleDiameter); string location = LocalizedString.Get("Location: 'Advanced Controls' -> 'Slice Settings' -> 'Print' -> 'Layers/Perimeters'"); - StyledMessageBox.ShowMessageBox(string.Format("{0}\n\n{1}\n\n{2}", error, details, location), "Slice Error"); + StyledMessageBox.ShowMessageBox(null, string.Format("{0}\n\n{1}\n\n{2}", error, details, location), "Slice Error"); return false; } else if (FirstLayerHeight > NozzleDiameter) @@ -755,7 +755,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration string error = LocalizedString.Get("First Layer Height' must be less than or equal to the 'Nozzle Diameter'."); string details = string.Format("First Layer Height = {0}\nNozzle Diameter = {1}", FirstLayerHeight, NozzleDiameter); string location = "Location: 'Advanced Controls' -> 'Slice Settings' -> 'Print' -> 'Layers/Perimeters'"; - StyledMessageBox.ShowMessageBox(string.Format("{0}\n\n{1}\n\n{2}", error, details, location), "Slice Error"); + StyledMessageBox.ShowMessageBox(null, string.Format("{0}\n\n{1}\n\n{2}", error, details, location), "Slice Error"); return false; } @@ -764,7 +764,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration string error = LocalizedString.Get("First Layer Extrusion Width' must be less than or equal to the 'Nozzle Diameter' * 4."); string details = string.Format("First Layer Extrusion Width = {0}\nNozzle Diameter = {1}", GetActiveValue("first_layer_extrusion_width"), NozzleDiameter); string location = "Location: 'Advanced Controls' -> 'Slice Settings' -> 'Print' -> 'Advanced' -> 'Frist Layer'"; - StyledMessageBox.ShowMessageBox(string.Format("{0}\n\n{1}\n\n{2}", error, details, location), "Slice Error"); + StyledMessageBox.ShowMessageBox(null, string.Format("{0}\n\n{1}\n\n{2}", error, details, location), "Slice Error"); return false; } @@ -773,7 +773,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration string error = "The Min Fan Speed can only go as high as 100%."; string details = string.Format("It is currently set to {0}.", MinFanSpeed); string location = "Location: 'Advanced Controls' -> 'Slice Settings' -> 'Filament' -> 'Cooling' (show all settings)"; - StyledMessageBox.ShowMessageBox(string.Format("{0}\n\n{1}\n\n{2}", error, details, location), "Slice Error"); + StyledMessageBox.ShowMessageBox(null, string.Format("{0}\n\n{1}\n\n{2}", error, details, location), "Slice Error"); return false; } @@ -782,7 +782,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration string error = "The Max Fan Speed can only go as high as 100%."; string details = string.Format("It is currently set to {0}.", MaxFanSpeed); string location = "Location: 'Advanced Controls' -> 'Slice Settings' -> 'Filament' -> 'Cooling' (show all settings)"; - StyledMessageBox.ShowMessageBox(string.Format("{0}\n\n{1}\n\n{2}", error, details, location), "Slice Error"); + StyledMessageBox.ShowMessageBox(null, string.Format("{0}\n\n{1}\n\n{2}", error, details, location), "Slice Error"); return false; } if (FillDensity < 0 || FillDensity > 1) @@ -790,7 +790,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration string error = "The Fill Density must be between 0 and 1 inclusive."; string details = string.Format("It is currently set to {0}.", FillDensity); string location = "Location: 'Advanced Controls' -> 'Slice Settings' -> 'Print' -> 'Infill'"; - StyledMessageBox.ShowMessageBox(string.Format("{0}\n\n{1}\n\n{2}", error, details, location), "Slice Error"); + StyledMessageBox.ShowMessageBox(null, string.Format("{0}\n\n{1}\n\n{2}", error, details, location), "Slice Error"); return false; } @@ -840,7 +840,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration string error = string.Format("The '{0}' must be greater than 0.", SliceSettingsOrganizer.Instance.GetSettingsData(speedSetting).PresentationName); string details = string.Format("It is currently set to {0}.", actualSpeedValueString); string location = "Location: 'Advanced Controls' -> 'Slice Settings' -> 'Print' -> 'Speed'"; - StyledMessageBox.ShowMessageBox(string.Format("{0}\n\n{1}\n\n{2}", error, details, location), "Slice Error"); + StyledMessageBox.ShowMessageBox(null, string.Format("{0}\n\n{1}\n\n{2}", error, details, location), "Slice Error"); return false; } diff --git a/Utilities/ProjectFileHandler.cs b/Utilities/ProjectFileHandler.cs index 3968f35e1..a52addfaf 100644 --- a/Utilities/ProjectFileHandler.cs +++ b/Utilities/ProjectFileHandler.cs @@ -130,7 +130,7 @@ namespace MatterHackers.MatterControl string fileNameOnly = Path.GetFileName(item.FileLocation); if (addedFileNames.Contains(fileNameOnly)) { - StyledMessageBox.ShowMessageBox(string.Format("Duplicate file name found but in a different folder '{0}'. This part will not be added to the collection.\n\n{1}", fileNameOnly, item.FileLocation), "Duplicate File"); + StyledMessageBox.ShowMessageBox(null, string.Format("Duplicate file name found but in a different folder '{0}'. This part will not be added to the collection.\n\n{1}", fileNameOnly, item.FileLocation), "Duplicate File"); continue; }