public void UpdateEntries(IList <GitStatusEntry> newEntries) { // Handle the empty list scenario if (!newEntries.Any()) { entries.Clear(); entryCommitTargets.Clear(); tree = null; foldedTreeEntries.Clear(); OnCommitTreeChange(); return; } // Remove what got nuked for (var index = 0; index < entries.Count;) { if (!newEntries.Contains(entries[index])) { entries.RemoveAt(index); entryCommitTargets.RemoveAt(index); } else { index++; } } // Remove folding state of nuked items for (var index = 0; index < foldedTreeEntries.Count;) { if (!newEntries.Any(e => e.Path.IndexOf(foldedTreeEntries[index]) == 0)) { foldedTreeEntries.RemoveAt(index); } else { index++; } } // Add new stuff for (var index = 0; index < newEntries.Count; ++index) { var entry = newEntries[index]; if (!entries.Contains(entry)) { entries.Add(entry); entryCommitTargets.Add(new GitCommitTarget()); } } // TODO: Filter .meta files - consider adding them as children of the asset or folder they're supporting // TODO: In stead of completely rebuilding the tree structure, figure out a way to migrate open/closed states from the old tree to the new // Build tree structure tree = new FileTreeNode(FileSystemHelpers.FindCommonPath(entries.Select(e => e.Path)), stateChangeCallback); tree.RepositoryPath = tree.Path; for (var index = 0; index < entries.Count; index++) { var entryPath = entries[index].Path.ToNPath(); if (entryPath.IsChildOf(tree.Path)) { entryPath = entryPath.RelativeTo(tree.Path.ToNPath()); } var node = new FileTreeNode(entryPath, stateChangeCallback) { Target = entryCommitTargets[index] }; if (!string.IsNullOrEmpty(entries[index].ProjectPath)) { node.Icon = AssetDatabase.GetCachedIcon(entries[index].ProjectPath); } BuildTree(tree, node); } OnCommitTreeChange(); }
internal static FileTreeNode BuildTreeRoot(IList <GitStatusEntry> newEntries, List <GitStatusEntry> gitStatusEntries, List <GitCommitTarget> gitCommitTargets, List <string> foldedTreeEntries, Func <string, object> iconLoaderFunc = null) { Guard.ArgumentNotNullOrEmpty(newEntries, "newEntries"); var newEntriesSetByPath = new HashSet <string>(newEntries.Select(entry => entry.Path)); var gitStatusEntriesSetByPath = new HashSet <string>(gitStatusEntries.Select(entry => entry.Path)); // Remove what got nuked for (var index = 0; index < gitStatusEntries.Count;) { if (!newEntriesSetByPath.Contains(gitStatusEntries[index].Path)) { gitStatusEntries.RemoveAt(index); gitCommitTargets.RemoveAt(index); } else { index++; } } // Remove folding state of nuked items for (var index = 0; index < foldedTreeEntries.Count;) { if (newEntries.All(e => e.Path.IndexOf(foldedTreeEntries[index], StringComparison.CurrentCulture) != 0)) { foldedTreeEntries.RemoveAt(index); } else { index++; } } var foldedTreeSet = new HashSet <string>(foldedTreeEntries); // Add new stuff for (var index = 0; index < newEntries.Count; ++index) { var entry = newEntries[index]; if (!gitStatusEntriesSetByPath.Contains(entry.Path)) { gitStatusEntries.Add(entry); gitCommitTargets.Add(new GitCommitTarget()); } } // TODO: Filter .meta files - consider adding them as children of the asset or folder they're supporting // TODO: In stead of completely rebuilding the tree structure, figure out a way to migrate open/closed states from the old tree to the new // Build tree structure var tree = new FileTreeNode(FileSystemHelpers.FindCommonPath(gitStatusEntries.Select(e => e.Path))); tree.RepositoryPath = tree.Path; for (var index1 = 0; index1 < gitStatusEntries.Count; index1++) { var gitStatusEntry = gitStatusEntries[index1]; var entryPath = gitStatusEntry.Path.ToNPath(); if (entryPath.IsChildOf(tree.Path)) { entryPath = entryPath.RelativeTo(tree.Path.ToNPath()); } var node = new FileTreeNode(entryPath) { Target = gitCommitTargets[index1] }; if (!String.IsNullOrEmpty(gitStatusEntry.ProjectPath)) { node.Icon = iconLoaderFunc?.Invoke(gitStatusEntry.ProjectPath); } BuildChildNode(tree, node, foldedTreeSet); } return(tree); }