private void UnloadNode(LinkNode node, List <ulong> visible) { node.AddSubs = false; if (visible != null && node.IsVisible()) { visible.Add(node.Link.UserID); } if (NodeMap.ContainsKey(node.Link.UserID)) { NodeMap.Remove(node.Link.UserID); } // for each child, call unload node, then clear foreach (LinkNode child in node.Nodes) { UnloadNode(child, visible); } // unloads children of node, not the node itself node.Nodes.Clear(); node.Collapse(); }
private void UpdateOperation(LinkNode node) { OpLink link = node.Link; TreeListNode parent = null; OpLink uplink = GetTreeHigher(link); if (uplink == null) parent = virtualParent; else if (NodeMap.ContainsKey(uplink.UserID)) parent = NodeMap[uplink.UserID]; else if (uplink.IsLoopRoot) { parent = CreateNode(uplink); LoadRoot((LinkNode)parent); } // else branch this link is apart of is not visible in current display // self is changing ensure it's visible if (node.Link.UserID == Core.UserID) { if (parent == null) { List<ulong> uplinks = Trust.GetUnconfirmedUplinkIDs(Core.UserID, Project); uplinks.Add(Core.UserID); ExpandPath(node, uplinks); // check nodeMap again now that highers added if (NodeMap.ContainsKey(uplink.UserID)) parent = NodeMap[uplink.UserID]; } if (parent != null) parent.Expand(); } // remember settings bool selected = node.Selected; bool expanded = node.IsExpanded; bool loadsubs = node.AddSubs; // update parent node if (node.Parent != parent) { List<ulong> visible = new List<ulong>(); // remove previous instance of node if (node.Parent != null) { if (node.IsVisible()) visible.Add(link.UserID); LinkNode oldParent = node.Parent as LinkNode; LinkNode unload = (oldParent != null && oldParent.Link.IsLoopRoot) ? oldParent : node; // if old parent is a loop node, the loop is made obsolete by change UnloadNode(unload, visible); unload.Remove(); } if (parent == null) return; // if new parent is hidden, dont bother adding till user expands LinkNode newParent = parent as LinkNode; // null if virtual parent (root) if (newParent != null && newParent.AddSubs == false) return; // copy node to start fresh LinkNode newNode = CreateNode(node.Link); if (newParent != null) GuiUtils.InsertSubNode(newParent, newNode); else LoadRoot(newNode); ArrangeRoots(); // arrange nodes can cause newNode to become invalid, retrieve updated copy if(!NodeMap.ContainsKey(link.UserID)) return; newNode = NodeMap[link.UserID]; if (loadsubs) // if previous node set to add kids { LoadNode(newNode); if (expanded) // if previous node set expanded newNode.Expand(); } node = newNode; // recurse to each previously visible node List<LinkNode> roots = new List<LinkNode>(); foreach (TreeListNode treeNode in Nodes) if (treeNode.GetType() == typeof(LinkNode)) if (((LinkNode)treeNode).Section == ProjectNode) roots.Add(treeNode as LinkNode); foreach (ulong id in visible) { List<ulong> uplinks = Trust.GetUnconfirmedUplinkIDs(id, Project); foreach (LinkNode root in roots) VisiblePath(root, uplinks); } // show unlinked if there's something to show if (Nodes.IndexOf(UnlinkedNode) + 1 == Nodes.Count) UnlinkedNode.Text = ""; else UnlinkedNode.Text = "Untrusted"; } node.UpdateStatus(); if (selected) node.Selected = true; Invalidate(); }
private void UpdateOperation(LinkNode node) { OpLink link = node.Link; TreeListNode parent = null; OpLink uplink = GetTreeHigher(link); if (uplink == null) { parent = virtualParent; } else if (NodeMap.ContainsKey(uplink.UserID)) { parent = NodeMap[uplink.UserID]; } else if (uplink.IsLoopRoot) { parent = CreateNode(uplink); LoadRoot((LinkNode)parent); } // else branch this link is apart of is not visible in current display // self is changing ensure it's visible if (node.Link.UserID == Core.UserID) { if (parent == null) { List <ulong> uplinks = Trust.GetUnconfirmedUplinkIDs(Core.UserID, Project); uplinks.Add(Core.UserID); ExpandPath(node, uplinks); // check nodeMap again now that highers added if (NodeMap.ContainsKey(uplink.UserID)) { parent = NodeMap[uplink.UserID]; } } if (parent != null) { parent.Expand(); } } // remember settings bool selected = node.Selected; bool expanded = node.IsExpanded; bool loadsubs = node.AddSubs; // update parent node if (node.Parent != parent) { List <ulong> visible = new List <ulong>(); // remove previous instance of node if (node.Parent != null) { if (node.IsVisible()) { visible.Add(link.UserID); } LinkNode oldParent = node.Parent as LinkNode; LinkNode unload = (oldParent != null && oldParent.Link.IsLoopRoot) ? oldParent : node; // if old parent is a loop node, the loop is made obsolete by change UnloadNode(unload, visible); unload.Remove(); } if (parent == null) { return; } // if new parent is hidden, dont bother adding till user expands LinkNode newParent = parent as LinkNode; // null if virtual parent (root) if (newParent != null && newParent.AddSubs == false) { return; } // copy node to start fresh LinkNode newNode = CreateNode(node.Link); if (newParent != null) { GuiUtils.InsertSubNode(newParent, newNode); } else { LoadRoot(newNode); } ArrangeRoots(); // arrange nodes can cause newNode to become invalid, retrieve updated copy if (!NodeMap.ContainsKey(link.UserID)) { return; } newNode = NodeMap[link.UserID]; if (loadsubs) // if previous node set to add kids { LoadNode(newNode); if (expanded) // if previous node set expanded { newNode.Expand(); } } node = newNode; // recurse to each previously visible node List <LinkNode> roots = new List <LinkNode>(); foreach (TreeListNode treeNode in Nodes) { if (treeNode.GetType() == typeof(LinkNode)) { if (((LinkNode)treeNode).Section == ProjectNode) { roots.Add(treeNode as LinkNode); } } } foreach (ulong id in visible) { List <ulong> uplinks = Trust.GetUnconfirmedUplinkIDs(id, Project); foreach (LinkNode root in roots) { VisiblePath(root, uplinks); } } // show unlinked if there's something to show if (Nodes.IndexOf(UnlinkedNode) + 1 == Nodes.Count) { UnlinkedNode.Text = ""; } else { UnlinkedNode.Text = "Untrusted"; } } node.UpdateStatus(); if (selected) { node.Selected = true; } Invalidate(); }
private void UnloadNode(LinkNode node, List<ulong> visible) { node.AddSubs = false; if (visible != null && node.IsVisible()) visible.Add(node.Link.UserID); if (NodeMap.ContainsKey(node.Link.UserID)) NodeMap.Remove(node.Link.UserID); // for each child, call unload node, then clear foreach (LinkNode child in node.Nodes) UnloadNode(child, visible); // unloads children of node, not the node itself node.Nodes.Clear(); node.Collapse(); }