From a1e6fb6fd9252f76076876634436f212eb74291c Mon Sep 17 00:00:00 2001 From: John Lewin Date: Mon, 14 May 2018 14:36:06 -0700 Subject: [PATCH 1/5] Reset ActiveContainer to RootContainer on ReloadAll if Cloud based - Issue MatterHackers/MCCentral#3364 Opened CloudLibrary folder not refreshed on sign out/in as new user --- ApplicationView/ApplicationController.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ApplicationView/ApplicationController.cs b/ApplicationView/ApplicationController.cs index 774326d02..8a9f2eb35 100644 --- a/ApplicationView/ApplicationController.cs +++ b/ApplicationView/ApplicationController.cs @@ -1167,6 +1167,13 @@ namespace MatterHackers.MatterControl AppContext.RootSystemWindow.AddChild(reloadingOverlay); + var library = ApplicationController.Instance.Library; + + if (library.ActiveContainer.GetType().Name.IndexOf("CloudLibrary", StringComparison.OrdinalIgnoreCase) != -1) + { + library.ActiveContainer = library.RootLibaryContainer; + } + this.IsReloading = true; UiThread.RunOnIdle(() => From 7f2cf2ecae36a3e0932a8b5dec96a1c542ba0217 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Mon, 14 May 2018 16:42:04 -0700 Subject: [PATCH 2/5] Select file (if applicable) when shelling to Explorer.exe - Issue MatterHackers/MCCentral#3372 On FileSystemContainer delete, ensure focus is moved to selected item --- .../Providers/FileSystem/FileSystemContainer.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Library/Providers/FileSystem/FileSystemContainer.cs b/Library/Providers/FileSystem/FileSystemContainer.cs index e9591a37f..00742634e 100644 --- a/Library/Providers/FileSystem/FileSystemContainer.cs +++ b/Library/Providers/FileSystem/FileSystemContainer.cs @@ -204,7 +204,7 @@ namespace MatterHackers.MatterControl.Library private string GetNonCollidingName(string fileName) { // Switching from .stl, .obj or similar to AMF. Save the file and update the - // the filename with an incremented (n) value to reflect the extension change in the UI + // the filename with an incremented (n) value to reflect the extension change in the UI var similarFileNames = Directory.GetFiles(this.fullPath, $"{Path.GetFileNameWithoutExtension(fileName)}.*"); // ; @@ -281,7 +281,18 @@ namespace MatterHackers.MatterControl.Library public override void Remove(IEnumerable items) { // Removing content from the filesystem can have devastating effects - open a shell window allowing the customer make changes as they seem fit - Process.Start(this.fullPath); + if (AggContext.OperatingSystem == OSType.Windows) + { + if (items.Count() == 1 + && items.FirstOrDefault() is FileSystemFileItem fileItem) + { + Process.Start("explorer.exe", $"/select, \"{fileItem.Path}\""); + } + else + { + Process.Start(this.fullPath); + } + } } public override void Rename(ILibraryItem item, string revisedName) From 6b64a36b6c92e4c3136052c5fc95cc4a7411a0ec Mon Sep 17 00:00:00 2001 From: John Lewin Date: Mon, 14 May 2018 17:00:00 -0700 Subject: [PATCH 3/5] Use FileSystemContainer base on history containers - Issue MatterHackers/MCCentral#3368 Add common FileSystemContainer delete logic to PlatingHistoryContainer --- .../FileSystem/FileSystemContainer.cs | 30 ++++++------- .../MatterControl/PartHistoryContainer.cs | 9 +--- .../MatterControl/PlatingHistoryContainer.cs | 43 +++---------------- 3 files changed, 22 insertions(+), 60 deletions(-) diff --git a/Library/Providers/FileSystem/FileSystemContainer.cs b/Library/Providers/FileSystem/FileSystemContainer.cs index 00742634e..563279462 100644 --- a/Library/Providers/FileSystem/FileSystemContainer.cs +++ b/Library/Providers/FileSystem/FileSystemContainer.cs @@ -41,17 +41,15 @@ namespace MatterHackers.MatterControl.Library { public class FileSystemContainer : WritableContainer { - private string fullPath; - private FileSystemWatcher directoryWatcher; private bool isActiveContainer; private bool isDirty; - public FileSystemContainer(string path) + public FileSystemContainer(string fullPath) { - this.fullPath = path; - this.Name = Path.GetFileName(path); + this.FullPath = fullPath; + this.Name = Path.GetFileName(fullPath); this.IsProtected = false; @@ -59,9 +57,9 @@ namespace MatterHackers.MatterControl.Library this.Items = new List(); #if !__ANDROID__ if (AggContext.OperatingSystem == OSType.Windows - && Directory.Exists(path)) + && Directory.Exists(fullPath)) { - directoryWatcher = new FileSystemWatcher(path); + directoryWatcher = new FileSystemWatcher(fullPath); directoryWatcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName; directoryWatcher.Changed += DirectoryContentsChanged; directoryWatcher.Created += DirectoryContentsChanged; @@ -75,6 +73,8 @@ namespace MatterHackers.MatterControl.Library #endif } + public string FullPath { get; protected set; } + // Indicates if the new AMF file should use the original file name incremented until no name collision occurs public bool UseIncrementedNameDuringTypeChange { get; internal set; } @@ -142,7 +142,7 @@ namespace MatterHackers.MatterControl.Library { string filter = this.KeywordFilter.Trim(); - var allFiles = Directory.GetFiles(fullPath, "*.*", searchDepth); + var allFiles = Directory.GetFiles(FullPath, "*.*", searchDepth); var zipFiles = allFiles.Where(f => Path.GetExtension(f).IndexOf(".zip", StringComparison.OrdinalIgnoreCase) != -1); @@ -151,7 +151,7 @@ namespace MatterHackers.MatterControl.Library List containers; if (filter == "") { - var directories = Directory.GetDirectories(fullPath, "*.*", searchDepth).Select(p => new DirectoryContainerLink(p)).ToList(); + var directories = Directory.GetDirectories(FullPath, "*.*", searchDepth).Select(p => new DirectoryContainerLink(p)).ToList(); containers = directories.Concat(zipFiles.Select(f => new LocalZipContainerLink(f))).OrderBy(d => d.Name).ToList(); } else @@ -205,7 +205,7 @@ namespace MatterHackers.MatterControl.Library { // Switching from .stl, .obj or similar to AMF. Save the file and update the // the filename with an incremented (n) value to reflect the extension change in the UI - var similarFileNames = Directory.GetFiles(this.fullPath, $"{Path.GetFileNameWithoutExtension(fileName)}.*"); + var similarFileNames = Directory.GetFiles(this.FullPath, $"{Path.GetFileNameWithoutExtension(fileName)}.*"); // ; var validName = agg_basics.GetNonCollidingName(fileName, (testName) => !File.Exists(testName)); @@ -222,7 +222,7 @@ namespace MatterHackers.MatterControl.Library directoryWatcher.EnableRaisingEvents = false; - Directory.CreateDirectory(this.fullPath); + Directory.CreateDirectory(this.FullPath); await Task.Run(async () => { @@ -231,7 +231,7 @@ namespace MatterHackers.MatterControl.Library switch (item) { case CreateFolderItem newFolder: - string targetFolderPath = Path.Combine(this.fullPath, newFolder.Name); + string targetFolderPath = Path.Combine(this.FullPath, newFolder.Name); // TODO: write adaption of GetNonCollidingName for directories Directory.CreateDirectory(targetFolderPath); @@ -240,7 +240,7 @@ namespace MatterHackers.MatterControl.Library break; case ILibraryAssetStream streamItem: - string targetPath = Path.Combine(this.fullPath, streamItem.FileName); + string targetPath = Path.Combine(this.FullPath, streamItem.FileName); try { @@ -290,7 +290,7 @@ namespace MatterHackers.MatterControl.Library } else { - Process.Start(this.fullPath); + Process.Start(this.FullPath); } } } @@ -301,7 +301,7 @@ namespace MatterHackers.MatterControl.Library { if (Directory.Exists(directoryLink.Path)) { - Process.Start(this.fullPath); + Process.Start(this.FullPath); } } else if (item is FileSystemFileItem fileItem) diff --git a/Library/Providers/MatterControl/PartHistoryContainer.cs b/Library/Providers/MatterControl/PartHistoryContainer.cs index 95192d68e..dca721880 100644 --- a/Library/Providers/MatterControl/PartHistoryContainer.cs +++ b/Library/Providers/MatterControl/PartHistoryContainer.cs @@ -27,13 +27,6 @@ of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project. */ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using MatterHackers.Agg.Image; -using MatterHackers.Agg.Platform; -using MatterHackers.DataConverters3D; using MatterHackers.Localizations; using MatterHackers.MatterControl.DataStorage; @@ -43,9 +36,9 @@ namespace MatterHackers.MatterControl.Library public class PartHistoryContainer : HistoryContainerBase { public PartHistoryContainer() + :base (ApplicationDataStorage.Instance.PartHistoryDirectory) { this.Name = "Part History".Localize(); - this.FullPath = ApplicationDataStorage.Instance.PartHistoryDirectory; } } } diff --git a/Library/Providers/MatterControl/PlatingHistoryContainer.cs b/Library/Providers/MatterControl/PlatingHistoryContainer.cs index bb0a8b389..630e3692c 100644 --- a/Library/Providers/MatterControl/PlatingHistoryContainer.cs +++ b/Library/Providers/MatterControl/PlatingHistoryContainer.cs @@ -32,7 +32,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; using MatterHackers.Agg.Image; -using MatterHackers.DataConverters3D; using MatterHackers.Localizations; using MatterHackers.MatterControl.DataStorage; @@ -40,32 +39,27 @@ namespace MatterHackers.MatterControl.Library { public class PlatingHistoryContainer : HistoryContainerBase { - public PlatingHistoryContainer() + public PlatingHistoryContainer(): + base (ApplicationDataStorage.Instance.PlatingDirectory) { this.Name = "Plating History".Localize(); - this.FullPath = ApplicationDataStorage.Instance.PlatingDirectory; } } - public class HistoryContainerBase : LibraryContainer, ILibraryWritableContainer + public class HistoryContainerBase : FileSystemContainer, ILibraryWritableContainer { - public HistoryContainerBase() + public HistoryContainerBase(string fullPath) + : base(fullPath) { this.ChildContainers = new List(); this.Items = new List(); + this.IsProtected = true; } - public string FullPath { get; protected set; } - public int PageSize { get; set; } = 25; public event EventHandler ItemContentChanged; - public void Add(IEnumerable items) - { - throw new NotImplementedException(); - } - public bool AllowAction(ContainerActions containerActions) { switch(containerActions) @@ -93,31 +87,6 @@ namespace MatterHackers.MatterControl.Library } } - public void Move(IEnumerable items, ILibraryWritableContainer targetContainer) - { - throw new NotImplementedException(); - } - - public void Remove(IEnumerable items) - { - throw new NotImplementedException(); - } - - public void Rename(ILibraryItem item, string revisedName) - { - throw new NotImplementedException(); - } - - public void Save(ILibraryItem item, IObject3D content) - { - if (item is FileSystemFileItem fileItem) - { - // Serialize the scene to disk using a modified Json.net pipeline with custom ContractResolvers and JsonConverters - File.WriteAllText(fileItem.Path, content.ToJson()); - this.ItemContentChanged?.Invoke(this, new ItemChangedEventArgs(fileItem)); - } - } - public void SetThumbnail(ILibraryItem item, int width, int height, ImageBuffer imageBuffer) { } From 1631327dc0246154bdf99c98d1cdfb88f1eff1b3 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Mon, 14 May 2018 17:25:20 -0700 Subject: [PATCH 4/5] Only fire ReloadContent after threshold elapsed --- .../Providers/FileSystem/FileSystemContainer.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Library/Providers/FileSystem/FileSystemContainer.cs b/Library/Providers/FileSystem/FileSystemContainer.cs index 563279462..3f51fa725 100644 --- a/Library/Providers/FileSystem/FileSystemContainer.cs +++ b/Library/Providers/FileSystem/FileSystemContainer.cs @@ -117,14 +117,29 @@ namespace MatterHackers.MatterControl.Library } } + long lastTimeContentsChanged; + RunningInterval waitingForRefresh; private void DirectoryContentsChanged(object sender, EventArgs e) { // Flag for reload isDirty = true; + lastTimeContentsChanged = UiThread.CurrentTimerMs; // Only refresh content if we're the active container - if (isActiveContainer) + if (isActiveContainer + && waitingForRefresh == null) { + waitingForRefresh = UiThread.SetInterval(WaitToRefresh, .5); + } + } + + private void WaitToRefresh() + { + if (UiThread.CurrentTimerMs > lastTimeContentsChanged + 500 + && waitingForRefresh != null) + { + waitingForRefresh.Continue = false; + waitingForRefresh = null; this.ReloadContent(); } } From 9915f7bd5f089ada749279c8844efd06f985a13b Mon Sep 17 00:00:00 2001 From: John Lewin Date: Mon, 14 May 2018 17:36:39 -0700 Subject: [PATCH 5/5] Skip removal confirmation in FileSystemContainers - User must manually remove anyway - Issue MatterHackers/MCCentral#3373 Skip removal validation on FileSystemContainer children --- Library/Widgets/PrintLibraryWidget.cs | 36 ++++++++++++++++----------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/Library/Widgets/PrintLibraryWidget.cs b/Library/Widgets/PrintLibraryWidget.cs index 0cdad656e..5583aca4e 100644 --- a/Library/Widgets/PrintLibraryWidget.cs +++ b/Library/Widgets/PrintLibraryWidget.cs @@ -838,23 +838,29 @@ namespace MatterHackers.MatterControl.PrintLibrary var libraryItems = libraryView.SelectedItems.Select(p => p.Model); if (libraryItems.Any()) { - var container = libraryView.ActiveContainer as ILibraryWritableContainer; - if (container != null) + if (libraryView.ActiveContainer is ILibraryWritableContainer container) { - StyledMessageBox.ShowMessageBox( - (doDelete) => - { - if (doDelete) + if (container is FileSystemContainer) + { + container.Remove(libraryItems); + libraryView.SelectedItems.Clear(); + } + else + { + StyledMessageBox.ShowMessageBox( + (doDelete) => { - container.Remove(libraryItems); - libraryView.SelectedItems.Clear(); - } - }, - "Are you sure you want to remove the currently selected items?".Localize(), - "Remove Items?".Localize(), - StyledMessageBox.MessageType.YES_NO, - "Remove".Localize()); - + if (doDelete) + { + container.Remove(libraryItems); + libraryView.SelectedItems.Clear(); + } + }, + "Are you sure you want to remove the currently selected items?".Localize(), + "Remove Items?".Localize(), + StyledMessageBox.MessageType.YES_NO, + "Remove".Localize()); + } } } }