Revise RenameButtonRenamesLocalLibraryFolder test

- Restore support for LocalLibrary -> Create Folder
- Share Selection logic between Row/Icon views
- Make folders selectable
- Improve naming of DirectoryContainerLink
This commit is contained in:
John Lewin 2017-06-03 15:11:12 -07:00
parent fce8d8b813
commit dd9e2d30b5
8 changed files with 97 additions and 113 deletions

View file

@ -410,7 +410,7 @@ namespace MatterHackers.MatterControl
if (Directory.Exists(directory))
{
this.Library.RegisterRootProvider(
new FileSystemContainer.ContainerLink(directory)
new FileSystemContainer.DirectoryContainerLink(directory)
{
UseIncrementedNameDuringTypeChange = true
});

View file

@ -168,7 +168,7 @@ namespace MatterHackers.MatterControl.Library
List<ILibraryContainerLink> containers;
if (filter == "")
{
var directories = Directory.GetDirectories(fullPath, "*.*", searchDepth).Select(p => new ContainerLink(p)).ToList<ILibraryContainerLink>();
var directories = Directory.GetDirectories(fullPath, "*.*", searchDepth).Select(p => new DirectoryContainerLink(p)).ToList<ILibraryContainerLink>();
containers = directories.Concat(zipFiles.Select(f => new LocalZipContainerLink(f))).OrderBy(d => d.Name).ToList();
}
else
@ -346,7 +346,7 @@ namespace MatterHackers.MatterControl.Library
public override void Rename(ILibraryItem item, string revisedName)
{
if (item is ContainerLink directoryLink)
if (item is DirectoryContainerLink directoryLink)
{
if (Directory.Exists(directoryLink.Path))
{
@ -378,9 +378,9 @@ namespace MatterHackers.MatterControl.Library
#endregion
public class ContainerLink : FileSystemItem, ILibraryContainerLink
public class DirectoryContainerLink : FileSystemItem, ILibraryContainerLink
{
public ContainerLink(string path)
public DirectoryContainerLink(string path)
: base(path)
{
}

View file

@ -125,65 +125,68 @@ namespace MatterHackers.MatterControl.Library
{
await Task.Run(async () =>
{
/*
* var newCollection = new PrintItemCollection(container.Name, "");
newCollection.ParentCollectionID = this.CollectionID;
newCollection.Commit();
this.ReloadContainer();
* */
foreach (var item in items.OfType<ILibraryContentStream>())
if (items.FirstOrDefault() is ILibraryContainerLink containerInfo)
{
var newCollection = new PrintItemCollection(containerInfo.Name, "");
newCollection.ParentCollectionID = this.CollectionID;
newCollection.Commit();
}
else
{
string filePath;
if (item is FileSystemFileItem)
foreach (var item in items.OfType<ILibraryContentStream>())
{
// Get existing file path
var fileItem = item as FileSystemFileItem;
filePath = fileItem.Path;
}
else
{
// Copy stream to library path
filePath = ApplicationDataStorage.Instance.GetNewLibraryFilePath("." + item.ContentType);
string filePath;
using (var outputStream = File.OpenWrite(filePath))
using (var streamInteface = await item.GetContentStream(null))
if (item is FileSystemFileItem)
{
streamInteface.Stream.CopyTo(outputStream);
}
}
if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath))
{
if (Path.GetExtension(filePath).ToUpper() == ".ZIP")
{
List<PrintItem> partFiles = ProjectFileHandler.ImportFromProjectArchive(filePath);
if (partFiles != null)
{
foreach (PrintItem part in partFiles)
{
string childFilePath = part.FileLocation;
using (var fileStream = File.OpenRead(part.FileLocation))
{
AddItem(fileStream, Path.GetExtension(childFilePath).ToUpper(), PrintItemWrapperExtensionMethods.GetFriendlyName(Path.GetFileNameWithoutExtension(childFilePath)));
}
}
}
// Get existing file path
var fileItem = item as FileSystemFileItem;
filePath = fileItem.Path;
}
else
{
using (var stream = File.OpenRead(filePath))
// Copy stream to library path
filePath = ApplicationDataStorage.Instance.GetNewLibraryFilePath("." + item.ContentType);
using (var outputStream = File.OpenWrite(filePath))
using (var streamInteface = await item.GetContentStream(null))
{
AddItem(stream, Path.GetExtension(filePath).ToUpper(), PrintItemWrapperExtensionMethods.GetFriendlyName(Path.GetFileNameWithoutExtension(filePath)));
streamInteface.Stream.CopyTo(outputStream);
}
}
if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath))
{
if (Path.GetExtension(filePath).ToUpper() == ".ZIP")
{
List<PrintItem> partFiles = ProjectFileHandler.ImportFromProjectArchive(filePath);
if (partFiles != null)
{
foreach (PrintItem part in partFiles)
{
string childFilePath = part.FileLocation;
using (var fileStream = File.OpenRead(part.FileLocation))
{
AddItem(fileStream, Path.GetExtension(childFilePath).ToUpper(), PrintItemWrapperExtensionMethods.GetFriendlyName(Path.GetFileNameWithoutExtension(childFilePath)));
}
}
}
}
else
{
using (var stream = File.OpenRead(filePath))
{
AddItem(stream, Path.GetExtension(filePath).ToUpper(), PrintItemWrapperExtensionMethods.GetFriendlyName(Path.GetFileNameWithoutExtension(filePath)));
}
}
}
}
this.ReloadContainer();
}
this.ReloadContainer();
this.OnReloaded();
});
}
@ -227,10 +230,16 @@ namespace MatterHackers.MatterControl.Library
sqliteItem.PrintItem.Name = revisedName;
sqliteItem.PrintItem.Commit();
}
else if (selectedItem is SqliteLibraryContainerLink)
else if (selectedItem is SqliteLibraryContainerLink containerLink)
{
// TODO: lookup collection by id, rename, commit, release, reload
System.Diagnostics.Debugger.Break();
string sql = $"SELECT * FROM PrintItemCollection WHERE ID = {containerLink.ContainerID}";
var container = Datastore.Instance.dbSQLite.Query<PrintItemCollection>(sql).FirstOrDefault();
if (container != null)
{
container.Name = revisedName;
container.Commit();
}
}
this.ReloadContainer();

