Beispiel #1
0
        public void ClearsFilterOnEachItem()
        {
            HierarchyTreeViewItemCollection collection;
            HierarchyTreeViewItem           item;
            HierarchyTreeViewItem           childA;
            HierarchyTreeViewItem           childB;
            HierarchyTreeViewItem           childC;


            childA = Factory.CreateTreeViewItem(name: "A");
            childB = Factory.CreateTreeViewItem(name: "B");
            childC = Factory.CreateTreeViewItem(name: "C");
            item   = Factory.CreateTreeViewItem(name: "Root", children: new[] { childA, childB, childC });

            collection = new HierarchyTreeViewItemCollection(new[] { item });
            collection.Filter(new RegexTextFilter("B"));

            Assert.Equal(new[] { item }, collection);
            Assert.Equal(new[] { childB }, item.Children);

            collection.ClearFilter();

            Assert.Equal(new[] { item }, collection);
            Assert.Equal(new[] { childA, childB, childC }, item.Children);
        }
Beispiel #2
0
    public HierarchyTreeViewItem(
        IHierarchyNode node,
        IEnumerable <HierarchyTreeViewItem> children
        )
    {
        _node    = node;
        Children = new HierarchyTreeViewItemCollection(children);

        _isChecked  = false;
        _isExpanded = true;

        // Connect the children to this parent item.
        foreach (var child in Children)
        {
            child.Parent = this;
        }

        // If there are children, then that collection could
        // change as the items are filtered. We will need to
        // update our checked state when that collection changes.
        if (Children.Count > 0)
        {
            Children.CollectionChanged += (s, e) => UpdateCheckedStateFromChildren(true);
        }
    }
Beispiel #3
0
        public void IncludesFilteredItems()
        {
            HierarchyTreeViewItemCollection collection;
            HierarchyTreeViewItem           root1;
            HierarchyTreeViewItem           root2;
            HierarchyTreeViewItem           child1;
            HierarchyTreeViewItem           child2;
            HierarchyTreeViewItem           grandchild1;
            HierarchyTreeViewItem           grandchild2;


            grandchild1 = Factory.CreateTreeViewItem(name: "x");
            grandchild2 = Factory.CreateTreeViewItem(name: "a");
            child1      = Factory.CreateTreeViewItem(name: "x", children: new[] { grandchild1 });
            child2      = Factory.CreateTreeViewItem(name: "x", children: new[] { grandchild2 });
            root1       = Factory.CreateTreeViewItem(name: "x", children: new[] { child1 });
            root2       = Factory.CreateTreeViewItem(name: "a", children: new[] { child2 });

            collection = new HierarchyTreeViewItemCollection(new[] { root1, root2 });

            collection.Filter(new RegexTextFilter("x"));

            Assert.Equal(
                new[] {
                root1,
                child1,
                grandchild1,
                root2,
                child2,
                grandchild2
            },
                collection.GetFullHierarchy()
                );
        }
Beispiel #4
0
        public void ReturnsAllItemsAndAllDescendants()
        {
            HierarchyTreeViewItemCollection collection;
            HierarchyTreeViewItem           root1;
            HierarchyTreeViewItem           root2;
            HierarchyTreeViewItem           child1;
            HierarchyTreeViewItem           child2;
            HierarchyTreeViewItem           grandchild1;
            HierarchyTreeViewItem           grandchild2;


            grandchild1 = Factory.CreateTreeViewItem();
            grandchild2 = Factory.CreateTreeViewItem();
            child1      = Factory.CreateTreeViewItem(children: new[] { grandchild1 });
            child2      = Factory.CreateTreeViewItem(children: new[] { grandchild2 });
            root1       = Factory.CreateTreeViewItem(children: new[] { child1 });
            root2       = Factory.CreateTreeViewItem(children: new[] { child2 });

            collection = new HierarchyTreeViewItemCollection(new[] { root1, root2 });

            Assert.Equal(
                new[] {
                root1,
                child1,
                grandchild1,
                root2,
                child2,
                grandchild2
            },
                collection.GetFullHierarchy()
                );
        }
Beispiel #5
0
        public void ReturnsFalseWhenCollectionIsEmpty()
        {
            HierarchyTreeViewItemCollection collection;


            collection = new HierarchyTreeViewItemCollection(Enumerable.Empty <HierarchyTreeViewItem>());

            Assert.False(collection.CalculateCheckedState());
        }
    public async Task OnLoadedAsync()
    {
        IEnumerable <IHierarchyNode> hierarchy;


        hierarchy = await _hierarchyFactory.Invoke();

        Items = new HierarchyTreeViewItemCollection(hierarchy.Select(CreateItem));

        LoadedVisibility  = Visibility.Visible;
        LoadingVisibility = Visibility.Collapsed;
    }
Beispiel #7
0
        public void ReturnsNullWhenAllItemsAreIndeterminate()
        {
            HierarchyTreeViewItemCollection collection;


            collection = new HierarchyTreeViewItemCollection(new[] {
                Factory.CreateTreeViewItem(isChecked: null),
                Factory.CreateTreeViewItem(isChecked: null),
                Factory.CreateTreeViewItem(isChecked: null),
            });

            Assert.Null(collection.CalculateCheckedState());
        }
