/// <summary> /// Returns a list of subdirectories of the current directory /// </summary> public GitDirectoryInfo[] GetDirectories() { // As the subdirectories are being added, keep them sorted SortedDictionary <string, GitDirectoryInfo> dict = new SortedDictionary <string, GitDirectoryInfo>(); // For every node item in our list that represents a directory, add it // to the bucket where each represents one subdirectory node at that level foreach (string s in List) { // Pick only directories from the list and create a new directory node int index = s.IndexOf(Path.DirectorySeparatorChar); if (index > 0) { string name = s.Substring(0, index); string rest = s.Substring(index + 1); string path = Path.Combine(FullName, name); GitDirectoryInfo newDir = new GitDirectoryInfo(path, new List <string>()); if (dict.ContainsKey(name)) { newDir = dict[name]; } newDir.List.Add(rest); dict[name] = newDir; } } // Return the array of values of a sorted dictionary: // values are GitDirectoryInfo structures return(dict.Values.ToArray()); }
/// <summary> /// Returns a list of subdirectories of the current directory /// </summary> public GitDirectoryInfo[] GetDirectories() { // As the subdirectories are being added, keep them sorted SortedDictionary<string, GitDirectoryInfo> dict = new SortedDictionary<string, GitDirectoryInfo>(); // For every node item in our list that represents a directory, add it // to the bucket where each represents one subdirectory node at that level foreach (string s in List) { // Pick only directories from the list and create a new directory node int index = s.IndexOf(Path.DirectorySeparatorChar); if (index > 0) { string name = s.Substring(0, index); string rest = s.Substring(index + 1); string path = Path.Combine(FullName, name); GitDirectoryInfo newDir = new GitDirectoryInfo(path, new List<string>()); if (dict.ContainsKey(name)) newDir = dict[name]; newDir.List.Add(rest); dict[name] = newDir; } } // Return the array of values of a sorted dictionary: // values are GitDirectoryInfo structures return dict.Values.ToArray(); }
/// <summary> /// Recursive function to traverse the virtual directory of /// a flat git response files and build a visual tree component. /// </summary> /// <param name="tnRoot">Root node to base the tree on</param> /// <param name="list">List of files in git format</param> /// <param name="sortBy">File sorting order</param> private static void BuildTreeRecurse(TreeNode tnRoot, List <string> list, GitDirectoryInfo.SortBy sortBy) { string rootPath = tnRoot.Tag.ToString(); GitDirectoryInfo dir = new GitDirectoryInfo(rootPath, list); GitDirectoryInfo[] dirs = dir.GetDirectories(); foreach (GitDirectoryInfo d in dirs) { TreeNode tn = new TreeNode(d.Name); tn.Tag = d.FullName + Path.DirectorySeparatorChar; tnRoot.Nodes.Add(tn); BuildTreeRecurse(tn, d.List, sortBy); } GitFileInfo[] files = dir.GetFiles(sortBy); foreach (GitFileInfo file in files) { TreeNode tn = new TreeNode(file.Name); tn.Tag = file.FullName; tnRoot.Nodes.Add(tn); } }
/// <summary> /// Builds a flat list of tree nodes based on a given list of files /// </summary> /// <param name="tnRoot">Root node to build the list on</param> /// <param name="list">List of relative path file names</param> public static void BuildFileList(TreeNode tnRoot, List<string> list, GitDirectoryInfo.SortBy sortBy) { // Sort the list according to the sorting rule if (sortBy == GitDirectoryInfo.SortBy.Name) list.Sort(); else { var vSort = from s in list orderby Path.GetExtension(s), s ascending select s; list = vSort.ToList(); } // Build a list view); foreach (string s in list) { TreeNode tn = new TreeNode(s); tn.Tag = s; tnRoot.Nodes.Add(tn); } }
/// <summary> /// Recursive function to traverse the virtual directory of /// a flat git response files and build a visual tree component. /// </summary> /// <param name="tnRoot">Root node to base the tree on</param> /// <param name="list">List of files in git format</param> /// <param name="sortBy">File sorting order</param> private static void BuildTreeRecurse(TreeNode tnRoot, List<string> list, GitDirectoryInfo.SortBy sortBy) { string rootPath = tnRoot.Tag.ToString(); GitDirectoryInfo dir = new GitDirectoryInfo(rootPath, list); GitDirectoryInfo[] dirs = dir.GetDirectories(); foreach (GitDirectoryInfo d in dirs) { TreeNode tn = new TreeNode(d.Name); tn.Tag = d.FullName + Path.DirectorySeparatorChar; tnRoot.Nodes.Add(tn); BuildTreeRecurse(tn, d.List, sortBy); } GitFileInfo[] files = dir.GetFiles(sortBy); foreach (GitFileInfo file in files) { TreeNode tn = new TreeNode(file.Name); tn.Tag = file.FullName; tnRoot.Nodes.Add(tn); } }
/// <summary> /// Build a tree view given the list of files /// </summary> /// <param name="tnRoot">Root node to base the tree on</param> /// <param name="list">List of files in git format</param> /// <param name="sortBy">File sorting order</param> public static void BuildTree(TreeNode tnRoot, List<string> list, GitDirectoryInfo.SortBy sortBy) { BuildTreeRecurse(tnRoot, list, sortBy); }