Made the file system provider able to navigate folders.

This commit is contained in:
Lars Brubaker 2015-06-15 12:12:18 -07:00
parent d2f1ba4b22
commit c38b4de0ba
11 changed files with 185 additions and 110 deletions

View file

@ -180,12 +180,15 @@ namespace MatterHackers.MatterControl.DataStorage
public PrintItemCollection()
{ }
public PrintItemCollection(string name, string id)
public PrintItemCollection(string name, string collectionKey)
{
this.Name = name;
Key = collectionKey;
}
public string Name { get; set; }
public string Key { get; set; }
}
public class PrintItem : Entity

View file

@ -199,10 +199,22 @@ namespace MatterHackers.MatterControl.PrintLibrary
LibraryProvider.ItemRemoved.RegisterEvent(ItemRemovedFromToLibrary, ref unregisterEvents);
}
public void RebuildView()
{
AddAllItems();
}
private void AddAllItems()
{
topToBottomItemList.RemoveAllChildren();
PrintItemCollection parent = LibraryProvider.CurrentProvider.GetParentCollectionItem();
if (parent != null)
{
LibraryRowItem queueItem = new LibraryRowItemCollection(parent, this, false);
AddListItemToTopToBottom(queueItem);
}
for (int i = 0; i < LibraryProvider.CurrentProvider.CollectionCount; i++)
{
PrintItemCollection item = LibraryProvider.CurrentProvider.GetCollectionItem(i);

View file

@ -30,32 +30,33 @@ either expressed or implied, of the FreeBSD Project.
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.PartPreviewWindow;
using MatterHackers.MatterControl.PrintLibrary.Provider;
using MatterHackers.MatterControl.PrintQueue;
using MatterHackers.VectorMath;
using System;
using System.Globalization;
using System.IO;
namespace MatterHackers.MatterControl.PrintLibrary
{
public abstract class LibraryRowItem : GuiWidget
{
public RGBA_Bytes WidgetTextColor;
public RGBA_Bytes WidgetBackgroundColor;
public bool isSelectedItem = false;
private bool isHoverItem = false;
protected TextWidget partLabel;
public CheckBox selectionCheckBox;
private LinkButtonFactory linkButtonFactory = new LinkButtonFactory();
public RGBA_Bytes WidgetBackgroundColor;
public RGBA_Bytes WidgetTextColor;
protected LibraryDataView libraryDataView;
protected TextWidget partLabel;
protected SlideWidget rightButtonOverlay;
protected GuiWidget selectionCheckBoxContainer;
private bool editMode = false;
private bool isHoverItem = false;
private LinkButtonFactory linkButtonFactory = new LinkButtonFactory();
private ConditionalClickWidget primaryClickContainer;
public LibraryRowItem(LibraryDataView libraryDataView)
{
this.libraryDataView = libraryDataView;
}
private event EventHandler unregisterEvents;
public bool EditMode
{
@ -89,9 +90,52 @@ namespace MatterHackers.MatterControl.PrintLibrary
}
}
public LibraryRowItem(LibraryDataView libraryDataView)
public override void OnClosed(EventArgs e)
{
this.libraryDataView = libraryDataView;
if (unregisterEvents != null)
{
unregisterEvents(this, null);
}
base.OnClosed(e);
}
public override void OnDraw(Graphics2D graphics2D)
{
if (this.libraryDataView.EditMode)
{
selectionCheckBoxContainer.Visible = true;
rightButtonOverlay.Visible = false;
}
else
{
selectionCheckBoxContainer.Visible = false;
}
base.OnDraw(graphics2D);
if (this.isSelectedItem)
{
this.BackgroundColor = ActiveTheme.Instance.PrimaryAccentColor;
this.partLabel.TextColor = RGBA_Bytes.White;
this.selectionCheckBox.TextColor = RGBA_Bytes.White;
}
else if (this.IsHoverItem)
{
RectangleDouble Bounds = LocalBounds;
RoundedRect rectBorder = new RoundedRect(Bounds, 0);
this.BackgroundColor = RGBA_Bytes.White;
this.partLabel.TextColor = RGBA_Bytes.Black;
this.selectionCheckBox.TextColor = RGBA_Bytes.Black;
graphics2D.Render(new Stroke(rectBorder, 3), ActiveTheme.Instance.SecondaryAccentColor);
}
else
{
this.BackgroundColor = new RGBA_Bytes(255, 255, 255, 255);
this.partLabel.TextColor = RGBA_Bytes.Black;
this.selectionCheckBox.TextColor = RGBA_Bytes.Black;
}
}
protected void CreateGuiElements()
@ -145,7 +189,6 @@ namespace MatterHackers.MatterControl.PrintLibrary
}
primaryFlow.AddChild(selectionCheckBoxContainer);
primaryFlow.AddChild(GetThumbnailWidget());
primaryFlow.AddChild(middleColumn);
@ -158,7 +201,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
primaryContainer.AddChild(primaryClickContainer);
rightButtonOverlay = getItemActionButtons();
rightButtonOverlay = GetItemActionButtons();
rightButtonOverlay.Visible = false;
mainContainer.AddChild(primaryContainer);
@ -168,32 +211,27 @@ namespace MatterHackers.MatterControl.PrintLibrary
AddHandlers();
}
#region Abstract Functions
public abstract void AddToQueue();
public abstract void Edit();
public abstract void Export();
public abstract void RemoveFromCollection();
public abstract void RemoveFromParentCollection();
protected abstract SlideWidget GetItemActionButtons();
protected abstract string GetItemName();
protected abstract GuiWidget GetThumbnailWidget();
private ConditionalClickWidget primaryClickContainer;
protected abstract void RemoveThisFromPrintLibrary();
protected abstract SlideWidget getItemActionButtons();
private void SetDisplayAttributes()
{
//this.VAnchor = Agg.UI.VAnchor.FitToChildren;
this.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
if (ActiveTheme.Instance.DisplayMode == ActiveTheme.ApplicationDisplayType.Touchscreen)
{
this.Height = 65;
}
else
{
this.Height = 50;
}
this.Padding = new BorderDouble(0);
this.Margin = new BorderDouble(6, 0, 6, 6);
}
private event EventHandler unregisterEvents;
#endregion Abstract Functions
private void AddHandlers()
{
@ -217,13 +255,16 @@ namespace MatterHackers.MatterControl.PrintLibrary
//selectionCheckBox.CheckedStateChanged += selectionCheckBox_CheckedStateChanged;
}
public override void OnClosed(EventArgs e)
private void onAddLinkClick(object sender, EventArgs e)
{
if (unregisterEvents != null)
}
private void onConfirmRemove(bool messageBoxResponse)
{
if (messageBoxResponse)
{
unregisterEvents(this, null);
libraryDataView.RemoveChild(this);
}
base.OnClosed(e);
}
private void onLibraryItemClick(object sender, EventArgs e)
@ -252,6 +293,12 @@ namespace MatterHackers.MatterControl.PrintLibrary
}
}
private void onThemeChanged(object sender, EventArgs e)
{
//Set background and text color to new theme
this.Invalidate();
}
private void selectionCheckBox_CheckedStateChanged(object sender, EventArgs e)
{
if (selectionCheckBox.Checked == true)
@ -266,73 +313,21 @@ namespace MatterHackers.MatterControl.PrintLibrary
}
}
private void onAddLinkClick(object sender, EventArgs e)
private void SetDisplayAttributes()
{
}
protected abstract void RemoveThisFromPrintLibrary();
private void onConfirmRemove(bool messageBoxResponse)
{
if (messageBoxResponse)
//this.VAnchor = Agg.UI.VAnchor.FitToChildren;
this.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
if (ActiveTheme.Instance.DisplayMode == ActiveTheme.ApplicationDisplayType.Touchscreen)
{
libraryDataView.RemoveChild(this);
}
}
private void onThemeChanged(object sender, EventArgs e)
{
//Set background and text color to new theme
this.Invalidate();
}
public override void OnDraw(Graphics2D graphics2D)
{
if (this.libraryDataView.EditMode)
{
selectionCheckBoxContainer.Visible = true;
rightButtonOverlay.Visible = false;
this.Height = 65;
}
else
{
selectionCheckBoxContainer.Visible = false;
this.Height = 50;
}
base.OnDraw(graphics2D);
if (this.isSelectedItem)
{
this.BackgroundColor = ActiveTheme.Instance.PrimaryAccentColor;
this.partLabel.TextColor = RGBA_Bytes.White;
this.selectionCheckBox.TextColor = RGBA_Bytes.White;
}
else if (this.IsHoverItem)
{
RectangleDouble Bounds = LocalBounds;
RoundedRect rectBorder = new RoundedRect(Bounds, 0);
this.BackgroundColor = RGBA_Bytes.White;
this.partLabel.TextColor = RGBA_Bytes.Black;
this.selectionCheckBox.TextColor = RGBA_Bytes.Black;
graphics2D.Render(new Stroke(rectBorder, 3), ActiveTheme.Instance.SecondaryAccentColor);
}
else
{
this.BackgroundColor = new RGBA_Bytes(255, 255, 255, 255);
this.partLabel.TextColor = RGBA_Bytes.Black;
this.selectionCheckBox.TextColor = RGBA_Bytes.Black;
}
this.Padding = new BorderDouble(0);
this.Margin = new BorderDouble(6, 0, 6, 6);
}
public abstract void RemoveFromParentCollection();
public abstract void AddToQueue();
public abstract void RemoveFromCollection();
public abstract void Edit();
public abstract void Export();
}
}

