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:
parent
fce8d8b813
commit
dd9e2d30b5
8 changed files with 97 additions and 113 deletions
|
|
@ -410,7 +410,7 @@ namespace MatterHackers.MatterControl
|
||||||
if (Directory.Exists(directory))
|
if (Directory.Exists(directory))
|
||||||
{
|
{
|
||||||
this.Library.RegisterRootProvider(
|
this.Library.RegisterRootProvider(
|
||||||
new FileSystemContainer.ContainerLink(directory)
|
new FileSystemContainer.DirectoryContainerLink(directory)
|
||||||
{
|
{
|
||||||
UseIncrementedNameDuringTypeChange = true
|
UseIncrementedNameDuringTypeChange = true
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -168,7 +168,7 @@ namespace MatterHackers.MatterControl.Library
|
||||||
List<ILibraryContainerLink> containers;
|
List<ILibraryContainerLink> containers;
|
||||||
if (filter == "")
|
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();
|
containers = directories.Concat(zipFiles.Select(f => new LocalZipContainerLink(f))).OrderBy(d => d.Name).ToList();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -346,7 +346,7 @@ namespace MatterHackers.MatterControl.Library
|
||||||
|
|
||||||
public override void Rename(ILibraryItem item, string revisedName)
|
public override void Rename(ILibraryItem item, string revisedName)
|
||||||
{
|
{
|
||||||
if (item is ContainerLink directoryLink)
|
if (item is DirectoryContainerLink directoryLink)
|
||||||
{
|
{
|
||||||
if (Directory.Exists(directoryLink.Path))
|
if (Directory.Exists(directoryLink.Path))
|
||||||
{
|
{
|
||||||
|
|
@ -378,9 +378,9 @@ namespace MatterHackers.MatterControl.Library
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public class ContainerLink : FileSystemItem, ILibraryContainerLink
|
public class DirectoryContainerLink : FileSystemItem, ILibraryContainerLink
|
||||||
{
|
{
|
||||||
public ContainerLink(string path)
|
public DirectoryContainerLink(string path)
|
||||||
: base(path)
|
: base(path)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -125,65 +125,68 @@ namespace MatterHackers.MatterControl.Library
|
||||||
{
|
{
|
||||||
await Task.Run(async () =>
|
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
|
string filePath;
|
||||||
var fileItem = item as FileSystemFileItem;
|
|
||||||
filePath = fileItem.Path;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Copy stream to library path
|
|
||||||
filePath = ApplicationDataStorage.Instance.GetNewLibraryFilePath("." + item.ContentType);
|
|
||||||
|
|
||||||
using (var outputStream = File.OpenWrite(filePath))
|
if (item is FileSystemFileItem)
|
||||||
using (var streamInteface = await item.GetContentStream(null))
|
|
||||||
{
|
{
|
||||||
streamInteface.Stream.CopyTo(outputStream);
|
// Get existing file path
|
||||||
}
|
var fileItem = item as FileSystemFileItem;
|
||||||
}
|
filePath = fileItem.Path;
|
||||||
|
|
||||||
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
|
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();
|
this.OnReloaded();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -227,10 +230,16 @@ namespace MatterHackers.MatterControl.Library
|
||||||
sqliteItem.PrintItem.Name = revisedName;
|
sqliteItem.PrintItem.Name = revisedName;
|
||||||
sqliteItem.PrintItem.Commit();
|
sqliteItem.PrintItem.Commit();
|
||||||
}
|
}
|
||||||
else if (selectedItem is SqliteLibraryContainerLink)
|
else if (selectedItem is SqliteLibraryContainerLink containerLink)
|
||||||
{
|
{
|
||||||
// TODO: lookup collection by id, rename, commit, release, reload
|
string sql = $"SELECT * FROM PrintItemCollection WHERE ID = {containerLink.ContainerID}";
|
||||||
System.Diagnostics.Debugger.Break();
|
|
||||||
|
var container = Datastore.Instance.dbSQLite.Query<PrintItemCollection>(sql).FirstOrDefault();
|
||||||
|
if (container != null)
|
||||||
|
{
|
||||||
|
container.Name = revisedName;
|
||||||
|
container.Commit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ReloadContainer();
|
this.ReloadContainer();
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,7 @@ either expressed or implied, of the FreeBSD Project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
|
||||||
using MatterHackers.Agg;
|
using MatterHackers.Agg;
|
||||||
using MatterHackers.Agg.Image;
|
|
||||||
using MatterHackers.Agg.UI;
|
using MatterHackers.Agg.UI;
|
||||||
using MatterHackers.MatterControl.Library;
|
using MatterHackers.MatterControl.Library;
|
||||||
using MatterHackers.VectorMath;
|
using MatterHackers.VectorMath;
|
||||||
|
|
@ -126,28 +124,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
|
||||||
|
|
||||||
imageWidget.Click += (sender, e) =>
|
imageWidget.Click += (sender, e) =>
|
||||||
{
|
{
|
||||||
bool isContentItem = listViewItem.Model is ILibraryContentItem;
|
this.OnItemSelect();
|
||||||
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();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
container.AddChild(imageWidget);
|
container.AddChild(imageWidget);
|
||||||
|
|
|
||||||
|
|
@ -138,6 +138,33 @@ namespace MatterHackers.MatterControl.CustomWidgets
|
||||||
SetItemThumbnail(thumbnail);
|
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)
|
protected void SetItemThumbnail(ImageBuffer thumbnail, bool colorize = false)
|
||||||
{
|
{
|
||||||
if (thumbnail != null)
|
if (thumbnail != null)
|
||||||
|
|
|
||||||
|
|
@ -174,35 +174,9 @@ namespace MatterHackers.MatterControl.CustomWidgets
|
||||||
middleColumn.MouseUp += (sender, e) =>
|
middleColumn.MouseUp += (sender, e) =>
|
||||||
{
|
{
|
||||||
if (mouseDownOnMiddle
|
if (mouseDownOnMiddle
|
||||||
&& listViewItem.Model is ILibraryContentItem
|
|
||||||
&& middleColumn.LocalBounds.Contains(e.Position))
|
&& middleColumn.LocalBounds.Contains(e.Position))
|
||||||
{
|
{
|
||||||
// TODO: Resolve missing .EditMode condition
|
this.OnItemSelect();
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mouseDownOnMiddle = false;
|
mouseDownOnMiddle = false;
|
||||||
|
|
|
||||||
|
|
@ -286,11 +286,13 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
||||||
{
|
{
|
||||||
if (createFolderWindow == null)
|
if (createFolderWindow == null)
|
||||||
{
|
{
|
||||||
createFolderWindow = new CreateFolderWindow((returnInfo) =>
|
createFolderWindow = new CreateFolderWindow((result) =>
|
||||||
{
|
{
|
||||||
// TODO: Implement
|
if (!string.IsNullOrEmpty(result.newName)
|
||||||
throw new NotImplementedException("createFolderButton click");
|
&& this.libraryView.ActiveContainer is ILibraryWritableContainer writableContainer)
|
||||||
//this.libraryView.ActiveContainer.AddCollectionToLibrary(returnInfo.newName);
|
{
|
||||||
|
writableContainer.Add(new[] { new DynamicContainerLink(result.newName, null) });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
createFolderWindow.Closed += (sender2, e2) => { createFolderWindow = null; };
|
createFolderWindow.Closed += (sender2, e2) => { createFolderWindow = null; };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -173,7 +173,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
|
||||||
[Test]
|
[Test]
|
||||||
public async Task RenameButtonRenamesLocalLibraryFolder()
|
public async Task RenameButtonRenamesLocalLibraryFolder()
|
||||||
{
|
{
|
||||||
AutomationTest testToRun = (testRunner) =>
|
await MatterControlUtilities.RunTest((testRunner) =>
|
||||||
{
|
{
|
||||||
testRunner.CloseSignInAndPrinterSelect();
|
testRunner.CloseSignInAndPrinterSelect();
|
||||||
// Navigate to Local Library
|
// Navigate to Local Library
|
||||||
|
|
@ -195,9 +195,6 @@ namespace MatterHackers.MatterControl.Tests.Automation
|
||||||
// Confirm newly created folder exists
|
// Confirm newly created folder exists
|
||||||
Assert.IsTrue(testRunner.WaitForName("New Folder Row Item Collection", 1), "New folder should appear as GuiWidget");
|
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.ClickByName("New Folder Row Item Collection");
|
||||||
testRunner.Delay(.2);
|
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");
|
Assert.IsTrue(testRunner.WaitForName("Renamed Library Folder Row Item Collection", 2), "Renamed folder should exist");
|
||||||
|
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
};
|
});
|
||||||
|
|
||||||
await MatterControlUtilities.RunTest(testToRun);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue