Now we can rename folders in file provider.

This commit is contained in:
larsbrubaker 2015-07-28 12:12:42 -07:00
parent 2e706a084f
commit 0aa0f7e97f
5 changed files with 40 additions and 16 deletions

View file

@ -48,12 +48,12 @@ namespace MatterHackers.MatterControl.PrintLibrary
{ {
LibraryProvider parentProvider; LibraryProvider parentProvider;
PrintItemCollection printItemCollection; PrintItemCollection printItemCollection;
int collectionIndex; public int CollectionIndex { get; private set; }
public LibraryRowItemCollection(PrintItemCollection collection, int collectionIndex, LibraryDataView libraryDataView, LibraryProvider parentProvider, GuiWidget thumbnailWidget) public LibraryRowItemCollection(PrintItemCollection collection, int collectionIndex, LibraryDataView libraryDataView, LibraryProvider parentProvider, GuiWidget thumbnailWidget)
: base(libraryDataView, thumbnailWidget) : base(libraryDataView, thumbnailWidget)
{ {
this.collectionIndex = collectionIndex; this.CollectionIndex = collectionIndex;
this.parentProvider = parentProvider; this.parentProvider = parentProvider;
this.printItemCollection = collection; this.printItemCollection = collection;
this.ItemName = printItemCollection.Name; this.ItemName = printItemCollection.Name;
@ -85,12 +85,12 @@ namespace MatterHackers.MatterControl.PrintLibrary
public override void RemoveFromCollection() public override void RemoveFromCollection()
{ {
int collectionItemCollectionCount = LibraryDataView.CurrentLibraryProvider.GetCollectionChildCollectionCount(collectionIndex); int collectionItemCollectionCount = LibraryDataView.CurrentLibraryProvider.GetCollectionChildCollectionCount(CollectionIndex);
int collectionItemItemCount = LibraryDataView.CurrentLibraryProvider.GetCollectionItemCount(collectionIndex); int collectionItemItemCount = LibraryDataView.CurrentLibraryProvider.GetCollectionItemCount(CollectionIndex);
if (collectionItemCollectionCount > 0 || collectionItemItemCount > 0) if (collectionItemCollectionCount > 0 || collectionItemItemCount > 0)
{ {
string message = collectionNotEmtyMessage.FormatWith(LibraryDataView.CurrentLibraryProvider.GetCollectionItem(collectionIndex).Name); string message = collectionNotEmtyMessage.FormatWith(LibraryDataView.CurrentLibraryProvider.GetCollectionItem(CollectionIndex).Name);
UiThread.RunOnIdle(() => UiThread.RunOnIdle(() =>
{ {
// Let the user know this collection is not empty and check if they want to delete it. // Let the user know this collection is not empty and check if they want to delete it.
@ -99,7 +99,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
} }
else else
{ {
LibraryDataView.CurrentLibraryProvider.RemoveCollection(collectionIndex); LibraryDataView.CurrentLibraryProvider.RemoveCollection(CollectionIndex);
} }
} }
@ -107,7 +107,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
{ {
if (messageBoxResponse) if (messageBoxResponse)
{ {
LibraryDataView.CurrentLibraryProvider.RemoveCollection(collectionIndex); LibraryDataView.CurrentLibraryProvider.RemoveCollection(CollectionIndex);
} }
} }

View file

@ -53,7 +53,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
{ {
public bool isActivePrint = false; public bool isActivePrint = false;
LibraryProvider libraryProvider; LibraryProvider libraryProvider;
private int itemIndex; public int ItemIndex { get; private set; }
double thumbnailWidth = 0; double thumbnailWidth = 0;
public PrintItemWrapper printItemInstance = null; public PrintItemWrapper printItemInstance = null;
@ -73,7 +73,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
this.ItemName = libraryProvider.GetPrintItemName(itemIndex); this.ItemName = libraryProvider.GetPrintItemName(itemIndex);
this.libraryProvider = libraryProvider; this.libraryProvider = libraryProvider;
this.itemIndex = itemIndex; this.ItemIndex = itemIndex;
CreateGuiElements(); CreateGuiElements();
@ -84,7 +84,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
{ {
get get
{ {
return libraryProvider.IsItemProtected(itemIndex); return libraryProvider.IsItemProtected(ItemIndex);
} }
} }
@ -92,7 +92,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
{ {
if (printItemInstance == null) if (printItemInstance == null)
{ {
printItemInstance = await libraryProvider.GetPrintItemWrapperAsync(this.itemIndex, ReportProgressRatio); printItemInstance = await libraryProvider.GetPrintItemWrapperAsync(this.ItemIndex, ReportProgressRatio);
} }
return printItemInstance; return printItemInstance;
@ -223,7 +223,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
public async override void RemoveFromCollection() public async override void RemoveFromCollection()
{ {
LibraryDataView.CurrentLibraryProvider.RemoveItem(itemIndex); LibraryDataView.CurrentLibraryProvider.RemoveItem(ItemIndex);
} }
protected override SlideWidget GetItemActionButtons() protected override SlideWidget GetItemActionButtons()
@ -287,7 +287,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
protected async override void RemoveThisFromPrintLibrary() protected async override void RemoveThisFromPrintLibrary()
{ {
// TODO: The LibraryProvider does not need a printitemwrapper to remove an item! Why not an interger like the others? // TODO: The LibraryProvider does not need a printitemwrapper to remove an item! Why not an interger like the others?
LibraryDataView.CurrentLibraryProvider.RemoveItem(itemIndex); LibraryDataView.CurrentLibraryProvider.RemoveItem(ItemIndex);
} }
private void ExportQueueItemWindow_Closed(object sender, EventArgs e) private void ExportQueueItemWindow_Closed(object sender, EventArgs e)

View file

@ -281,9 +281,24 @@ namespace MatterHackers.MatterControl.PrintLibrary
{ {
if (renameItemWindow == null) if (renameItemWindow == null)
{ {
string currentName = "currentName"; LibraryRowItem rowItem = libraryDataView.SelectedItems[0];
LibraryRowItemPart partItem = rowItem as LibraryRowItemPart;
LibraryRowItemCollection collectionItem = rowItem as LibraryRowItemCollection;
string currentName = libraryDataView.SelectedItems[0].ItemName;
renameItemWindow = new RenameItemWindow(currentName, (returnInfo) => renameItemWindow = new RenameItemWindow(currentName, (returnInfo) =>
{ {
if (partItem != null)
{
LibraryDataView.CurrentLibraryProvider.RenameItem(partItem.ItemIndex, returnInfo.newName);
}
else if (collectionItem != null)
{
LibraryDataView.CurrentLibraryProvider.RenameCollection(collectionItem.CollectionIndex, returnInfo.newName);
}
libraryDataView.SelectedItems.Clear();
}); });
renameItemWindow.Closed += (sender2, e2) => { renameItemWindow = null; }; renameItemWindow.Closed += (sender2, e2) => { renameItemWindow = null; };

View file

@ -191,7 +191,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
string sourceDir = Path.Combine(rootPath, currentDirectoryDirectories[collectionIndexToRename]); string sourceDir = Path.Combine(rootPath, currentDirectoryDirectories[collectionIndexToRename]);
if (Directory.Exists(sourceDir)) if (Directory.Exists(sourceDir))
{ {
string destDir = Path.Combine(Path.GetDirectoryName(sourceDir), sourceDir); string destDir = Path.Combine(Path.GetDirectoryName(sourceDir), newName);
Directory.Move(sourceDir, destDir); Directory.Move(sourceDir, destDir);
Stopwatch time = Stopwatch.StartNew(); Stopwatch time = Stopwatch.StartNew();
// Wait for up to some amount of time for the directory to be gone. // Wait for up to some amount of time for the directory to be gone.

View file

@ -3430,3 +3430,12 @@ Translated:Cloud Library
English:Rename English:Rename
Translated:Rename Translated:Rename
English:Rename Item:
Translated:Rename Item:
English:New Name
Translated:New Name
English:Enter New Name Here
Translated:Enter New Name Here