From c8433b1cfa2acb27d5bb2b7dc400ce7a89266e75 Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Thu, 18 Jun 2015 18:06:04 -0700 Subject: [PATCH] Renamed GetBreadCrumbs to Get ProviderLocator Made in return a list of nodes rather than a string made the data store this as json --- DataStorage/Models.cs | 6 +-- PartPreviewWindow/View3D/View3DWidget.cs | 2 +- PrintLibrary/PrintLibraryWidget.cs | 38 +++++++++---------- PrintLibrary/Provider/LibraryProvider.cs | 14 ++++++- .../Provider/LibraryProviderFileSystem.cs | 32 +++------------- .../Provider/LibraryProviderSelector.cs | 31 +++++++-------- .../Provider/LibraryProviderSqlite.cs | 2 +- 7 files changed, 56 insertions(+), 69 deletions(-) diff --git a/DataStorage/Models.cs b/DataStorage/Models.cs index 5285edf4d..52d9d3327 100644 --- a/DataStorage/Models.cs +++ b/DataStorage/Models.cs @@ -199,7 +199,7 @@ namespace MatterHackers.MatterControl.DataStorage public string Name { get; set; } - public string LibraryProviderBreadCrumbs { get; set; } + public string LibraryProviderLocatorJson { get; set; } public string FileLocation { get; set; } @@ -212,11 +212,11 @@ namespace MatterHackers.MatterControl.DataStorage { } - public PrintItem(string name, string fileLocation, string libraryProviderBreadCrumbs = "") + public PrintItem(string name, string fileLocation, string libraryProviderLocatorJson = "") { this.Name = name; this.FileLocation = fileLocation; - this.LibraryProviderBreadCrumbs = libraryProviderBreadCrumbs; + this.LibraryProviderLocatorJson = libraryProviderLocatorJson; DateAdded = DateTime.Now; PrintCount = 0; diff --git a/PartPreviewWindow/View3D/View3DWidget.cs b/PartPreviewWindow/View3D/View3DWidget.cs index c3bc27459..ef57b8122 100644 --- a/PartPreviewWindow/View3D/View3DWidget.cs +++ b/PartPreviewWindow/View3D/View3DWidget.cs @@ -1872,7 +1872,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow } saveSucceded = true; - //LibraryProvider.Instance.SaveToCollection(printItemWrapper.PrintItem.LibraryProviderBreadCrumbs + //LibraryProvider.Instance.SaveToCollection(printItemWrapper.PrintItem.LibraryProviderLocator LibrarySQLiteData.SaveToLibraryFolder(printItemWrapper, asynchMeshGroups, true); } catch (System.UnauthorizedAccessException) diff --git a/PrintLibrary/PrintLibraryWidget.cs b/PrintLibrary/PrintLibraryWidget.cs index 34caf3e2d..dd040c10c 100644 --- a/PrintLibrary/PrintLibraryWidget.cs +++ b/PrintLibrary/PrintLibraryWidget.cs @@ -31,9 +31,8 @@ using MatterHackers.Agg; using MatterHackers.Agg.UI; using MatterHackers.Localizations; using MatterHackers.MatterControl.CustomWidgets; -using MatterHackers.MatterControl.PrintQueue; -using MatterHackers.PolygonMesh.Processors; using MatterHackers.MatterControl.PrintLibrary.Provider; +using MatterHackers.PolygonMesh.Processors; using MatterHackers.VectorMath; using System; using System.Collections.Generic; @@ -48,7 +47,7 @@ namespace MatterHackers.MatterControl.PrintLibrary private TextImageButtonFactory editButtonFactory = new TextImageButtonFactory(); private TextWidget navigationLabel; private TextWidget breadCrumbDisplay; - + private FlowLayoutWidget itemOperationButtons; private List editOperationMultiCapable = new List(); @@ -93,7 +92,7 @@ namespace MatterHackers.MatterControl.PrintLibrary enterEditModeButton = editButtonFactory.Generate("Edit".Localize(), centerText: true); enterEditModeButton.Click += enterEditModeButtonClick; } - + leaveEditModeButton.Visible = false; FlowLayoutWidget searchPanel = new FlowLayoutWidget(); @@ -149,7 +148,7 @@ namespace MatterHackers.MatterControl.PrintLibrary spacer.HAnchor = HAnchor.ParentLeftRight; buttonPanel.AddChild(spacer); } - + CreateEditBarButtons(); breadCrumbDisplay = new TextWidget(""); @@ -207,6 +206,7 @@ namespace MatterHackers.MatterControl.PrintLibrary } private event EventHandler unregisterEvents; + private void AddHandlers() { libraryDataView.SelectedItems.OnAdd += onLibraryItemsSelected; @@ -216,27 +216,23 @@ namespace MatterHackers.MatterControl.PrintLibrary private void CollectionChanged(object sender, EventArgs e) { - string breadCrumbs = LibraryProvider.Instance.GetBreadCrumbs(); + List providerLocator = LibraryProvider.Instance.GetProviderLocator(); StringBuilder path = new StringBuilder(); - string[] splitOnBar = breadCrumbs.Split('|'); - if (splitOnBar.Length > 1) + bool first = true; + foreach (ProviderLocatorNode node in providerLocator) { - bool first = true; - foreach (string split in splitOnBar) + if (!first) { - if (!first) - { - path.Append("->"); - } - string[] splitOnComma = split.Split(','); - if (splitOnComma.Length > 1 - && splitOnComma[1] != "..") - { - path.Append(splitOnComma[1]); - first = false; - } + path.Append("->"); + } + + if (node.Name != "..") + { + path.Append(node.Name); + first = false; } } + breadCrumbDisplay.Text = path.ToString(); } diff --git a/PrintLibrary/Provider/LibraryProvider.cs b/PrintLibrary/Provider/LibraryProvider.cs index fd244ea39..ff69b6842 100644 --- a/PrintLibrary/Provider/LibraryProvider.cs +++ b/PrintLibrary/Provider/LibraryProvider.cs @@ -36,6 +36,18 @@ using System.ComponentModel; namespace MatterHackers.MatterControl.PrintLibrary.Provider { + public class ProviderLocatorNode + { + public string Key; + public string Name; + + public ProviderLocatorNode(string key, string name) + { + this.Key = key; + this.Name = name; + } + } + public abstract class LibraryProvider { public static RootedObjectEventHandler CollectionChanged = new RootedObjectEventHandler(); @@ -77,7 +89,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider public abstract void AddFilesToLibrary(IList files, ReportProgressRatio reportProgress = null, RunWorkerCompletedEventHandler callback = null); // A key,value list that threads into the current collection looks like "key0,displayName0|key1,displayName1|key2,displayName2|...|keyN,displayNameN". - public abstract string GetBreadCrumbs(); + public abstract List GetProviderLocator(); public abstract PrintItemCollection GetCollectionItem(int collectionIndex); diff --git a/PrintLibrary/Provider/LibraryProviderFileSystem.cs b/PrintLibrary/Provider/LibraryProviderFileSystem.cs index 5cdb9ee26..a466d71de 100644 --- a/PrintLibrary/Provider/LibraryProviderFileSystem.cs +++ b/PrintLibrary/Provider/LibraryProviderFileSystem.cs @@ -30,6 +30,7 @@ either expressed or implied, of the FreeBSD Project. using MatterHackers.Agg; using MatterHackers.MatterControl.DataStorage; using MatterHackers.MatterControl.PrintQueue; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.ComponentModel; @@ -127,33 +128,9 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider throw new NotImplementedException(); } - public override string GetBreadCrumbs() + public override List GetProviderLocator() { throw new NotImplementedException(); - - // append all of the collection keys with names - string addDirectory = currentDirectory; - List collectionKeys = new List(); - while (addDirectory != ".") - { - collectionKeys.Add(addDirectory); - addDirectory = Path.GetDirectoryName(addDirectory); - } - - string total = ""; - bool first = true; - for(int i = collectionKeys.Count-1; i>=0; i--) - { - string key = collectionKeys[i]; - if (!first) - { - total += "|"; - } - total += key + "," + Path.GetFileName(key); - first = false; - } - - return total; } public override PrintItemCollection GetCollectionItem(int collectionIndex) @@ -185,8 +162,9 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider public override PrintItemWrapper GetPrintItemWrapper(int itemIndex) { string fileName = currentDirectoryFiles[itemIndex]; - string breadCrumbs = LibraryProvider.Instance.GetBreadCrumbs(); - return new PrintItemWrapper(new DataStorage.PrintItem(Path.GetFileNameWithoutExtension(fileName), fileName, breadCrumbs)); + List providerLocator = LibraryProvider.Instance.GetProviderLocator(); + string providerLocatorJson = JsonConvert.SerializeObject(providerLocator); + return new PrintItemWrapper(new DataStorage.PrintItem(Path.GetFileNameWithoutExtension(fileName), fileName, providerLocatorJson)); } public override void RemoveCollection(string collectionName) diff --git a/PrintLibrary/Provider/LibraryProviderSelector.cs b/PrintLibrary/Provider/LibraryProviderSelector.cs index a2fa13b71..8610c809b 100644 --- a/PrintLibrary/Provider/LibraryProviderSelector.cs +++ b/PrintLibrary/Provider/LibraryProviderSelector.cs @@ -31,6 +31,7 @@ using MatterHackers.Agg; using MatterHackers.MatterControl.DataStorage; using MatterHackers.MatterControl.PrintQueue; using System; +using Newtonsoft.Json; using System.Collections.Generic; using System.ComponentModel; using System.IO; @@ -64,12 +65,12 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider libraryProviders.Add(factory.CreateProvider(this.ProviderKey)); } - breadCrumbStack.Add(new PrintItemCollection("..", ProviderKey)); + providerLocationStack.Add(new PrintItemCollection("..", ProviderKey)); } #region Overriden Abstract Methods - private List breadCrumbStack = new List(); + private List providerLocationStack = new List(); public override int CollectionCount { @@ -183,32 +184,32 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider } // A key,value list that threads into the current collection loos like "key0,displayName0|key1,displayName1|key2,displayName2|...|keyN,displayNameN". - public override string GetBreadCrumbs() + public override List GetProviderLocator() { if (selectedLibraryProvider == -1) { - return ""; + return new List(); } else { - StringBuilder breadCrumbString = new StringBuilder(); + List providerPathNodes = new List(); bool first = true; - for (int i = 0; i < breadCrumbStack.Count; i++) + for (int i = 0; i < providerLocationStack.Count; i++) { - PrintItemCollection collection = breadCrumbStack[i]; + PrintItemCollection collection = providerLocationStack[i]; if (first) { - breadCrumbString.Append("{0},{1}".FormatWith(collection.Key, collection.Name)); + providerPathNodes.Add(new ProviderLocatorNode(collection.Key, collection.Name)); first = false; } else { - breadCrumbString.Append("|{0},{1}".FormatWith(collection.Key, collection.Name)); + providerPathNodes.Add(new ProviderLocatorNode(collection.Key, collection.Name)); } } - return breadCrumbString.ToString(); + return providerPathNodes; } } @@ -281,18 +282,18 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider { // This logic may need to be move legitamately into the virtual functions of the providers rather than all // gathered up here. If you find that this is not working the way you want ask me. LBB - if ((breadCrumbStack.Count > 2 - && collectionBase.Key == breadCrumbStack[breadCrumbStack.Count - 2].Key) - || (breadCrumbStack.Count > 1 + if ((providerLocationStack.Count > 2 + && collectionBase.Key == providerLocationStack[providerLocationStack.Count - 2].Key) + || (providerLocationStack.Count > 1 && selectedLibraryProvider != -1 && collectionBase.Key == libraryProviders[selectedLibraryProvider].GetParentCollectionItem().Key) ) { - breadCrumbStack.RemoveAt(breadCrumbStack.Count - 1); + providerLocationStack.RemoveAt(providerLocationStack.Count - 1); } else { - breadCrumbStack.Add(collectionBase); + providerLocationStack.Add(collectionBase); } if (collectionBase.Key == this.ProviderKey) diff --git a/PrintLibrary/Provider/LibraryProviderSqlite.cs b/PrintLibrary/Provider/LibraryProviderSqlite.cs index 81383ecac..7dab2a02a 100644 --- a/PrintLibrary/Provider/LibraryProviderSqlite.cs +++ b/PrintLibrary/Provider/LibraryProviderSqlite.cs @@ -137,7 +137,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider LibrarySQLiteData.Instance.LoadFilesIntoLibrary(files, reportProgress, callback); } - public override string GetBreadCrumbs() + public override List GetProviderLocator() { throw new NotImplementedException(); }