using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ANX.ContentCompiler.GUI
{
public static class TreeViewExtensions
{
///
/// Performs a recursive search on this TreeView's nodes and its child nodes. Returns the first item found.
///
/// The TreeView
/// Name to search for
/// The first node matching the given criteria or null
public static TreeNode RecursiveSearch(this TreeView treeView, String name)
{
foreach (TreeNode treeNode in treeView.Nodes)
{
if (treeNode.Name.Equals(name))
return treeNode;
var retNode = treeNode.RecursiveSearch(name);
if (retNode != null)
{
return retNode;
}
}
return null;
}
///
/// Performs a recursive search on this TreeNode's nodes and their child nodes. Returns the first item found.
///
/// The TreeNode
/// Name to search for
/// The first node matching the given criteria or null
public static TreeNode RecursiveSearch(this TreeNode treeNode, String name)
{
foreach (TreeNode node in treeNode.Nodes)
{
if (node.Name.Equals(name))
return node;
var ret = node.RecursiveSearch(name);
if (ret != null)
return ret;
}
return null;
}
///
/// Recursively replaces all parts of the names/texts with new values.
///
///
///
///
public static void RecursivelyReplacePartOfName(this TreeNode tree, string old, string newString)
{
tree.Name = tree.Name.Replace(old, newString);
tree.Text = tree.Text.Replace(old, newString);
foreach (TreeNode node in tree.Nodes)
{
node.RecursivelyReplacePartOfName(old, newString);
}
}
}
}