Beispiel #8
0
        public void ReturnsTrueWhenAllItemsAreChecked()
        {
            HierarchyTreeViewItemCollection collection;


            collection = new HierarchyTreeViewItemCollection(new[] {
                Factory.CreateTreeViewItem(isChecked: true),
                Factory.CreateTreeViewItem(isChecked: true),
                Factory.CreateTreeViewItem(isChecked: true),
            });

            Assert.True(collection.CalculateCheckedState());
        }
Beispiel #9
0
        public void ReturnsNullWhenSomeItemsAreChecked()
        {
            HierarchyTreeViewItemCollection collection;


            collection = new HierarchyTreeViewItemCollection(new[] {
                Factory.CreateTreeViewItem(isChecked: true),
                Factory.CreateTreeViewItem(isChecked: false),
                Factory.CreateTreeViewItem(isChecked: true),
            });

            Assert.Null(collection.CalculateCheckedState());
        }
Beispiel #10
0
        public void ReturnsFalseWhenNoItemsAreChecked()
        {
            HierarchyTreeViewItemCollection collection;


            collection = new HierarchyTreeViewItemCollection(new[] {
                Factory.CreateTreeViewItem(isChecked: false),
                Factory.CreateTreeViewItem(isChecked: false),
                Factory.CreateTreeViewItem(isChecked: false)
            });

            Assert.False(collection.CalculateCheckedState());
        }
Beispiel #11
0
        public void DoesNotRaiseCollectionChangedEventWhenCollectionIsEmpty()
        {
            HierarchyTreeViewItemCollection collection;
            bool raised;


            raised = false;

            collection = new HierarchyTreeViewItemCollection(Enumerable.Empty <HierarchyTreeViewItem>());
            collection.CollectionChanged += (s, e) => raised = true;

            collection.Filter(new RegexTextFilter("foo"));

            Assert.False(raised);
        }
Beispiel #12
0
        public void FiltersCollectionToOnlyContainItemsThatMatchFilterWhenItemshaveNoChildren()
        {
            HierarchyTreeViewItemCollection collection;
            HierarchyTreeViewItem           foo;
            HierarchyTreeViewItem           bar;
            HierarchyTreeViewItem           meep;


            foo  = Factory.CreateTreeViewItem(name: "foo");
            bar  = Factory.CreateTreeViewItem(name: "bar");
            meep = Factory.CreateTreeViewItem(name: "meep");

            collection = new HierarchyTreeViewItemCollection(new[] { foo, bar, meep });
            collection.Filter(new RegexTextFilter("foo"));

            Assert.Equal(new[] { foo }, collection);
        }
Beispiel #13
0
        public void FiltersCollectionToOnlyContainItemsThatMatchFilterOrHaveChildrenThatMatchFilter()
        {
            HierarchyTreeViewItemCollection collection;
            HierarchyTreeViewItem           foo;
            HierarchyTreeViewItem           bar;
            HierarchyTreeViewItem           meep;


            foo  = Factory.CreateTreeViewItem(name: "foo", children: new[] { Factory.CreateTreeViewItem(name: "x") });
            bar  = Factory.CreateTreeViewItem(name: "bar", children: new[] { Factory.CreateTreeViewItem(name: "y") });
            meep = Factory.CreateTreeViewItem(name: "meep", children: new[] { Factory.CreateTreeViewItem(name: "fff") });

            collection = new HierarchyTreeViewItemCollection(new[] { foo, bar, meep });
            collection.Filter(new RegexTextFilter("f"));

            Assert.Equal(new[] { foo, meep }, collection);
        }
Beispiel #14
0
        public void ReturnsCountOfFilteredItems()
        {
            HierarchyTreeViewItemCollection collection;


            collection = new HierarchyTreeViewItemCollection(new[] {
                Factory.CreateTreeViewItem(name: "foo"),
                Factory.CreateTreeViewItem(name: "bar")
            });

            Assert.Equal(2, collection.Count);

            collection.Filter(new RegexTextFilter("f"));

            Assert.Single(collection);

            collection.ClearFilter();

            Assert.Equal(2, collection.Count);
        }
Beispiel #15
0
        public void RaisesCollectionChangedEventWhenCollectionIsNotEmpty()
        {
            HierarchyTreeViewItemCollection collection;

            Assert.RaisedEvent <NotifyCollectionChangedEventArgs> e;


            collection = new HierarchyTreeViewItemCollection(new[] {
                Factory.CreateTreeViewItem(name: "foo"),
                Factory.CreateTreeViewItem(name: "bar")
            });

            e = Assert.Raises <NotifyCollectionChangedEventArgs>(
                (x) => collection.CollectionChanged += new NotifyCollectionChangedEventHandler(x),
                (x) => collection.CollectionChanged -= new NotifyCollectionChangedEventHandler(x),
                () => collection.Filter(new RegexTextFilter("foo"))
                );

            Assert.Equal(NotifyCollectionChangedAction.Reset, e.Arguments.Action);
        }
