separating saving the tab bar layout and scene contents

This commit is contained in:
Lars Brubaker 2022-02-01 10:33:45 -08:00
parent 6f7271b20d
commit 66215016cd
4 changed files with 28 additions and 27 deletions

View file

@ -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();
}
};

View file

@ -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;

View file

@ -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);
}

View file

@ -299,7 +299,8 @@ namespace MatterHackers.MatterControl
var unsavedWorkspaces = new List<PartWorkspace>();
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;