Beispiel #1
0
 public void TestNullAdaptee()
 {
     var treeViewModel = new TreeViewModel();
     treeViewModel.Adaptee = null;
     treeViewModel.AutoExpand = AutoExpandMode.Disabled;
     treeViewModel.ShowRoot = true;
     treeViewModel.CollapseAll();
     treeViewModel.ExpandAll();
     treeViewModel.ExpandToFirstLeaf();
     Assert.False(treeViewModel.GetExpandedItems().Any());
     Assert.Null(treeViewModel.Adaptee);
     Assert.AreEqual(treeViewModel.AutoExpand, AutoExpandMode.Disabled);
     Assert.IsTrue(treeViewModel.ShowRoot);
 }
Beispiel #2
0
        public void TestAdapteeWithJustRoot()
        {
            var treeView = new MyTreeView(); //has a root MyNode

            var treeViewModel = new TreeViewModel();
            var treeViewWithSelection = new TreeViewWithSelection(treeView);
            treeViewModel.Adaptee = treeViewWithSelection;
            treeViewModel.AutoExpand = AutoExpandMode.Disabled;
            treeViewModel.ShowRoot = true;
            treeViewModel.CollapseAll();
            treeViewModel.ExpandAll();
            var expandedItem = treeViewModel.GetExpandedItems().First();
            Assert.AreEqual(expandedItem, treeView.Root);
            Assert.AreEqual(treeViewWithSelection, treeViewModel.Adaptee);
            Assert.AreEqual(treeViewModel.AutoExpand, AutoExpandMode.Disabled);
            Assert.IsTrue(treeViewModel.ShowRoot);
        }
Beispiel #3
0
        /// <summary>
        /// Constructor</summary>
        /// <param name="settingsService">Settings service that manages preferences</param>
        /// <param name="pathName">Path to the setting to show</param>
        public SettingsDialogViewModel(SettingsService settingsService, string pathName)
        {
            Title = "Preferences".Localize();

            m_settingsService = settingsService;
            m_originalState = m_settingsService.UserState; // for cancel

            m_treeViewAdapter = new TreeViewWithSelection(settingsService.UserSettingsInternal);
            m_treeViewAdapter.SelectionChanged += TreeViewAdapterSelectionChanged;
            TreeViewModel = new TreeViewModel { MultiSelectEnabled = false, ShowRoot = false, TreeView = m_treeViewAdapter };
            TreeViewModel.ExpandAll();

            Node node = pathName != null
                            ? TreeViewModel.Show(m_settingsService.GetSettingsPathInternal(pathName), true)
                            : TreeViewModel.ExpandToFirstLeaf();

            node.IsSelected = true;

            SetDefaultsCommand = new DelegateCommand(SetDefaults, CanSetDefaults, false);
        }
Beispiel #4
0
        /// <summary>
        /// Constructor</summary>
        /// <param name="settingsService">Settings service that manages preferences</param>
        /// <param name="pathName">Path to the setting to show</param>
        public SettingsDialogViewModel(SettingsService settingsService, string pathName)
        {
            Title = "Preferences".Localize();

            m_settingsService = settingsService;
            m_originalState   = m_settingsService.UserState; // for cancel

            m_treeViewAdapter = new TreeViewWithSelection(settingsService.UserSettingsInternal);
            m_treeViewAdapter.SelectionChanged += TreeViewAdapterSelectionChanged;
            TreeViewModel = new TreeViewModel {
                MultiSelectEnabled = false, ShowRoot = false, TreeView = m_treeViewAdapter
            };
            TreeViewModel.ExpandAll();

            Node node = pathName != null
                            ? TreeViewModel.Show(m_settingsService.GetSettingsPathInternal(pathName), true)
                            : TreeViewModel.ExpandToFirstLeaf();

            node.IsSelected = true;

            SetDefaultsCommand = new DelegateCommand(SetDefaults, CanSetDefaults, false);
        }
Beispiel #5
0
 public Node(object adaptee, TreeViewModel owner, Node parent)
     : base(adaptee)
 {
     m_owner = owner;
     Parent = parent;
 }
