void InsertIntoTree(GrhTreeView treeView) { Remove(); var folder = GrhTreeViewFolderNode.Create(treeView, GrhData.Categorization.Category.ToString()); folder.Nodes.Add(this); }
/// <summary> /// Deletes a node from the tree, along with any node under it. /// </summary> /// <param name="root">Root node to delete.</param> static void DeleteNode(GrhTreeViewFolderNode root) { if (root == null) { return; } var toDelete = root.GetChildGrhDataNodes(true).ToImmutable(); Debug.Assert(!toDelete.HasDuplicates()); foreach (var node in toDelete) { DeleteNode(node); } }
public GrhTreeViewFolderNode FindFolder(string category) { var delimiters = new string[] { SpriteCategorization.Delimiter }; var categoryParts = category.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); GrhTreeViewFolderNode current = null; var currentColl = Nodes; for (var i = 0; i < categoryParts.Length; i++) { var subCategory = categoryParts[i]; current = currentColl.OfType <GrhTreeViewFolderNode>().FirstOrDefault(x => x.SubCategory == subCategory); if (current == null) { return(null); } currentColl = current.Nodes; } return(current); }
/// <summary> /// Creates a <see cref="GrhTreeViewFolderNode"/>. /// </summary> /// <param name="treeView">The <see cref="TreeView"/> to add the node to.</param> /// <param name="category">The category for the node.</param> /// <returns>The <see cref="GrhTreeViewFolderNode"/> instance.</returns> public static GrhTreeViewFolderNode Create(TreeView treeView, string category) { var delimiters = new string[] { SpriteCategorization.Delimiter }; var categoryParts = category.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); GrhTreeViewFolderNode current = null; var currentColl = treeView.Nodes; for (var i = 0; i < categoryParts.Length; i++) { var subCategory = categoryParts[i]; var matches = currentColl.OfType <GrhTreeViewFolderNode>().Where(x => x.SubCategory == subCategory); var count = matches.Count(); if (count == 0) { // Create the new folder node for the subcategory current = new GrhTreeViewFolderNode(currentColl, subCategory); } else if (count == 1) { // Use the found match current = matches.First(); } else { // Uhm... too many matches? const string errmsg = "Somehow we have more than one node for a single category (`{0}`)."; Debug.Fail(string.Format(errmsg, category)); return(matches.FirstOrDefault()); } currentColl = current.Nodes; } return(current); }
/// <summary> /// Creates a <see cref="GrhTreeViewFolderNode"/>. /// </summary> /// <param name="treeView">The <see cref="TreeView"/> to add the node to.</param> /// <param name="category">The category for the node.</param> /// <returns>The <see cref="GrhTreeViewFolderNode"/> instance.</returns> public static GrhTreeViewFolderNode Create(TreeView treeView, string category) { var delimiters = new string[] { SpriteCategorization.Delimiter }; var categoryParts = category.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); GrhTreeViewFolderNode current = null; var currentColl = treeView.Nodes; for (var i = 0; i < categoryParts.Length; i++) { var subCategory = categoryParts[i]; var matches = currentColl.OfType<GrhTreeViewFolderNode>().Where(x => x.SubCategory == subCategory); var count = matches.Count(); if (count == 0) { // Create the new folder node for the subcategory current = new GrhTreeViewFolderNode(currentColl, subCategory); } else if (count == 1) { // Use the found match current = matches.First(); } else { // Uhm... too many matches? const string errmsg = "Somehow we have more than one node for a single category (`{0}`)."; Debug.Fail(string.Format(errmsg, category)); return matches.FirstOrDefault(); } currentColl = current.Nodes; } return current; }