/// <summary> /// Recursive helper function to build the tree. /// </summary> /// <param name="parent">The parent node to add any subnodes to.</param> /// <param name="path">The path array.</param> /// <param name="index">The current index into the path array.</param> /// <returns></returns> private BrowserNode expandRemainingPath(BrowserNode parent, String[] path, int index) { if (index == path.Length) { return(parent); } if (!parent.hasChild(path[index])) { parent.addChild(new BrowserNode(path[index], null)); } return(expandRemainingPath(parent.getChild(path[index]), path, index + 1)); }
/// <summary> /// Add a node to the tree. This will automaticly create any folder nodes specified /// in the path. The path values can be separated by the delimiter array. So you could /// make a path such as Foo\Bar and send a "\" as the delimiter which would then put node /// into a folder called Bar which in turn is a subfolder of Foo, which would be a top /// level node in the tree. /// </summary> /// <param name="path">The path to put the node in. Pass null to place the object just under the root node.</param> /// <param name="delimeter">The delimiter to split up the path. Can be null if path is null.</param> /// <param name="node">The node to add to path.</param> public void addNode(String path, String[] delimeter, BrowserNode node) { BrowserNode folder; if (path != null && delimeter != null) { String[] expandedPath = path.Split(delimeter, StringSplitOptions.RemoveEmptyEntries); if (expandedPath.Length > 0) { folder = expandRemainingPath(rootNode, expandedPath, 0); } else { folder = rootNode; } } else { folder = rootNode; } folder.addChild(node); }
public void removeChild(BrowserNode child) { children.Remove(child.text); }
public void addChild(BrowserNode child) { children.Add(child.text, child); }
/// <summary> /// Add a node to the tree with the default path delimiters. These are \ and /. /// See the overloaded version for more information about the paths. /// </summary> /// <param name="path">The path to the node.</param> /// <param name="node">The node.</param> public void addNode(String path, BrowserNode node) { addNode(path, DefaultDelimiters, node); }
public Browser(String rootNodeName, String prompt) { rootNode = new BrowserNode(rootNodeName, null); this.Prompt = prompt; }