From d2f6dcf8bc66360e28d4506f91c73a9e7b1beb2e Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Wed, 7 Nov 2018 14:41:11 -0800 Subject: [PATCH] Made to so we save all workspaces before exit issue: MatterHackers/MCCentral#4318 Part tab fails to persist on close --- .../ApplicationView/ApplicationController.cs | 9 +----- MatterControlLib/RootSystemWindow.cs | 30 ++++++++++++++++--- Program.cs | 1 + Submodules/MatterSlice | 2 +- Submodules/agg-sharp | 2 +- 5 files changed, 30 insertions(+), 14 deletions(-) diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index 981113924..555ee5309 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -1547,7 +1547,7 @@ namespace MatterHackers.MatterControl return mappedEditors; } - internal void Shutdown() + public void Shutdown() { // Ensure all threads shutdown gracefully on close @@ -1757,13 +1757,6 @@ namespace MatterHackers.MatterControl { this.Thumbnails.Shutdown(); - // Save changes before close - if (this.ActivePrinter != null - && this.ActivePrinter != PrinterConfig.EmptyPrinter) - { - await this.ActivePrinter.Bed.SaveChanges(null, CancellationToken.None); - } - ApplicationSettings.Instance.ReleaseClientToken(); } diff --git a/MatterControlLib/RootSystemWindow.cs b/MatterControlLib/RootSystemWindow.cs index e0a19b95e..167d46547 100644 --- a/MatterControlLib/RootSystemWindow.cs +++ b/MatterControlLib/RootSystemWindow.cs @@ -289,12 +289,34 @@ namespace MatterHackers.MatterControl StyledMessageBox.MessageType.YES_NO_WITHOUT_HIGHLIGHT); }); } - else + else if(!ApplicationController.Instance.ApplicationExiting) { - ApplicationController.Instance.ApplicationExiting = true; - // Make sure we tell the Application Controller to shut down. This will release the slicing thread if running. - ApplicationController.Instance.Shutdown(); + // cancel the close so that we can save all our active work spaces + eventArgs.Cancel = true; + + UiThread.RunOnIdle(async () => + { + var application = ApplicationController.Instance; + // Save changes before close + if (application.ActivePrinter != null + && application.ActivePrinter != PrinterConfig.EmptyPrinter) + { + await application.Tasks.Execute("Saving Print Bed".Localize() + "...", application.ActivePrinter.Bed.SaveChanges); + } + + foreach (var workspace in application.Workspaces) + { + await application.Tasks.Execute("Saving Print Bed".Localize() + "...", workspace.SceneContext.SaveChanges); + } + + application.ApplicationExiting = true; + // Make sure we tell the Application Controller to shut down. This will release the slicing thread if running. + application.Shutdown(); + this.CloseOnIdle(); + }); } + + // we are exiting and have finished saving } public override void OnClosed(EventArgs e) diff --git a/Program.cs b/Program.cs index c295ce3e7..3bf1a2fbd 100644 --- a/Program.cs +++ b/Program.cs @@ -75,6 +75,7 @@ namespace MatterHackers.MatterControl config.Bind("Agg:GraphicsMode", AggContext.Config.GraphicsMode); Slicer.RunInProcess = config.GetValue("MatterControl:Slicer:Debug"); + Slicer.RunInProcess = true; // Make sure we have the right working directory as we assume everything relative to the executable. Directory.SetCurrentDirectory(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)); diff --git a/Submodules/MatterSlice b/Submodules/MatterSlice index fafbca251..ac9ff0914 160000 --- a/Submodules/MatterSlice +++ b/Submodules/MatterSlice @@ -1 +1 @@ -Subproject commit fafbca2512fb34724eca996fc3fe4ba489b27ae7 +Subproject commit ac9ff0914ad8b0a2c379ef47657f051f4e1edfa0 diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 7af8c7cde..190c148a7 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 7af8c7cde04feba99adf51d85ac90d413bd7992b +Subproject commit 190c148a7494d0a13ee318f5f3a80dc9f6989e61