public static FileTree ForDirectory(string rootDirectory) { FileTree root = new FileTree(rootDirectory); foreach (string file in Directory.EnumerateFileSystemEntries(rootDirectory, "*", SearchOption.AllDirectories)) { string[] parts = file.Split('/', '\\'); bool skip = false; bool isFile = File.Exists(file); int fileNameParts = isFile ? 1 : 0; for (int i = 1; !skip && i < parts.Length - fileNameParts; ++i) { if (DirectoryIgnoreList.Contains(parts[i], StringComparer.OrdinalIgnoreCase)) { skip = true; } } if (!skip) { root.GetModelFor(file, isFile); } } root.SortChildren(); return(root); }
public IgnoreTreeModel(string rootDirectory, string pattern) { this._pattern = pattern.TrimStart('/', '\\', '!'); this.TreeRoot = FileTree.ForDirectory(rootDirectory); this.ShouldBeVisible = this.CheckVisibility; this.IsSearchMatch = f => true; this.NodeFilter = this.FilterNodes; this.FileCount = this.TreeRoot.AllFiles.Count(x => x.IsFile && this.ShouldBeVisible(x)); this.SearchIcon = WpfUtil.GetIconForImageMoniker(KnownMonikers.Search, 16, 16); this.ShowAllFilesIcon = WpfUtil.GetIconForImageMoniker(KnownMonikers.ShowAllFiles, 16, 16); this.SyncToSolutionExplorerIcon = WpfUtil.GetIconForImageMoniker(KnownMonikers.Sync, 16, 16); }
public FileTreeModel(string fullPath, FileTree root, bool isFile) { this.IsExpanded = true; this._children = new List <FileTreeModel>(); this.Root = root; this.Name = Path.GetFileName(fullPath); this.IsFile = isFile; this.FullPath = fullPath; int lastSlash = fullPath.LastIndexOfAny(new[] { '/', '\\' }); //Normally this would be -1, but if the path starts with / or \, we don't want to make an empty entry if (lastSlash > 0) { string parentFullPath = fullPath.Substring(0, lastSlash).Trim('/', '\\'); if (!string.IsNullOrEmpty(parentFullPath)) { this.Parent = root.GetModelFor(parentFullPath, false); this.Parent?.Children?.Add(this); } } }