示例#1
0
        public void Remove(TreePosition pos)
        {
            // Remove all child nodes in reverse order and notify client of each removed child.
            // This allows clients to keep track of all removed nodes, before the current node
            // will be removed and invalidated.
            for (int i = GetChildrenCount(pos) - 1; i >= 0; i--)
            {
                Remove(GetChild(pos, i));
            }
            NodePosition np = GetPosition(pos);

            np.ParentList.RemoveAt(np.NodeIndex);
            var parent = np.ParentList.Parent;
            var index  = np.NodeIndex;

            version++;
            if (NodeDeleted != null)
            {
                NodeDeleted(this, new TreeNodeChildEventArgs(parent, index, pos));
            }
        }
示例#2
0
        public TreePosition InsertAfter(TreePosition pos)
        {
            NodePosition np = GetPosition(pos);
            Node         nn = new Node();

            nn.NodeId = nextNodeId++;

            np.ParentList.Insert(np.NodeIndex + 1, nn);
            version++;

            // Update the provided position is still valid
            np.StoreVersion = version;

            var node = new NodePosition()
            {
                ParentList = np.ParentList, NodeId = nn.NodeId, NodeIndex = np.NodeIndex + 1, StoreVersion = version
            };

            if (NodeInserted != null)
            {
                NodeInserted(this, new TreeNodeEventArgs(node));
            }
            return(node);
        }
示例#3
0
 public TreePosition GetChild(TreePosition pos, int index)
 {
     if (pos == null)
     {
         if (rootNodes.Count == 0)
         {
             return(null);
         }
         Node n = rootNodes[index];
         return(new NodePosition()
         {
             ParentList = rootNodes, NodeId = n.NodeId, NodeIndex = index, StoreVersion = version
         });
     }
     else
     {
         NodePosition np = GetPosition(pos);
         Node         n  = np.ParentList[np.NodeIndex];
         return(new NodePosition()
         {
             ParentList = n.Children, NodeId = n.Children[index].NodeId, NodeIndex = index, StoreVersion = version
         });
     }
 }