View file

@ -28,9 +28,7 @@ either expressed or implied, of the FreeBSD Project.
*/
using System;
using System.Linq;
using MatterHackers.Agg;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.UI;
using MatterHackers.MatterControl.Library;
using MatterHackers.VectorMath;
@ -126,28 +124,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
imageWidget.Click += (sender, e) =>
{
bool isContentItem = listViewItem.Model is ILibraryContentItem;
bool isValidStream = (listViewItem.Model is ILibraryContentStream stream
&& ApplicationController.Instance.Library.IsContentFileType(stream.FileName));
if (isContentItem || isValidStream)
{
if (this.IsSelected)
{
listViewItem.ListView.SelectedItems.Remove(listViewItem);
}
else
{
if (!Keyboard.IsKeyDown(Keys.ControlKey))
{
listViewItem.ListView.SelectedItems.Clear();
}
listViewItem.ListView.SelectedItems.Add(listViewItem);
}
Invalidate();
}
this.OnItemSelect();
};
container.AddChild(imageWidget);

View file

@ -138,6 +138,33 @@ namespace MatterHackers.MatterControl.CustomWidgets
SetItemThumbnail(thumbnail);
}
internal void OnItemSelect()
{
bool isContentItem = listViewItem.Model is ILibraryContentItem;
bool isValidStream = (listViewItem.Model is ILibraryContentStream stream
&& ApplicationController.Instance.Library.IsContentFileType(stream.FileName));
bool isContainerLink = listViewItem.Model is ILibraryContainerLink;
if (isContentItem || isValidStream || isContainerLink)
{
if (this.IsSelected)
{
listViewItem.ListView.SelectedItems.Remove(listViewItem);
}
else
{
if (!Keyboard.IsKeyDown(Keys.ControlKey))
{
listViewItem.ListView.SelectedItems.Clear();
}
listViewItem.ListView.SelectedItems.Add(listViewItem);
}
Invalidate();
}
}
protected void SetItemThumbnail(ImageBuffer thumbnail, bool colorize = false)
{
if (thumbnail != null)

View file

@ -174,35 +174,9 @@ namespace MatterHackers.MatterControl.CustomWidgets
middleColumn.MouseUp += (sender, e) =>
{
if (mouseDownOnMiddle
&& listViewItem.Model is ILibraryContentItem
&& middleColumn.LocalBounds.Contains(e.Position))
{
// TODO: Resolve missing .EditMode condition
if (false /*this.libraryDataView.EditMode*/)
{
if (this.IsSelected)
{
listViewItem.ListView.SelectedItems.Remove(listViewItem);
}
else
{
listViewItem.ListView.SelectedItems.Remove(listViewItem);
}
Invalidate();
}
else
{
if (!this.IsSelected)
{
if (!Keyboard.IsKeyDown(Keys.ControlKey))
{
listViewItem.ListView.SelectedItems.Clear();
}
listViewItem.ListView.SelectedItems.Add(listViewItem);
Invalidate();
}
}
this.OnItemSelect();
}
mouseDownOnMiddle = false;

View file

@ -286,11 +286,13 @@ namespace MatterHackers.MatterControl.PrintLibrary
{
if (createFolderWindow == null)
{
createFolderWindow = new CreateFolderWindow((returnInfo) =>
createFolderWindow = new CreateFolderWindow((result) =>
{
// TODO: Implement
throw new NotImplementedException("createFolderButton click");
//this.libraryView.ActiveContainer.AddCollectionToLibrary(returnInfo.newName);
if (!string.IsNullOrEmpty(result.newName)
&& this.libraryView.ActiveContainer is ILibraryWritableContainer writableContainer)
{
writableContainer.Add(new[] { new DynamicContainerLink(result.newName, null) });
}
});
createFolderWindow.Closed += (sender2, e2) => { createFolderWindow = null; };
}

View file

@ -173,7 +173,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
[Test]
public async Task RenameButtonRenamesLocalLibraryFolder()
{
AutomationTest testToRun = (testRunner) =>
await MatterControlUtilities.RunTest((testRunner) =>
{
testRunner.CloseSignInAndPrinterSelect();
// Navigate to Local Library
@ -195,9 +195,6 @@ namespace MatterHackers.MatterControl.Tests.Automation
// Confirm newly created folder exists
Assert.IsTrue(testRunner.WaitForName("New Folder Row Item Collection", 1), "New folder should appear as GuiWidget");
testRunner.ClickByName("Library Edit Button");
testRunner.Delay(.2);
testRunner.ClickByName("New Folder Row Item Collection");
testRunner.Delay(.2);
@ -213,9 +210,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
Assert.IsTrue(testRunner.WaitForName("Renamed Library Folder Row Item Collection", 2), "Renamed folder should exist");
return Task.FromResult(0);
};
await MatterControlUtilities.RunTest(testToRun);
});
}
[Test]