Add persistence mechanism for Part tabs

- Issue MatterHackers/MCCentral#3162
Tabs need new persistence mechanism to survive ReloadAll
This commit is contained in:
John Lewin 2018-05-03 23:00:02 -07:00
parent c21018f503
commit 3f81c5e83d
3 changed files with 25 additions and 28 deletions

View file

@ -1597,6 +1597,8 @@ namespace MatterHackers.MatterControl
public static IObject3D ClipboardItem { get; internal set; }
public Action<ILibraryItem> ShareLibraryItem { get; set; }
public List<BedConfig> Workspaces { get; } = new List<BedConfig>();
public event EventHandler<WidgetSourceEventArgs> AddPrintersTabRightElement;
public void NotifyPrintersTabRightElement(GuiWidget sourceExentionArea)

View file

@ -1,5 +1,5 @@
/*
Copyright (c) 2017, Lars Brubaker
Copyright (c) 2018, Lars Brubaker, John Lewin
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -28,19 +28,14 @@ either expressed or implied, of the FreeBSD Project.
*/
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using MatterHackers.Agg;
using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.PartPreviewWindow.PlusTab;
using MatterHackers.MatterControl.SettingsManagement;
using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.VectorMath;
using Newtonsoft.Json;
namespace MatterHackers.MatterControl.PartPreviewWindow
{
@ -165,28 +160,26 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
ApplicationController.Instance.NotifyPrintersTabRightElement(extensionArea);
// Show start page during initial application startup
{
tabControl.AddTab(
new ChromeTab("Start".Localize(), tabControl, tabControl.NewTabPage(), theme, hasClose: false)
{
MinimumSize = new Vector2(0, theme.TabButtonHeight),
Name = "Start Tab",
Padding = new BorderDouble(15, 0)
});
}
// Show fixed start page
tabControl.AddTab(
new ChromeTab("Start".Localize(), tabControl, tabControl.NewTabPage(), theme, hasClose: false)
{
MinimumSize = new Vector2(0, theme.TabButtonHeight),
Name = "Start Tab",
Padding = new BorderDouble(15, 0)
});
// Add a tab for the current printer
if (ActiveSliceSettings.Instance.PrinterSelected)
{
string tabTitle = ActiveSliceSettings.Instance.GetValue(SettingsKey.printer_name);
this.CreatePrinterTab(printer, theme, tabTitle);
}
else
{
this.CreatePrinterTab(printer, theme, printer.Settings.GetValue(SettingsKey.printer_name));
}
// ************** Restore active tabs..... ******************
// Restore active tabs
foreach (var bed in ApplicationController.Instance.Workspaces)
{
this.CreatePartTab("New Part", bed, theme);
}
}
internal ChromeTab CreatePrinterTab(PrinterConfig printer, ThemeConfig theme, string tabTitle)

View file

@ -299,18 +299,20 @@ namespace MatterHackers.MatterControl.PartPreviewWindow.PlusTab
{
UiThread.RunOnIdle(async () =>
{
BedConfig bed;
partPreviewContent.CreatePartTab(
"New Part",
bed = new BedConfig(),
theme);
var bed = new BedConfig();
await bed.LoadContent(
new EditContext()
{
ContentStore = ApplicationController.Instance.Library.PartHistory,
SourceItem = BedConfig.NewPlatingItem(ApplicationController.Instance.Library.PartHistory)
});
ApplicationController.Instance.Workspaces.Add(bed);
partPreviewContent.CreatePartTab(
"New Part",
bed,
theme);
});
};
toolbar.AddChild(emptyPlateButton);