private void ReplaceArchiveWithExtractedContents(FileSystemTreeElement archiveFileSystemTreeElement, DirectoryInfo archiveExtractionDirectory) { if (archiveFileSystemTreeElement.ParentFileSystemTreeElement.IsDirectory) { FileSystemTreeElement parent = archiveFileSystemTreeElement.ParentFileSystemTreeElement; ObservableCollection <FileSystemTreeElement> parentContainigFileSystemElementCollection = parent.ChildFileSystemTreeElements; int archiveFileIndex = parentContainigFileSystemElementCollection.IndexOf(archiveFileSystemTreeElement); var archiveRepresentationNode = new FileSystemTreeElement( parent.RootFileSystemTreeElement, parent, archiveExtractionDirectory) { IsArchive = true, AlternativeIElementName = archiveFileSystemTreeElement.ElementInfo.Name.Equals(archiveExtractionDirectory.Name, StringComparison.OrdinalIgnoreCase) ? "" : archiveExtractionDirectory.Name }; List <FileSystemTreeElement> lazySubdirectories = archiveRepresentationNode.InitializeWithLazyTreeStructure(); archiveRepresentationNode.SortChildren(); FilterFileSystemTree(archiveRepresentationNode); Application.Current.Dispatcher.Invoke( () => { parentContainigFileSystemElementCollection.Insert(archiveFileIndex, archiveRepresentationNode); parentContainigFileSystemElementCollection.Remove(archiveFileSystemTreeElement); archiveFileSystemTreeElement.ParentFileSystemTreeElement.ChildFileSystemTreeElements = parentContainigFileSystemElementCollection; if (archiveRepresentationNode.IsLazyLoading) { ObserveVirtualDirectories(lazySubdirectories); } archiveRepresentationNode.IsExpanded = true; }, DispatcherPriority.Send); } }
private void LazyLoadChildren(FileSystemTreeElement directoryNode) { if (!directoryNode.HasLazyChildren) { return; } directoryNode.HasLazyChildren = false; Task.Run( () => { List <FileSystemTreeElement> lazyFileSystemElements = directoryNode.InitializeWithLazyTreeStructure(); directoryNode.SortChildren(); FilterFileSystemTree(directoryNode); if (directoryNode.IsLazyLoading) { ObserveVirtualDirectories(lazyFileSystemElements); } }).ConfigureAwait(true); }
private void AddFilePathInfoToExplorerTree([NotNull] FileSystemInfo pathInfo, bool isRootFolderExpanded) { var fileSystemTreeElement = new FileSystemTreeElement( this.VirtualExplorerRootDirectory, this.VirtualExplorerRootDirectory, pathInfo); fileSystemTreeElement.IsArchive = !fileSystemTreeElement.IsDirectory && FileExtractor.FileIsArchive(fileSystemTreeElement.ElementInfo as FileInfo); fileSystemTreeElement.IsSystemDirectory = DriveInfo.GetDrives().Any((driveInfo) => driveInfo.RootDirectory.FullName.Equals(fileSystemTreeElement.ElementInfo.FullName, StringComparison.OrdinalIgnoreCase)); if (fileSystemTreeElement.IsDirectory || fileSystemTreeElement.IsArchive) { List <FileSystemTreeElement> lazyFileSystemElements = fileSystemTreeElement.InitializeWithLazyTreeStructure(); // Observe top level tree directories 'IsExpanded' to show/ hide drag drop hint accordingly ObserveTopLevelDirectoryIsExpanded(fileSystemTreeElement); // Observe lazy children if (fileSystemTreeElement.IsLazyLoading) { ObserveVirtualDirectories(lazyFileSystemElements); fileSystemTreeElement.IsExpanded = isRootFolderExpanded && !fileSystemTreeElement.IsArchive; } } // Validate state including the new item that to this point is still not added to the tree UpdateFileSystemElementTreeState(fileSystemTreeElement); Application.Current.Dispatcher.Invoke( () => { FilterFileSystemTree(fileSystemTreeElement); this.VirtualExplorerRootDirectory.ChildFileSystemTreeElements.Add(fileSystemTreeElement); }, DispatcherPriority.Send); }