diff --git a/MatterControl.csproj b/MatterControl.csproj index 0be41b5f6..608abbd39 100644 --- a/MatterControl.csproj +++ b/MatterControl.csproj @@ -207,6 +207,7 @@ + diff --git a/PrintLibrary/LibraryDataView.cs b/PrintLibrary/LibraryDataView.cs index dec09bb71..1c6056748 100644 --- a/PrintLibrary/LibraryDataView.cs +++ b/PrintLibrary/LibraryDataView.cs @@ -41,15 +41,6 @@ namespace MatterHackers.MatterControl.PrintLibrary { private event EventHandler unregisterEvents; - private void SetDisplayAttributes() - { - this.MinimumSize = new Vector2(0, 200); - this.AnchorAll(); - this.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor; - this.AutoScroll = true; - this.ScrollArea.Padding = new BorderDouble(3, 3, 15, 3); - } - private bool editMode = false; public bool EditMode @@ -183,12 +174,18 @@ namespace MatterHackers.MatterControl.PrintLibrary public LibraryDataView() { - SetDisplayAttributes(); - ScrollArea.HAnchor |= Agg.UI.HAnchor.ParentLeftRight; + // set the display attributes + { + this.AnchorAll(); + this.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor; + this.ScrollArea.Padding = new BorderDouble(3, 3, 5, 3); + } + + ScrollArea.HAnchor = HAnchor.ParentLeftRight; AutoScroll = true; topToBottomItemList = new FlowLayoutWidget(FlowDirection.TopToBottom); - topToBottomItemList.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth; + topToBottomItemList.HAnchor = HAnchor.ParentLeftRight; AddChild(topToBottomItemList); AddAllItems(); @@ -250,13 +247,24 @@ namespace MatterHackers.MatterControl.PrintLibrary IndexArgs addedIndexArgs = e as IndexArgs; PrintItemWrapper item = LibraryProvider.Instance.GetPrintItemWrapper(addedIndexArgs.Index); LibraryRowItem libraryItem = new LibraryRowItemPart(item, this); - AddListItemToTopToBottom(libraryItem, addedIndexArgs.Index); + + int displayIndexToAdd = addedIndexArgs.Index + LibraryProvider.Instance.CollectionCount; + if (LibraryProvider.Instance.HasParent) + { + displayIndexToAdd++; + } + AddListItemToTopToBottom(libraryItem, displayIndexToAdd); } private void ItemRemovedFromToLibrary(object sender, EventArgs e) { IndexArgs removeIndexArgs = e as IndexArgs; - topToBottomItemList.RemoveChild(removeIndexArgs.Index); + int indexToRemove = removeIndexArgs.Index + LibraryProvider.Instance.CollectionCount; + if (LibraryProvider.Instance.HasParent) + { + indexToRemove++; + } + topToBottomItemList.RemoveChild(indexToRemove); if (LibraryProvider.Instance.ItemCount > 0) { diff --git a/PrintLibrary/LibraryRowItemCollection.cs b/PrintLibrary/LibraryRowItemCollection.cs index ec6c33b62..188dd5292 100644 --- a/PrintLibrary/LibraryRowItemCollection.cs +++ b/PrintLibrary/LibraryRowItemCollection.cs @@ -122,16 +122,7 @@ namespace MatterHackers.MatterControl.PrintLibrary openButton.Width = 100; openButton.Click += (sender, e) => { - if (isSubdirector) - { - LibraryProvider.Instance.SetCollectionBase(collection); - } - else - { - LibraryProvider.Instance.SetCollectionBase(LibraryProvider.Instance.GetParentCollectionItem()); - } - - UiThread.RunOnIdle(libraryDataView.RebuildView); + ChangeCollection(); }; buttonFlowContainer.AddChild(openButton); @@ -142,6 +133,29 @@ namespace MatterHackers.MatterControl.PrintLibrary return buttonContainer; } + private void ChangeCollection() + { + if (isSubdirector) + { + LibraryProvider.Instance.SetCollectionBase(collection); + } + else + { + LibraryProvider.Instance.SetCollectionBase(LibraryProvider.Instance.GetParentCollectionItem()); + } + + UiThread.RunOnIdle(libraryDataView.RebuildView); + } + + public override void OnMouseDown(MouseEventArgs mouseEvent) + { + if (mouseEvent.Clicks == 2) + { + UiThread.RunOnIdle(ChangeCollection); + } + base.OnMouseDown(mouseEvent); + } + private void SetDisplayAttributes() { //this.VAnchor = Agg.UI.VAnchor.FitToChildren; diff --git a/PrintLibrary/LibraryRowItemPart.cs b/PrintLibrary/LibraryRowItemPart.cs index f1f865e5c..83eb9aa7f 100644 --- a/PrintLibrary/LibraryRowItemPart.cs +++ b/PrintLibrary/LibraryRowItemPart.cs @@ -58,8 +58,6 @@ namespace MatterHackers.MatterControl.PrintLibrary CreateGuiElements(); } - private ConditionalClickWidget primaryClickContainer; - protected override SlideWidget GetItemActionButtons() { SlideWidget buttonContainer = new SlideWidget(); @@ -258,6 +256,19 @@ namespace MatterHackers.MatterControl.PrintLibrary UiThread.RunOnIdle(() => openPartView()); } + public override void OnMouseDown(MouseEventArgs mouseEvent) + { + if (mouseEvent.Clicks == 2) + { + UiThread.RunOnIdle(() => + { + openPartView(View3DWidget.OpenMode.Viewing); + }); + } + base.OnMouseDown(mouseEvent); + } + + private void onViewPartClick(object sender, EventArgs e) { UiThread.RunOnIdle(() => diff --git a/PrintLibrary/Provider/LibraryProvider.cs b/PrintLibrary/Provider/LibraryProvider.cs index 9fbdb0baf..ed81107ac 100644 --- a/PrintLibrary/Provider/LibraryProvider.cs +++ b/PrintLibrary/Provider/LibraryProvider.cs @@ -50,8 +50,8 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider { if (instance == null) { - instance = new LibraryProviderSQLite(null); - //instance = new LibraryProviderSelector(); + //instance = new LibraryProviderSQLite(null); + instance = new LibraryProviderSelector(); } return instance; @@ -62,7 +62,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider public abstract bool HasParent { get; } - public abstract string Key { get; } + public abstract string ProviderTypeKey { get; } public abstract string Name { get; } @@ -104,16 +104,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider public static void OnItemRemoved(EventArgs eventArgs) { - IndexArgs removeIndexArgs = eventArgs as IndexArgs; - if (removeIndexArgs != null) - { - int numIndicesToSkip = Instance.CollectionCount; - if (Instance.HasParent) - { - numIndicesToSkip++; - } - ItemRemoved.CallEvents(Instance, new IndexArgs(removeIndexArgs.Index + numIndicesToSkip)); - } + ItemRemoved.CallEvents(Instance, eventArgs); } public static void SetCurrent(LibraryProvider current) diff --git a/PrintLibrary/Provider/LibraryProviderFactory.cs b/PrintLibrary/Provider/LibraryProviderFactory.cs new file mode 100644 index 000000000..b7be38a0a --- /dev/null +++ b/PrintLibrary/Provider/LibraryProviderFactory.cs @@ -0,0 +1,46 @@ +/* +Copyright (c) 2015, Lars Brubaker +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +The views and conclusions contained in the software and documentation are those +of the authors and should not be interpreted as representing official policies, +either expressed or implied, of the FreeBSD Project. +*/ + +using MatterHackers.Agg; +using MatterHackers.MatterControl.DataStorage; +using MatterHackers.MatterControl.PrintQueue; +using System; +using System.Collections.Generic; +using System.ComponentModel; + +namespace MatterHackers.MatterControl.PrintLibrary.Provider +{ + public class LibraryProviderFactory + { + virtual public LibraryProvider CreateProvider(string parentKey) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/PrintLibrary/Provider/LibraryProviderFileSystem.cs b/PrintLibrary/Provider/LibraryProviderFileSystem.cs index 1097d3dbf..e432462da 100644 --- a/PrintLibrary/Provider/LibraryProviderFileSystem.cs +++ b/PrintLibrary/Provider/LibraryProviderFileSystem.cs @@ -99,11 +99,11 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider } } - public override string Key + public override string ProviderTypeKey { get { - return "LibraryProvider_" + key.ToString(); + return "LibraryProvider_" + key.ToString() + "_Key"; } } diff --git a/PrintLibrary/Provider/LibraryProviderSelector.cs b/PrintLibrary/Provider/LibraryProviderSelector.cs index a63f923b0..b8fcb91d2 100644 --- a/PrintLibrary/Provider/LibraryProviderSelector.cs +++ b/PrintLibrary/Provider/LibraryProviderSelector.cs @@ -45,14 +45,22 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider public LibraryProviderSelector() { // put in the sqlite provider - LibraryProviderSQLite localStore = new LibraryProviderSQLite(Key); + LibraryProviderSQLite localStore = new LibraryProviderSQLite(this.ProviderTypeKey); libraryProviders.Add(localStore); // and any directory providers (sd card provider, etc...) - PrintItemCollection collectionBase = new PrintItemCollection("Downloads", Path.Combine("C:\\", "Users", "LarsBrubaker", "Downloads")); - libraryProviders.Add(new LibraryProviderFileSystem(collectionBase, "Downloads", Key)); + PrintItemCollection downloadsCollection = new PrintItemCollection("Downloads", Path.Combine("C:\\", "Users", "LarsBrubaker", "Downloads")); + libraryProviders.Add(new LibraryProviderFileSystem(downloadsCollection, "Downloads", this.ProviderTypeKey)); + + PrintItemCollection libraryCollection = new PrintItemCollection("Library Folder1", Path.Combine("C:\\", "Users", "LarsBrubaker", "AppData", "Local", "MatterControl", "Library")); + libraryProviders.Add(new LibraryProviderFileSystem(libraryCollection, "Library Folder2", this.ProviderTypeKey)); // Check for LibraryProvider factories and put them in the list too. + PluginFinder libraryFactories = new PluginFinder(); + foreach (LibraryProviderFactory factory in libraryFactories.Plugins) + { + libraryProviders.Add(factory.CreateProvider(this.ProviderTypeKey)); + } } #region Overriden Abstract Methods @@ -142,7 +150,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider if (selectedLibraryProvider == -1) { LibraryProvider provider = libraryProviders[collectionIndex]; - return new PrintItemCollection(provider.Name, provider.Key); + return new PrintItemCollection(provider.Name, provider.ProviderTypeKey); } else { @@ -150,11 +158,11 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider } } - public override string Key + public override string ProviderTypeKey { get { - return "LibraryProviderSelector"; + return "LibraryProviderSelectorKey"; } } @@ -231,7 +239,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider public override void SetCollectionBase(PrintItemCollection collectionBase) { - if (collectionBase.Key == Key) + if (collectionBase.Key == this.ProviderTypeKey) { selectedLibraryProvider = -1; return; @@ -240,7 +248,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider bool wasSet = false; for (int i = 0; i < libraryProviders.Count; i++) { - if (libraryProviders[i].Key == collectionBase.Key) + if (libraryProviders[i].ProviderTypeKey == collectionBase.Key) { selectedLibraryProvider = i; wasSet = true; diff --git a/PrintLibrary/Provider/LibraryProviderSqlite.cs b/PrintLibrary/Provider/LibraryProviderSqlite.cs index 8cab8a65d..21a7545f9 100644 --- a/PrintLibrary/Provider/LibraryProviderSqlite.cs +++ b/PrintLibrary/Provider/LibraryProviderSqlite.cs @@ -74,11 +74,11 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider } } - public override string Key + public override string ProviderTypeKey { get { - return "LibraryProviderSqlite"; + return "LibraryProviderSqliteKey"; } } diff --git a/Submodules/MatterSlice b/Submodules/MatterSlice index 364e78d56..7cb9ab4a0 160000 --- a/Submodules/MatterSlice +++ b/Submodules/MatterSlice @@ -1 +1 @@ -Subproject commit 364e78d56bd188c3f081166c755bf72c46de5c32 +Subproject commit 7cb9ab4a02c6233ed9a5c83690528336847a2ace