/// <summary> /// Converts a HierarchicalPathTreeCollection into a Gtk.TreeStore. /// </summary> public static TreeStore ToTreeStore <TValue>( this HierarchicalPathTreeCollection <TValue> tree, bool includeRootNode = false, string rootName = "<Root>") { // Create a new tree store to populate. var store = new TreeStore( typeof(string), typeof(HierarchicalPath), typeof(TValue)); // If we are including the parent, then start with that. if (includeRootNode) { AppendToTreeStore(store, tree, rootName); } else { // Populate the child nodes. foreach (HierarchicalPathTreeCollection <TValue> node in tree.DirectNodes) { AppendToTreeStore(store, node, node.Path.Last); } } // Return the resulting store. return(store); }
public void TestEmpty() { // Setup var collection = new HierarchicalPathTreeCollection<int>(); // Operation // Verification Assert.AreEqual(0, collection.Count); }
public void TestEmpty() { // Setup var collection = new HierarchicalPathTreeCollection <int>(); // Operation // Verification Assert.AreEqual(0, collection.Count); }
/// <summary> /// Appends the given tree to the root of the tree store. /// </summary> /// <typeparam name="TValue"></typeparam> /// <param name="store"></param> /// <param name="tree"></param> /// <param name="nodeName"></param> private static void AppendToTreeStore <TValue>( TreeStore store, HierarchicalPathTreeCollection <TValue> tree, string nodeName) { // Insert the first node into the tree. TreeIter iter = store.AppendValues(nodeName, tree.Path.Last, tree); // Go through all the child nodes under the three. AppendChildrenToTreeStore(store, iter, tree); }
/// <summary> /// Appends all of the child nodes into the tree. /// </summary> /// <typeparam name="TValue">The type represented by the tree.</typeparam> /// <param name="store">The TreeStore to append to.</param> /// <param name="iter">The TreeIter to append the nodes underneath.</param> /// <param name="tree">The tree level to append the children from.</param> private static void AppendChildrenToTreeStore <TValue>( TreeStore store, TreeIter iter, HierarchicalPathTreeCollection <TValue> tree) { // Go through all the child nodes under the three. foreach (HierarchicalPathTreeCollection <TValue> child in tree.DirectNodes) { AppendToTreeStore(store, iter, child, child.Path.Last); } }
/// <summary> /// Appends to the tree store underneath the given iterator. /// </summary> /// <typeparam name="TValue"></typeparam> /// <param name="store"></param> /// <param name="iter"></param> /// <param name="tree"></param> /// <param name="nodeName"></param> private static void AppendToTreeStore <TValue>( TreeStore store, TreeIter iter, HierarchicalPathTreeCollection <TValue> tree, string nodeName) { // Insert the node into the tree. TreeIter childIter = store.AppendValues(iter, nodeName, tree.Path.Last, tree); // Insert the children into the tree. AppendChildrenToTreeStore(store, childIter, tree); }
public void TestRootAdd() { // Setup var collection = new HierarchicalPathTreeCollection<int>(); var path = new HierarchicalPath("/"); // Operation collection.Add(path, 234); // Verification Assert.AreEqual(1, collection.Count); Assert.AreEqual(234, collection.Item); }
public void TestRootAdd() { // Setup var collection = new HierarchicalPathTreeCollection <int>(); var path = new HierarchicalPath("/"); // Operation collection.Add(path, 234); // Verification Assert.AreEqual(1, collection.Count); Assert.AreEqual(234, collection.Item); }
public void TestMultipleDepthAdds() { // Setup var collection = new HierarchicalPathTreeCollection<int>(); var path1 = new HierarchicalPath("/a/b"); var path2 = new HierarchicalPath("/a/c"); // Operation collection.Add(path1, 234); collection.Add(path2, 567); // Verification Assert.AreEqual(2, collection.Count); Assert.AreEqual(4, collection.NodeCount); Assert.AreEqual(0, collection.Item); Assert.AreEqual(2, collection.GetChild(new HierarchicalPath("/a")).Count); Assert.AreEqual(234, collection.Get(path1)); Assert.AreEqual(567, collection.Get(path2)); }
public void TestMultipleDepthAdds() { // Setup var collection = new HierarchicalPathTreeCollection <int>(); var path1 = new HierarchicalPath("/a/b"); var path2 = new HierarchicalPath("/a/c"); // Operation collection.Add(path1, 234); collection.Add(path2, 567); // Verification Assert.AreEqual(2, collection.Count); Assert.AreEqual(4, collection.NodeCount); Assert.AreEqual(0, collection.Item); Assert.AreEqual(2, collection.GetChild(new HierarchicalPath("/a")).Count); Assert.AreEqual(234, collection.Get(path1)); Assert.AreEqual(567, collection.Get(path2)); }