Exemplo n.º 1
0
        private void AddDuplicatesToTree(List <IsIdentifiableRule> allRules)
        {
            var root     = new TreeNodeWithCount("Identical Rules");
            var children = GetDuplicates(allRules).ToArray();

            root.Children = children;
            _treeView.AddObject(root);
        }
Exemplo n.º 2
0
        public void TreeNode_WorksWithoutDelegate()
        {
            var tree = new TreeView();

            var root = new TreeNode("Root");

            root.Children.Add(new TreeNode("Leaf1"));
            root.Children.Add(new TreeNode("Leaf2"));

            tree.AddObject(root);

            tree.Expand(root);
            Assert.Equal(2, tree.GetChildren(root).Count());
        }
Exemplo n.º 3
0
        public void MultiSelect_GetAllSelectedObjects()
        {
            var tree = new TreeView();

            TreeNode l1;
            TreeNode l2;
            TreeNode l3;
            TreeNode l4;

            var root = new TreeNode("Root");

            root.Children.Add(l1 = new TreeNode("Leaf1"));
            root.Children.Add(l2 = new TreeNode("Leaf2"));
            root.Children.Add(l3 = new TreeNode("Leaf3"));
            root.Children.Add(l4 = new TreeNode("Leaf4"));

            tree.AddObject(root);
            tree.MultiSelect = true;

            tree.Expand(root);
            Assert.Empty(tree.GetAllSelectedObjects());

            tree.SelectedObject = root;

            Assert.Single(tree.GetAllSelectedObjects(), root);

            // move selection down 1
            tree.AdjustSelection(1, false);

            Assert.Single(tree.GetAllSelectedObjects(), l1);

            // expand selection down 2 (e.g. shift down twice)
            tree.AdjustSelection(1, true);
            tree.AdjustSelection(1, true);

            Assert.Equal(3, tree.GetAllSelectedObjects().Count());
            Assert.Contains(l1, tree.GetAllSelectedObjects());
            Assert.Contains(l2, tree.GetAllSelectedObjects());
            Assert.Contains(l3, tree.GetAllSelectedObjects());

            tree.Collapse(root);

            // No selected objects since the root was collapsed
            Assert.Empty(tree.GetAllSelectedObjects());
        }
Exemplo n.º 4
0
        public void RefreshObject_EqualityTest()
        {
            var obj1 = new EqualityTestObject()
            {
                Name = "Bob", Age = 1
            };
            var obj2 = new EqualityTestObject()
            {
                Name = "Bob", Age = 2
            };;

            string root = "root";

            var tree = new TreeView <object> ();

            tree.TreeBuilder = new DelegateTreeBuilder <object> ((s) => ReferenceEquals(s, root) ? new object [] { obj1 } : null);
            tree.AddObject(root);

            // Tree is not expanded so the root has no children yet
            Assert.Empty(tree.GetChildren(root));


            tree.Expand(root);

            // now that the tree is expanded we should get our child returned
            Assert.Equal(1, tree.GetChildren(root).Count(child => ReferenceEquals(obj1, child)));

            // change the getter to return an Equal object (but not the same reference - obj2)
            tree.TreeBuilder = new DelegateTreeBuilder <object> ((s) => ReferenceEquals(s, root) ? new object [] { obj2 } : null);

            // tree has cached the knowledge of what children the root has so won't know about the change (we still get obj1)
            Assert.Equal(1, tree.GetChildren(root).Count(child => ReferenceEquals(obj1, child)));

            // now that we refresh the root we should get the new child reference (obj2)
            tree.RefreshObject(root);
            Assert.Equal(1, tree.GetChildren(root).Count(child => ReferenceEquals(obj2, child)));
        }