diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index aa54b777f..e2abfea59 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -289,20 +289,8 @@ namespace MatterHackers.MatterControl } } - public async Task PersistUserWorkspaceTabs(bool savePrinterScenes) + public void PersistOpenTabsLayout() { - if (savePrinterScenes) - { - // Persist all pending changes in all workspaces to disk - foreach (var workspace in this.Workspaces.ToArray()) - { - if (workspace.Printer != null) - { - await this.Tasks.Execute("Saving".Localize() + $" \"{workspace.Name}\" ...", workspace, workspace.SceneContext.SaveChanges); - } - } - } - // Project workspace definitions to serializable structure var workspaces = this.Workspaces .Where(w => w.SceneContext?.EditContext?.SourceFilePath?.Contains("\\Library\\CloudData") == false) @@ -333,11 +321,24 @@ namespace MatterHackers.MatterControl { NullValueHandling = NullValueHandling.Ignore }); - // Persist workspace definitions to disk + + // Persist workspace definition to disk File.WriteAllText(ProfileManager.Instance.OpenTabsPath, content); } } + public async Task PersistPrintTabsContent() + { + // Persist all pending changes in all workspaces to disk + foreach (var workspace in this.Workspaces.ToArray()) + { + if (workspace.Printer != null) + { + await this.Tasks.Execute("Saving".Localize() + $" \"{workspace.Name}\" ...", workspace, workspace.SceneContext.SaveChanges); + } + } + } + internal void ExportAsMatterControlConfig(PrinterConfig printer) { AggContext.FileDialogs.SaveFileDialog( @@ -454,10 +455,7 @@ namespace MatterHackers.MatterControl if (operationType != WorkspacesChangedEventArgs.OperationType.Restore) { - UiThread.RunOnIdle(async () => - { - await Instance.PersistUserWorkspaceTabs(true); - }); + Instance.PersistOpenTabsLayout(); } } @@ -952,7 +950,7 @@ namespace MatterHackers.MatterControl { if (!restoringWorkspaces) { - UiThread.RunOnIdle(async () => await PersistUserWorkspaceTabs(false)); + PersistOpenTabsLayout(); } }; diff --git a/MatterControlLib/PartPreviewWindow/MainViewWidget.cs b/MatterControlLib/PartPreviewWindow/MainViewWidget.cs index 0a843539a..4ec2e1358 100644 --- a/MatterControlLib/PartPreviewWindow/MainViewWidget.cs +++ b/MatterControlLib/PartPreviewWindow/MainViewWidget.cs @@ -584,10 +584,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow if (sourceItem != null) { - async void UpdateTabName(object s, EventArgs e) + void UpdateTabName(object s, EventArgs e) { partTab.Title = sourceItem.Name; - await ApplicationController.Instance.PersistUserWorkspaceTabs(false); + ApplicationController.Instance.PersistOpenTabsLayout(); } sourceItem.NameChanged += UpdateTabName; diff --git a/MatterControlLib/PartPreviewWindow/Tabs.cs b/MatterControlLib/PartPreviewWindow/Tabs.cs index 6860a5cc5..81ee9386c 100644 --- a/MatterControlLib/PartPreviewWindow/Tabs.cs +++ b/MatterControlLib/PartPreviewWindow/Tabs.cs @@ -475,16 +475,18 @@ namespace MatterHackers.MatterControl.PartPreviewWindow UiThread.RunOnIdle(async () => { await ApplicationController.Instance.Tasks.Execute("Saving Changes".Localize(), this, partTab.Workspace.SceneContext.SaveChanges); - this.parentTabControl.CloseTab(this); this.CloseClicked?.Invoke(this, null); + // Must be called after CloseClicked otherwise listeners are cleared before event is invoked + this.parentTabControl.CloseTab(this); }); break; case StyledMessageBox.ResponseType.NO: - UiThread.RunOnIdle(async () => + UiThread.RunOnIdle(() => { - this.parentTabControl.CloseTab(this); this.CloseClicked?.Invoke(this, null); + // Must be called after CloseClicked otherwise listeners are cleared before event is invoked + this.parentTabControl.CloseTab(this); }); break; } @@ -498,7 +500,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow else { this.CloseClicked?.Invoke(this, null); - // Must be called after CloseClicked otherwise listeners are cleared before event is invoked this.parentTabControl?.CloseTab(this); } diff --git a/MatterControlLib/RootSystemWindow.cs b/MatterControlLib/RootSystemWindow.cs index 5007dcb5f..9bfdd9ab7 100644 --- a/MatterControlLib/RootSystemWindow.cs +++ b/MatterControlLib/RootSystemWindow.cs @@ -299,7 +299,8 @@ namespace MatterHackers.MatterControl var unsavedWorkspaces = new List(); foreach (var workspace in ApplicationController.Instance.Workspaces) { - if (workspace.SceneContext?.Scene?.HasUnsavedChanges == true) + if (workspace.SceneContext?.Scene?.HasUnsavedChanges == true + && workspace.Printer == null) { unsavedWorkspaces.Add(workspace); } @@ -314,7 +315,8 @@ namespace MatterHackers.MatterControl { var application = ApplicationController.Instance; - await ApplicationController.Instance.PersistUserWorkspaceTabs(true); + ApplicationController.Instance.PersistOpenTabsLayout(); + await ApplicationController.Instance.PersistPrintTabsContent(); application.ApplicationExiting = true;