Пример #1
0
        private void RefreshStructure()
        {
            PlanStructure.BeginUpdate();


            // save selected
            PlanNode selected = GetSelected();

            // save visible while unloading
            List <ulong> visible = new List <ulong>();

            foreach (TreeListNode node in PlanStructure.Nodes)
            {
                if (node.GetType() == typeof(PlanNode))
                {
                    UnloadNode((PlanNode)node, visible);
                }
            }


            NodeMap.Clear();
            PlanStructure.Nodes.Clear();


            // nodes
            ThreadedList <OpLink> roots = null;

            if (Trust.ProjectRoots.SafeTryGetValue(ProjectID, out roots))
            {
                roots.LockReading(delegate()
                {
                    foreach (OpLink root in roots)
                    {
                        if (Uplinks.Contains(root.UserID))
                        {
                            PlanNode node = CreateNode(root);

                            Plans.Research(root.UserID);

                            LoadNode(node);

                            GuiUtils.InsertSubNode(PlanStructure.virtualParent, node);

                            ExpandPath(node, Uplinks);
                        }

                        if (root.IsLoopRoot &&
                            root.Downlinks.Count > 0 &&
                            Uplinks.Contains(root.Downlinks[0].UserID))
                        {
                            foreach (OpLink downlink in root.Downlinks)
                            {
                                if (!root.IsLoopedTo(downlink))
                                {
                                    PlanNode node = CreateNode(downlink);

                                    Plans.Research(downlink.UserID);

                                    LoadNode(node);

                                    GuiUtils.InsertSubNode(PlanStructure.virtualParent, node);

                                    ExpandPath(node, Uplinks);
                                }
                            }
                        }
                    }
                });
            }

            // restore visible
            foreach (ulong id in visible)
            {
                foreach (TreeListNode node in PlanStructure.Nodes)
                {
                    if (node.GetType() == typeof(PlanNode))
                    {
                        List <ulong> uplinks = Trust.GetUnconfirmedUplinkIDs(id, ProjectID);
                        uplinks.Add(id);
                        VisiblePath((PlanNode)node, uplinks);
                    }
                }
            }

            // restore selected
            if (selected != null)
            {
                if (NodeMap.ContainsKey(selected.Link.UserID))
                {
                    PlanStructure.Select(NodeMap[selected.Link.UserID]);
                }
            }


            PlanStructure.EndUpdate();
        }
Пример #2
0
        private void RefreshOperationTree()
        {
            BeginUpdate();

            // save selected
            LinkNode selected = GetSelected();

            // save visible while unloading
            List <ulong> visible = new List <ulong>();

            foreach (TreeListNode node in Nodes)
            {
                if (node.GetType() == typeof(LinkNode))
                {
                    UnloadNode((LinkNode)node, visible);
                }
            }

            NodeMap.Clear();
            Nodes.Clear();

            // white space
            if (FirstLineBlank)
            {
                Nodes.Add(new LabelNode(""));
            }

            if (!Trust.ProjectRoots.SafeContainsKey(Project))
            {
                EndUpdate();
                return;
            }

            string rootname = Core.User.Settings.Operation;

            if (Project != 0)
            {
                rootname = Trust.GetProjectName(Project);
            }

            // operation
            ProjectNode      = new ProjectNode(rootname, Project);
            ProjectNode.Font = TrustedFont;
            Nodes.Add(ProjectNode);

            // white space
            Nodes.Add(new LabelNode(""));

            // unlinked
            UnlinkedNode      = new ProjectNode("Untrusted", 0);
            UnlinkedNode.Font = UntrustedFont;

            Nodes.Add(UnlinkedNode);


            // if forced, load specific node as root
            if (ForceRootID != 0)
            {
                OpLink root = Trust.GetLink(ForceRootID, Project);

                if (root != null)
                {
                    SetupRoot(root);
                }
            }

            // get roots for specific project
            else
            {
                ThreadedList <OpLink> roots = null;
                if (Trust.ProjectRoots.SafeTryGetValue(Project, out roots))
                {
                    roots.LockReading(delegate()
                    {
                        foreach (OpLink root in roots)
                        {
                            SetupRoot(root);
                        }
                    });
                }
            }

            // show unlinked if there's something to show
            if (Nodes.IndexOf(UnlinkedNode) + 1 == Nodes.Count)
            {
                UnlinkedNode.Text = "";
            }
            else
            {
                UnlinkedNode.Text = "Untrusted";
            }

            // restore visible
            foreach (ulong id in visible)
            {
                foreach (TreeListNode node in Nodes)
                {
                    if (node.GetType() == typeof(LinkNode))
                    {
                        List <ulong> uplinks = Trust.GetUnconfirmedUplinkIDs(id, Project);
                        uplinks.Add(id);
                        VisiblePath((LinkNode)node, uplinks);
                    }
                }
            }

            // restore selected
            if (selected != null)
            {
                if (NodeMap.ContainsKey(selected.Link.UserID))
                {
                    Select(NodeMap[selected.Link.UserID]);
                }
            }

            EndUpdate();
        }