Exemplo n.º 1
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();
        }
Exemplo n.º 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();
        }
Exemplo n.º 3
0
        public void InsertRootNode(ProjectNode start, LinkNode node)
        {
            // inserts item directly under start, not as a child node

            int index = 0;

            TreeListNode root = start.Parent;
            node.Section = start;
            bool ready = false;

            foreach (TreeListNode entry in root.Nodes)
            {
                if (ready)
                    if (start == ProjectNode ||
                        (start == UnlinkedNode && string.Compare(node.Text, entry.Text, true) < 0) ||
                        entry.GetType() == typeof(LabelNode)) // lower bounds
                    {
                        root.Nodes.Insert(index, node);
                        return;
                    }

                if (entry == start)
                    ready = true;

                index++;
            }

            root.Nodes.Insert(index, node);
        }