void DuplicateGrhDataNode(GrhTreeViewNode node, string oldCategoryStart, string newCategoryStart) { var gd = node.GrhData; if (gd is AutomaticAnimatedGrhData) { return; } // Replace the start of the categorization to the new category var newCategory = newCategoryStart; if (gd.Categorization.Category.ToString().Length > oldCategoryStart.Length) { newCategory += gd.Categorization.Category.ToString().Substring(oldCategoryStart.Length); } // Grab the new title var newTitle = GrhInfo.GetUniqueTitle(newCategory, gd.Categorization.Title); // Duplicate var newGrhData = gd.Duplicate(new SpriteCategorization(newCategory, newTitle)); // Add the new one to the tree UpdateGrhData(newGrhData); }
/// <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(GrhTreeViewNode root) { if (root != null && root.GrhData != null) { GrhInfo.Delete(root.GrhData); } }
/// <summary> /// Sets the <see cref="Image"/> for a <see cref="GrhTreeViewNode"/> and refreshes it. /// </summary> /// <param name="node">The <see cref="GrhTreeViewNode"/>.</param> /// <param name="image">The <see cref="Image"/>.</param> static void SetNodeImage(GrhTreeViewNode node, Image image) { node._image = image; try { ((GrhTreeView)node.TreeView).RefreshNodeImage(node); } catch { } }
/// <summary> /// Completely rebuilds the <see cref="GrhTreeView"/>. /// </summary> public void RebuildTree() { if (DesignMode) { return; } // Suspend the layout and updating while we massively alter the collection BeginUpdate(); SuspendLayout(); try { // If there are any nodes already, keep track of which is selected GrhTreeViewNode selectedGrhNode = SelectedNode as GrhTreeViewNode; GrhData selectedGrhData = selectedGrhNode != null ? selectedGrhNode.GrhData : null; // Clear any existing nodes (probably isn't any, but just in case...) Nodes.Clear(); // Set up the filter string[] filterWords = (Filter ?? string.Empty).Split(',').Distinct(StringComparer.OrdinalIgnoreCase).Select(x => x.Trim()).Where(x => x.Length > 0).ToArray(); if (filterWords.Length == 0) { filterWords = null; } // Iterate through all the GrhDatas foreach (var grhData in GrhInfo.GrhDatas) { if (filterWords != null) { // With filtering string cat = grhData.Categorization.ToString(); if (filterWords.Any(x => cat.Contains(x, StringComparison.OrdinalIgnoreCase))) { AddGrhToTree(grhData); } } else { // No filtering AddGrhToTree(grhData); } } // Perform the initial sort Sort(); // If we used filtering, expand all nodes if (filterWords != null) { ExpandAll(); } // Restore selection if (selectedGrhData != null) { SelectedNode = FindGrhDataNode(selectedGrhData); } } finally { // Resume the layout and updating ResumeLayout(); EndUpdate(); } }
/// <summary> /// Adds a <see cref="GrhData"/> to the tree or updates it if it already exists. /// </summary> /// <param name="gd"><see cref="GrhData"/> to add or update.</param> void AddGrhToTree(GrhData gd) { GrhTreeViewNode.Create(this, gd); }
/// <summary> /// Updates a <see cref="GrhData"/>'s information in the tree. /// </summary> /// <param name="grhData"><see cref="GrhData"/> to update.</param> public void UpdateGrhData(GrhData grhData) { GrhTreeViewNode.Create(this, grhData); }