diff --git a/Library/LibraryRowItemCollection.cs b/Library/LibraryRowItemCollection.cs index 3c57bfd2a..22bf6334b 100644 --- a/Library/LibraryRowItemCollection.cs +++ b/Library/LibraryRowItemCollection.cs @@ -78,29 +78,28 @@ namespace MatterHackers.MatterControl.PrintLibrary throw new NotImplementedException(); } - private static string collectionNotEmtyMessage = "The folder you are trying to delete '{0}' is not empty. Would you like to delete it anyway?".Localize(); - private static string collectionNotEmtyTitle = "Folder not Empty".Localize(); - private static string deleteNow = "Delete".Localize(); - private static string doNotDelete = "Cancel".Localize(); + private static readonly string collectionNotEmtyMessage = "The folder '{0}' is not empty.\n\nWould you like to delete it anyway?".Localize(); + private static readonly string collectionNotEmtyTitle = "Delete folder?".Localize(); + private static readonly string deleteNow = "Delete".Localize(); + private static readonly string doNotDelete = "Cancel".Localize(); public override void RemoveFromCollection() { - // TODO: make a progress display to show that we are retieving the collection content (to check if its empty). - using (LibraryProvider collectionProvider = LibraryDataView.CurrentLibraryProvider.GetProviderForCollection(printItemCollection)) + int collectionItemCollectionCount = LibraryDataView.CurrentLibraryProvider.GetCollectionChildCollectionCount(collectionIndex); + int collectionItemItemCount = LibraryDataView.CurrentLibraryProvider.GetCollectionItemCount(collectionIndex); + + if (collectionItemCollectionCount > 0 || collectionItemItemCount > 0) { - if (collectionProvider.ItemCount > 0 || collectionProvider.CollectionCount > 0) + string message = collectionNotEmtyMessage.FormatWith(LibraryDataView.CurrentLibraryProvider.GetCollectionItem(collectionIndex).Name); + UiThread.RunOnIdle(() => { - collectionNotEmtyMessage = collectionNotEmtyMessage.FormatWith(printItemCollection.Name); - UiThread.RunOnIdle(() => - { - // Let the user know this collection is not empty and check if they want to delete it. - StyledMessageBox.ShowMessageBox(ProcessDialogResponse, collectionNotEmtyMessage, collectionNotEmtyTitle, StyledMessageBox.MessageType.YES_NO, deleteNow, doNotDelete); - }); - } - else - { - LibraryDataView.CurrentLibraryProvider.RemoveCollection(collectionIndex); - } + // Let the user know this collection is not empty and check if they want to delete it. + StyledMessageBox.ShowMessageBox(ProcessDialogResponse, message, collectionNotEmtyTitle, StyledMessageBox.MessageType.YES_NO, deleteNow, doNotDelete); + }); + } + else + { + LibraryDataView.CurrentLibraryProvider.RemoveCollection(collectionIndex); } } diff --git a/Library/Provider/LibraryProvider.cs b/Library/Provider/LibraryProvider.cs index ef7fe631f..1dbbeae5a 100644 --- a/Library/Provider/LibraryProvider.cs +++ b/Library/Provider/LibraryProvider.cs @@ -110,6 +110,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider public abstract Task GetPrintItemWrapperAsync(int itemIndex, ReportProgressRatio reportProgress = null); // TODO: make this asnyc + //public abstract Task GetProviderForCollectionAsync(PrintItemCollection collection); public abstract LibraryProvider GetProviderForCollection(PrintItemCollection collection); public abstract void RemoveCollection(int collectionIndexToRemove); @@ -149,6 +150,16 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider var printItemWrapper = GetPrintItemWrapperAsync(printItemIndex).Result; return new PartThumbnailWidget(printItemWrapper, "part_icon_transparent_40x40.png", "building_thumbnail_40x40.png", PartThumbnailWidget.ImageSizes.Size50x50); } + + public virtual int GetCollectionChildCollectionCount(int collectionIndex) + { + return GetProviderForCollection(GetCollectionItem(collectionIndex)).CollectionCount; + } + + public virtual int GetCollectionItemCount(int collectionIndex) + { + return GetProviderForCollection(GetCollectionItem(collectionIndex)).ItemCount; + } } public class ProviderLocatorNode diff --git a/Library/Provider/LibraryProviderFileSystem.cs b/Library/Provider/LibraryProviderFileSystem.cs index 67de5ce7e..af365b515 100644 --- a/Library/Provider/LibraryProviderFileSystem.cs +++ b/Library/Provider/LibraryProviderFileSystem.cs @@ -283,30 +283,42 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider private void GetFilesAndCollectionsInCurrentDirectory() { currentDirectoryDirectories.Clear(); - string[] directories = Directory.GetDirectories(Path.Combine(rootPath, currentDirectory)); - foreach (string directoryName in directories) + try { - if (keywordFilter.Trim() == string.Empty - || Path.GetFileNameWithoutExtension(directoryName).Contains(keywordFilter)) + string[] directories = Directory.GetDirectories(Path.Combine(rootPath, currentDirectory)); + foreach (string directoryName in directories) { - string subPath = directoryName.Substring(rootPath.Length + 1); - currentDirectoryDirectories.Add(subPath); + if (keywordFilter.Trim() == string.Empty + || Path.GetFileNameWithoutExtension(directoryName).Contains(keywordFilter)) + { + string subPath = directoryName.Substring(rootPath.Length + 1); + currentDirectoryDirectories.Add(subPath); + } } } + catch (Exception) + { + } currentDirectoryFiles.Clear(); - string[] files = Directory.GetFiles(Path.Combine(rootPath, currentDirectory)); - foreach (string filename in files) + try { - if (ApplicationSettings.LibraryFilterFileExtensions.Contains(Path.GetExtension(filename).ToLower())) + string[] files = Directory.GetFiles(Path.Combine(rootPath, currentDirectory)); + foreach (string filename in files) { - if (keywordFilter.Trim() == string.Empty - || Path.GetFileNameWithoutExtension(filename).Contains(keywordFilter)) + if (ApplicationSettings.LibraryFilterFileExtensions.Contains(Path.GetExtension(filename).ToLower())) { - currentDirectoryFiles.Add(filename); + if (keywordFilter.Trim() == string.Empty + || Path.GetFileNameWithoutExtension(filename).Contains(keywordFilter)) + { + currentDirectoryFiles.Add(filename); + } } } } + catch (Exception) + { + } LibraryProvider.OnDataReloaded(null); } diff --git a/StaticData/Translations/Master.txt b/StaticData/Translations/Master.txt index 951aeb9a3..422c76b88 100644 --- a/StaticData/Translations/Master.txt +++ b/StaticData/Translations/Master.txt @@ -3397,3 +3397,12 @@ Translated:The folder you are trying to delete '{0}' is not empty. Would you lik English:Folder not Empty Translated:Folder not Empty +English:The folder '{0}' is not empty.\nWould you like to delete it anyway? +Translated:The folder '{0}' is not empty.\nWould you like to delete it anyway? + +English:Delete folder? +Translated:Delete folder? + +English:The folder '{0}' is not empty.\n\nWould you like to delete it anyway? +Translated:The folder '{0}' is not empty.\n\nWould you like to delete it anyway? +