Merge pull request #3315 from jlewin/design_tools

Reset ActiveContainer to RootContainer on ReloadAll if Cloud based
This commit is contained in:
johnlewin 2018-05-15 07:45:37 -07:00 committed by GitHub
commit 6c778e0a98
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 78 additions and 77 deletions

View file

@ -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(() =>

View file

@ -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<ILibraryItem>();
#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; }
@ -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();
}
}
@ -142,7 +157,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 +166,7 @@ namespace MatterHackers.MatterControl.Library
List<ILibraryContainerLink> containers;
if (filter == "")
{
var directories = Directory.GetDirectories(fullPath, "*.*", searchDepth).Select(p => new DirectoryContainerLink(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
@ -204,8 +219,8 @@ 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
var similarFileNames = Directory.GetFiles(this.fullPath, $"{Path.GetFileNameWithoutExtension(fileName)}.*");
// 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 validName = agg_basics.GetNonCollidingName(fileName, (testName) => !File.Exists(testName));
@ -222,7 +237,7 @@ namespace MatterHackers.MatterControl.Library
directoryWatcher.EnableRaisingEvents = false;
Directory.CreateDirectory(this.fullPath);
Directory.CreateDirectory(this.FullPath);
await Task.Run(async () =>
{
@ -231,7 +246,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 +255,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
{
@ -281,7 +296,18 @@ namespace MatterHackers.MatterControl.Library
public override void Remove(IEnumerable<ILibraryItem> 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)
@ -290,7 +316,7 @@ namespace MatterHackers.MatterControl.Library
{
if (Directory.Exists(directoryLink.Path))
{
Process.Start(this.fullPath);
Process.Start(this.FullPath);
}
}
else if (item is FileSystemFileItem fileItem)

View file

@ -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;
}
}
}

View file

@ -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<ILibraryContainerLink>();
this.Items = new List<ILibraryItem>();
this.IsProtected = true;
}
public string FullPath { get; protected set; }
public int PageSize { get; set; } = 25;
public event EventHandler<ItemChangedEventArgs> ItemContentChanged;
public void Add(IEnumerable<ILibraryItem> items)
{
throw new NotImplementedException();
}
public bool AllowAction(ContainerActions containerActions)
{
switch(containerActions)
@ -93,31 +87,6 @@ namespace MatterHackers.MatterControl.Library
}
}
public void Move(IEnumerable<ILibraryItem> items, ILibraryWritableContainer targetContainer)
{
throw new NotImplementedException();
}
public void Remove(IEnumerable<ILibraryItem> 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)
{
}

View file

@ -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());
}
}
}
}