Beispiel #6
0
        public void TestAdaptee()
        {
            // Construct a tree.
            //  root
            //      a
            //          aa
            //          ab
            //      b
            //          ba
            var treeView = new MyItemTreeView();
            var a = new MyNode("a");
            var aa = new MyNode("aa");
            var ab = new MyNode("ab");
            var b = new MyNode("b");
            var ba = new MyNode("ba");
            treeView.Root.Children.Add(a);
            a.Children.Add(aa);
            a.Children.Add(ab);
            treeView.Root.Children.Add(b);
            b.Children.Add(ba);

            var treeViewModel = new TreeViewModel();
            var treeViewWithSelection = new TreeViewWithSelection(treeView);
            treeViewModel.Adaptee = treeViewWithSelection;
            treeViewModel.AutoExpand = AutoExpandMode.Disabled;

            // Test ShowRoot being false.
            treeViewModel.ShowRoot = false;
            treeViewModel.CollapseAll();
            var expandedList = treeViewModel.GetExpandedItems().ToList();
            Assert.IsTrue(expandedList.Count == 0);
            var rootModelNode = treeViewModel.Root;
            Assert.IsFalse(rootModelNode.IsVisible);
            Assert.IsFalse(rootModelNode.IsSelected);

            // Expand to first leaf ("aa") with ShowRoot being false.
            Node firstLeaf = treeViewModel.ExpandToFirstLeaf();
            Assert.IsTrue(firstLeaf.Adaptee == aa);
            expandedList = treeViewModel.GetExpandedItems().ToList();
            Assert.IsTrue(expandedList.Count == 3); // the leaf node can be "expanded"
            Assert.IsTrue(expandedList[0] == treeView.Root);
            Assert.IsTrue(expandedList[1] == a);
            Assert.IsTrue(expandedList[2] == aa);

            // Test ShowRoot being true.
            treeViewModel.ShowRoot = true;
            treeViewModel.CollapseAll();
            expandedList = treeViewModel.GetExpandedItems().ToList();
            Assert.IsTrue(expandedList.Count == 0);

            // Expand to first leaf ("aa") with ShowRoot being true.
            firstLeaf = treeViewModel.ExpandToFirstLeaf();
            Assert.IsTrue(firstLeaf.Adaptee == aa);
            expandedList = treeViewModel.GetExpandedItems().ToList();
            Assert.IsTrue(expandedList.Count == 3); // the leaf node can be "expanded"
            Assert.IsTrue(expandedList[0] == treeView.Root);
            Assert.IsTrue(expandedList[1] == a);
            Assert.IsTrue(expandedList[2] == aa);

            // Test ExpandAll
            treeViewModel.ExpandAll();
            expandedList = treeViewModel.GetExpandedItems().ToList();
            Assert.IsTrue(expandedList.Count == 6);

            Assert.AreEqual(treeViewWithSelection, treeViewModel.Adaptee);
            Assert.AreEqual(treeViewModel.AutoExpand, AutoExpandMode.Disabled);
            Assert.IsTrue(treeViewModel.ShowRoot);
        }
Beispiel #7
0
        public void TestGetInfoCalls()
        {
            // Construct a tree.
            //  root
            //      a
            //          aa
            //          ab
            //      b
            //          ba
            var treeView = new MyItemTreeView();
            var a = new MyNode("a");
            var aa = new MyNode("aa");
            var ab = new MyNode("ab");
            var b = new MyNode("b");
            var ba = new MyNode("ba");
            treeView.Root.Children.Add(a);
            a.Children.Add(aa);
            a.Children.Add(ab);
            treeView.Root.Children.Add(b);
            b.Children.Add(ba);

            var treeViewModel = new TreeViewModel(treeView);

            // Test ShowRoot being false.
            treeViewModel.ShowRoot = false;
            treeViewModel.CollapseAll();
            treeView.NodesQueried.Clear();
            treeViewModel.Refresh(treeView.Root); // to call IItemView.GetInfo()
            var expandedList = treeViewModel.GetExpandedItems().ToList();
            Assert.IsTrue(expandedList.Count == 0);
            var rootModelNode = treeViewModel.Root;
            Assert.IsFalse(rootModelNode.IsVisible);
            Assert.IsFalse(rootModelNode.IsSelected);
            //IItemView.GetInfo() should not be called on collapsed nodes.
            Assert.IsFalse(treeView.NodesQueried.Contains(aa));

            // Expand to first leaf ("aa") with ShowRoot being false.
            Node firstLeaf = treeViewModel.ExpandToFirstLeaf();
            Assert.IsTrue(firstLeaf.Adaptee == aa);
            expandedList = treeViewModel.GetExpandedItems().ToList();
            Assert.IsTrue(expandedList.Count == 3); // the leaf node can be "expanded"
            Assert.IsTrue(expandedList[0] == treeView.Root);
            Assert.IsTrue(expandedList[1] == a);
            Assert.IsTrue(expandedList[2] == aa);
            treeView.NodesQueried.Clear();
            treeViewModel.Refresh(treeView.Root); // to call IItemView.GetInfo()
            Assert.IsTrue(treeView.NodesQueried.Contains(aa));
            Assert.IsTrue(treeView.NodesQueried.Contains(a));
            Assert.IsFalse(treeView.NodesQueried.Contains(ba));

            // Test ShowRoot being true.
            treeViewModel.ShowRoot = true;
            treeViewModel.CollapseAll();
            expandedList = treeViewModel.GetExpandedItems().ToList();
            Assert.IsTrue(expandedList.Count == 0);

            // Expand to first leaf ("aa") with ShowRoot being true.
            treeView.NodesQueried.Clear();
            firstLeaf = treeViewModel.ExpandToFirstLeaf();
            Assert.IsTrue(firstLeaf.Adaptee == aa);
            expandedList = treeViewModel.GetExpandedItems().ToList();
            Assert.IsTrue(expandedList.Count == 3); // the leaf node can be "expanded"
            Assert.IsTrue(expandedList[0] == treeView.Root);
            Assert.IsTrue(expandedList[1] == a);
            Assert.IsTrue(expandedList[2] == aa);

            // Test ExpandAll
            treeView.NodesQueried.Clear();
            treeViewModel.ExpandAll();
            treeViewModel.Refresh(treeView.Root); // to call IItemView.GetInfo()
            expandedList = treeViewModel.GetExpandedItems().ToList();
            Assert.IsTrue(expandedList.Count == 6);
            Assert.IsTrue(treeView.NodesQueried.Count == 6);

            Assert.AreEqual(treeView, treeViewModel.Adaptee);
            Assert.IsTrue(treeViewModel.ShowRoot);
        }
Beispiel #8
0
 /// <summary>
 /// Constructor</summary>
 /// <param name="adaptee">Object that is adapted</param>
 /// <param name="owner">Node's owner</param>
 /// <param name="parent">Node's parent</param>
 public Node(object adaptee, TreeViewModel owner, Node parent)
     : base(adaptee)
 {
     m_owner = owner;
     Parent  = parent;
 }