View file

@ -28,6 +28,8 @@ either expressed or implied, of the FreeBSD Project.
*/
using MatterHackers.Agg;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.PlatformAbstract;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.Localizations;
@ -45,10 +47,12 @@ namespace MatterHackers.MatterControl.PrintLibrary
public class LibraryRowItemCollection : LibraryRowItem
{
PrintItemCollection collection;
bool isSubdirector;
public LibraryRowItemCollection(PrintItemCollection collection, LibraryDataView libraryDataView)
public LibraryRowItemCollection(PrintItemCollection collection, LibraryDataView libraryDataView, bool isSubdirector = true)
: base(libraryDataView)
{
this.isSubdirector = isSubdirector;
this.collection = collection;
CreateGuiElements();
}
@ -82,8 +86,16 @@ namespace MatterHackers.MatterControl.PrintLibrary
protected override GuiWidget GetThumbnailWidget()
{
PartThumbnailWidget thumbnailWidget = new PartThumbnailWidget(null, "part_icon_transparent_40x40.png", "building_thumbnail_40x40.png", PartThumbnailWidget.ImageSizes.Size50x50);
return thumbnailWidget;
string path = Path.Combine("Icons", "FileDialog", "folder.png");
if(!isSubdirector)
{
path = Path.Combine("Icons", "FileDialog", "upfolder.png");
}
ImageBuffer imageBuffer = new ImageBuffer();
StaticData.Instance.LoadImage(path, imageBuffer);
ImageWidget folderThumbnail = new ImageWidget(imageBuffer);
return folderThumbnail;
}
protected override string GetItemName()
@ -91,7 +103,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
return collection.Name;
}
protected override SlideWidget getItemActionButtons()
protected override SlideWidget GetItemActionButtons()
{
SlideWidget buttonContainer = new SlideWidget();
buttonContainer.VAnchor = VAnchor.ParentBottomTop;
@ -110,13 +122,22 @@ namespace MatterHackers.MatterControl.PrintLibrary
openButton.Width = 100;
openButton.Click += (sender, e) =>
{
throw new NotImplementedException();
if (isSubdirector)
{
LibraryProvider.CurrentProvider.SetCollectionBase(collection);
}
else
{
LibraryProvider.CurrentProvider.SetCollectionBase(LibraryProvider.CurrentProvider.GetParentCollectionItem());
}
UiThread.RunOnIdle(libraryDataView.RebuildView);
};
buttonFlowContainer.AddChild(openButton);
buttonContainer.AddChild(buttonFlowContainer);
buttonContainer.Width = 200;
buttonContainer.Width = 100;
return buttonContainer;
}