Beispiel #16
0
        public void DoesNotIncludeFilteredItems()
        {
            HierarchyTreeViewItemCollection collection;
            HierarchyTreeViewItem           root1;
            HierarchyTreeViewItem           root2;
            HierarchyTreeViewItem           root3;


            root1 = Factory.CreateTreeViewItem(name: "x");
            root2 = Factory.CreateTreeViewItem(name: "a");
            root3 = Factory.CreateTreeViewItem(name: "x");

            collection = new HierarchyTreeViewItemCollection(new[] { root1, root2, root3 });

            collection.Filter(new RegexTextFilter("x"));

            Assert.Equal(
                new[] { root1, root3 },
                collection
                );
        }
Beispiel #17
0
        public void UsesOriginalItemsWhenFilteringIfCollectionHasAlreadyBeenFiltered()
        {
            HierarchyTreeViewItemCollection collection;
            HierarchyTreeViewItem           foo;
            HierarchyTreeViewItem           bar;
            HierarchyTreeViewItem           meep;


            foo  = Factory.CreateTreeViewItem(name: "foo");
            bar  = Factory.CreateTreeViewItem(name: "bar");
            meep = Factory.CreateTreeViewItem(name: "meep");

            collection = new HierarchyTreeViewItemCollection(new[] { foo, bar, meep });
            collection.Filter(new RegexTextFilter("foo"));

            Assert.Equal(new[] { foo }, collection);

            collection.Filter(new RegexTextFilter("bar"));

            Assert.Equal(new[] { bar }, collection);
        }
Beispiel #18
0
        public void RestoresOriginalItems()
        {
            HierarchyTreeViewItemCollection collection;
            HierarchyTreeViewItem           foo;
            HierarchyTreeViewItem           bar;
            HierarchyTreeViewItem           meep;


            foo  = Factory.CreateTreeViewItem(name: "foo");
            bar  = Factory.CreateTreeViewItem(name: "bar");
            meep = Factory.CreateTreeViewItem(name: "meep");

            collection = new HierarchyTreeViewItemCollection(new[] { foo, bar, meep });
            collection.Filter(new RegexTextFilter("foo"));

            Assert.Equal(new[] { foo }, collection);

            collection.ClearFilter();

            Assert.Equal(new[] { foo, bar, meep }, collection);
        }
    public FilterDialogViewModel(
        Func <Task <IEnumerable <IHierarchyNode> > > hierarchyFactory,
        Func <TimeSpan, IDebouncer> debouncerFactory,
        TextFilterFactory textFilterFactory,
        JoinableTaskFactory joinableTaskFactory
        )
    {
        if (debouncerFactory is null)
        {
            throw new ArgumentNullException(nameof(debouncerFactory));
        }

        _hierarchyFactory  = hierarchyFactory ?? throw new ArgumentNullException(nameof(hierarchyFactory));
        _textFilterFactory = textFilterFactory ?? throw new ArgumentNullException(nameof(textFilterFactory));

        _items             = new HierarchyTreeViewItemCollection(Enumerable.Empty <HierarchyTreeViewItem>());
        _searchText        = "";
        _loadingVisibility = Visibility.Visible;
        _loadedVisibility  = Visibility.Collapsed;

        FocusSearchBoxSource = new FocusSource();

        ToggleLoadProjectDependenciesCommand = new DelegateCommand(
            (_) => LoadProjectDependencies   = !LoadProjectDependencies,
            CanAlwaysExecute,
            joinableTaskFactory
            );

        CollapseAllCommand = new DelegateCommand <HierarchyTreeViewItem>(
            CollapseAll,
            CanAlwaysExecute,
            joinableTaskFactory
            );

        ExpandAllCommand = new DelegateCommand <HierarchyTreeViewItem>(
            ExpandAll,
            CanAlwaysExecute,
            joinableTaskFactory
            );

        CheckAllCommand = new DelegateCommand(
            (_) => SetAllChecked(true),
            CanAlwaysExecute,
            joinableTaskFactory
            );

        UncheckAllCommand = new DelegateCommand(
            (_) => SetAllChecked(false),
            CanAlwaysExecute,
            joinableTaskFactory
            );

        ToggleRegularExpressionModeCommand = new DelegateCommand(
            (_) => UseRegularExpressions   = !UseRegularExpressions,
            CanAlwaysExecute,
            joinableTaskFactory
            );

        FocusSearchBoxCommand = new DelegateCommand(
            (_) => FocusSearchBoxSource.RequestFocus(),
            CanAlwaysExecute,
            joinableTaskFactory
            );

        AcceptCommand = new DelegateCommand(
            (_) => AcceptSelection(),
            CanAlwaysExecute,
            joinableTaskFactory
            );

        // Use a `DispatcherTimer` constructor without a callback
        // so that the timer doesn't start immediately. We only
        // want to start the timer when the search text changes.
        _debouncer         = debouncerFactory.Invoke(TimeSpan.FromMilliseconds(500));
        _debouncer.Stable += OnSearchStable;
    }