View file

@ -60,7 +60,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
private ConditionalClickWidget primaryClickContainer;
protected override SlideWidget getItemActionButtons()
protected override SlideWidget GetItemActionButtons()
{
SlideWidget buttonContainer = new SlideWidget();
buttonContainer.VAnchor = VAnchor.ParentBottomTop;

View file

@ -53,7 +53,8 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
{
// hack for the moment
currentProvider = new LibraryProviderSQLite();
//currentProvider = new LibraryProviderFileSystem(Path.Combine("C:\\", "Users", "LarsBrubaker", "Downloads"));
//PrintItemCollection collectionBase = new PrintItemCollection("Downloads", Path.Combine("C:\\", "Users", "LarsBrubaker", "Downloads"));
//currentProvider = new LibraryProviderFileSystem(collectionBase);
}
return currentProvider;
}
@ -61,6 +62,8 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
#region AbstractMethods
public abstract void SetCollectionBase(PrintItemCollection collectionBase);
public abstract int CollectionCount { get; }
public abstract int ItemCount { get; }
@ -71,6 +74,8 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
public abstract void AddFilesToLibrary(IList<string> files, ReportProgressRatio reportProgress = null, RunWorkerCompletedEventHandler callback = null);
public abstract PrintItemCollection GetParentCollectionItem();
public abstract PrintItemCollection GetCollectionItem(int collectionIndex);
public abstract PrintItemWrapper GetPrintItemWrapper(int itemIndex);

View file

@ -52,6 +52,25 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
GetFilesInCurrentDirectory();
}
public LibraryProviderFileSystem(PrintItemCollection collectionBase)
{
this.rootPath = collectionBase.Key;
GetFilesInCurrentDirectory();
}
public override void SetCollectionBase(PrintItemCollection collectionBase)
{
string collectionPath = collectionBase.Key;
int startOfCurrentDir = collectionPath.IndexOf('.');
if (startOfCurrentDir != -1)
{
this.currentDirectory = collectionPath.Substring(startOfCurrentDir);
}
GetFilesInCurrentDirectory();
}
public override int CollectionCount
{
get
@ -96,6 +115,17 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
throw new NotImplementedException();
}
public override PrintItemCollection GetParentCollectionItem()
{
if (currentDirectory != ".")
{
string parentDirectory = Path.GetDirectoryName(currentDirectory);
return new PrintItemCollection("..", parentDirectory);
}
return null;
}
public override PrintItemCollection GetCollectionItem(int collectionIndex)
{
string directoryName = currentDirectoryDirectories[collectionIndex];

View file

@ -46,6 +46,15 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
}
}
public override PrintItemCollection GetParentCollectionItem()
{
return null;
}
public override void SetCollectionBase(PrintItemCollection collectionBase)
{
}
public override int ItemCount
{
get

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB