예제 #1
0
        public void TestAddChild()
        {
            //Arrange
            rootItem.Height     = 100;
            rootItem.Visibility = true;

            //Act
            browserItem.AddChild(rootItem);

            //In this part we are adding 2 childs BrowserInternalElement under rootItem

            var childItem1 = new BrowserInternalElement("Item 1", rootItem);

            childItem1.Height     = 100; //This will execute the Set method of the Height property
            childItem1.Visibility = true;
            rootItem.AddChild(childItem1);

            var childItem2 = new BrowserInternalElement("Item 2", rootItem);

            childItem2.Height     = 100; //This will execute the Set method of the Height property
            childItem2.Visibility = false;
            rootItem.AddChild(childItem2);


            List <BrowserItem> itemsList = new List <BrowserItem>();

            rootItem.GetVisibleLeaves(ref itemsList);

            //Assert
            //Checks that the height has a value greater than 0
            Assert.Greater(rootItem.Height, 0);
        }
        public void TestItemCollections()
        {
            //This is the root element
            BrowserInternalElement elemRoot = new BrowserInternalElement();

            //This is the default element child of root
            BrowserInternalElement elemDefault = new BrowserInternalElement("Default", elemRoot);

            //This are the child elements whose father is elemDefault
            BrowserInternalElement elemChild  = new BrowserInternalElement("Child", elemDefault);
            BrowserInternalElement elemChild2 = new BrowserInternalElement("Child2", elemDefault);

            BrowserInternalElement elemSon = new BrowserInternalElement("Son1", null);

            elemChild.AddChild(elemSon);

            BrowserInternalElement elemGrandSon = new BrowserInternalElement("GranSon1", null);

            elemSon.AddChild(elemGrandSon);

            //The elemDefault will have two childs
            elemDefault.AddChild(elemChild);
            elemDefault.AddChild(elemChild2);

            //This will allow to enter the section "if (this.Items.Count == 1)"
            elemChild.Execute();

            //This will enable the section where BrowserInternalElement.Siblings Get method is executed
            elemChild2.Execute();

            elemGrandSon.ExpandToRoot();
            elemChild.ReturnToOldParent();
            elemGrandSon.ReturnToOldParent();

            elemRoot.Items = null; //This will execute the Set method of the Items property

            //Just checking the Get method of the BrowserInternalElement.Name property
            Assert.AreEqual(elemGrandSon.Name, "GranSon1");

            //This will check that was expanded correctly by the ExpandToRoot() method
            Assert.IsTrue(elemRoot.IsExpanded);

            //This will check that is Visible (ExpandToRoot() method make it visible)
            Assert.IsTrue(elemRoot.Visibility);
        }
예제 #3
0
        /// <summary>
        ///     Performs a search and updates the observable SearchResults property.
        /// </summary>
        /// <param name="query"> The search query </param>
        public void SearchAndUpdateResults(string query)
        {
            if (Visible != true)
            {
                return;
            }

            //var sw = new Stopwatch();

            //sw.Start();

            var result = this.Model.Search(query).ToList();

            //sw.Stop();

            //this.dynamoViewModel.Model.Logger.Log(String.Format("Search complete in {0}", sw.Elapsed));

            // Remove old execute handler from old top result
            if (topResult.Items.Any() && topResult.Items.First() is NodeSearchElement)
            {
                var oldTopResult = topResult.Items.First() as NodeSearchElement;
                oldTopResult.Executed -= this.ExecuteElement;
            }

            // deselect the last selected item
            if (visibleSearchResults.Count > SelectedIndex)
            {
                visibleSearchResults[SelectedIndex].IsSelected = false;
            }

            // clear visible results list
            visibleSearchResults.Clear();

            // if the search query is empty, go back to the default treeview
            if (string.IsNullOrEmpty(query))
            {
                foreach (var ele in this.Model.BrowserRootCategories)
                {
                    ele.CollapseToLeaves();
                    ele.SetVisibilityToLeaves(true);
                }

                // hide the top result
                topResult.Visibility = false;
                return;
            }

            // otherwise, first collapse all
            foreach (var root in this.Model.BrowserRootCategories)
            {
                root.CollapseToLeaves();
                root.SetVisibilityToLeaves(false);
            }

            // if there are any results, add the top result
            if (result.Any() && result.ElementAt(0) is NodeSearchElement)
            {
                topResult.Items.Clear();

                var firstRes = (result.ElementAt(0) as NodeSearchElement);

                var copy = firstRes.Copy();
                copy.Executed += this.ExecuteElement;

                var catName = MakeShortCategoryString(firstRes.FullCategoryName);

                var breadCrumb = new BrowserInternalElement(catName, topResult);
                breadCrumb.AddChild(copy);
                topResult.AddChild(breadCrumb);

                topResult.SetVisibilityToLeaves(true);
                copy.ExpandToRoot();
            }

            // for all of the other results, show them in their category
            foreach (var ele in result)
            {
                ele.Visibility = true;
                ele.ExpandToRoot();
            }

            // create an ordered list of visible search results
            var baseBrowserItem = new BrowserRootElement("root");

            foreach (var root in Model.BrowserRootCategories)
            {
                baseBrowserItem.Items.Add(root);
            }

            baseBrowserItem.GetVisibleLeaves(ref visibleSearchResults);

            if (visibleSearchResults.Any())
            {
                this.SelectedIndex = 0;
                visibleSearchResults[0].IsSelected = true;
            }

            SearchResults.Clear();
            visibleSearchResults.ToList()
            .ForEach(x => SearchResults.Add((NodeSearchElement)x));
        }
예제 #4
0
        /// <summary>
        ///     Performs a search and updates the observable SearchResults property.
        /// </summary>
        /// <param name="query"> The search query </param>
        public void SearchAndUpdateResults(string query)
        {
            if (Visible != true)
                return;

            //var sw = new Stopwatch();

            //sw.Start();

            var result = this.Model.Search(query).ToList();

            //sw.Stop();
            
            //this.dynamoViewModel.Model.Logger.Log(String.Format("Search complete in {0}", sw.Elapsed));

            // Remove old execute handler from old top result
            if (topResult.Items.Any() && topResult.Items.First() is NodeSearchElement)
            {
                var oldTopResult = topResult.Items.First() as NodeSearchElement;
                oldTopResult.Executed -= this.ExecuteElement;
            }

            // deselect the last selected item
            if (visibleSearchResults.Count > SelectedIndex)
            {
                visibleSearchResults[SelectedIndex].IsSelected = false;
            }

            // clear visible results list
            visibleSearchResults.Clear();

            // if the search query is empty, go back to the default treeview
            if (string.IsNullOrEmpty(query))
            {
                foreach (var ele in this.Model.BrowserRootCategories)
                {
                    ele.CollapseToLeaves();
                    ele.SetVisibilityToLeaves(true);
                }

                // hide the top result
                topResult.Visibility = false;
                return;
            }

            // otherwise, first collapse all
            foreach (var root in this.Model.BrowserRootCategories)
            {
                root.CollapseToLeaves();
                root.SetVisibilityToLeaves(false);
            }

            // if there are any results, add the top result 
            if (result.Any() && result.ElementAt(0) is NodeSearchElement)
            {
                topResult.Items.Clear();

                var firstRes = (result.ElementAt(0) as NodeSearchElement);

                var copy = firstRes.Copy();
                copy.Executed += this.ExecuteElement;

                var catName = MakeShortCategoryString(firstRes.FullCategoryName);

                var breadCrumb = new BrowserInternalElement(catName, topResult);
                breadCrumb.AddChild(copy);
                topResult.AddChild(breadCrumb);

                topResult.SetVisibilityToLeaves(true);
                copy.ExpandToRoot();
            }

            // for all of the other results, show them in their category
            foreach (var ele in result)
            {
                ele.Visibility = true;
                ele.ExpandToRoot();
            }

            // create an ordered list of visible search results
            var baseBrowserItem = new BrowserRootElement("root");
            foreach (var root in Model.BrowserRootCategories)
            {
                baseBrowserItem.Items.Add(root);
            }

            baseBrowserItem.GetVisibleLeaves(ref visibleSearchResults);

            if (visibleSearchResults.Any())
            {
                this.SelectedIndex = 0;
                visibleSearchResults[0].IsSelected = true;
            }

            SearchResults.Clear();
            visibleSearchResults.ToList()
                .ForEach(x => SearchResults.Add((NodeSearchElement)x));

        }
예제 #5
0
        /// <summary>
        ///     Asynchronously performs a search and updates the observable SearchResults property.
        /// </summary>
        /// <param name="query"> The search query </param>
        public void SearchAndUpdateResults(string query)
        {
            if (Visible != true)
            {
                return;
            }

            Task <IEnumerable <SearchElementBase> > .Factory.StartNew(() =>
            {
                lock (SearchDictionary)
                {
                    return(Search(query));
                }
            }).ContinueWith((t) =>
            {
                lock (_visibleSearchResults)
                {
                    // deselect the last selected item
                    if (_visibleSearchResults.Count > SelectedIndex)
                    {
                        _visibleSearchResults[SelectedIndex].IsSelected = false;
                    }

                    // clear visible results list
                    _visibleSearchResults.Clear();

                    // if the search query is empty, go back to the default treeview
                    if (string.IsNullOrEmpty(query))
                    {
                        foreach (var ele in BrowserRootCategories)
                        {
                            ele.CollapseToLeaves();
                            ele.SetVisibilityToLeaves(true);
                        }

                        // hide the top result
                        _topResult.Visibility = false;

                        return;
                    }

                    // otherwise, first collapse all
                    foreach (var root in BrowserRootCategories)
                    {
                        root.CollapseToLeaves();
                        root.SetVisibilityToLeaves(false);
                    }

                    //// if there are any results, add the top result
                    if (t.Result.Any() && t.Result.ElementAt(0) is NodeSearchElement)
                    {
                        _topResult.Items.Clear();

                        var firstRes = (t.Result.ElementAt(0) as NodeSearchElement);

                        var copy = firstRes.Copy();

                        var catName = firstRes.FullCategoryName.Replace(".", " > ");

                        // if the category name is too long, we strip off the interior categories
                        if (catName.Length > 50)
                        {
                            var s = catName.Split('>').Select(x => x.Trim()).ToList();
                            if (s.Count() > 4)
                            {
                                s = new List <string>()
                                {
                                    s[0],
                                    "...",
                                    s[s.Count - 3],
                                    s[s.Count - 2],
                                    s[s.Count - 1]
                                };
                                catName = System.String.Join(" > ", s);
                            }
                        }

                        var breadCrumb = new BrowserInternalElement(catName, _topResult);
                        breadCrumb.AddChild(copy);
                        _topResult.AddChild(breadCrumb);

                        _topResult.SetVisibilityToLeaves(true);
                        copy.ExpandToRoot();
                    }

                    // for all of the other results, show them in their category
                    foreach (var ele in _searchElements)
                    {
                        if (t.Result.Contains(ele))
                        {
                            ele.Visibility = true;
                            ele.ExpandToRoot();
                        }
                    }

                    // create an ordered list of visible search results
                    var baseBrowserItem = new BrowserRootElement("root");
                    foreach (var root in BrowserRootCategories)
                    {
                        baseBrowserItem.Items.Add(root);
                    }

                    baseBrowserItem.GetVisibleLeaves(ref _visibleSearchResults);

                    if (_visibleSearchResults.Any())
                    {
                        this.SelectedIndex = 0;
                        _visibleSearchResults[0].IsSelected = true;
                    }

                    SearchResults.Clear();
                    _visibleSearchResults.ToList().ForEach(x => SearchResults.Add((NodeSearchElement)x));
                }
            }
                            , TaskScheduler.FromCurrentSynchronizationContext()); // run continuation in ui thread
        }
예제 #6
0
        /// <summary>
        ///     Asynchronously performs a search and updates the observable SearchResults property.
        /// </summary>
        /// <param name="query"> The search query </param>
        public void SearchAndUpdateResults(string query)
        {
            if (Visible != true)
                return;

            Task<IEnumerable<SearchElementBase>>.Factory.StartNew(() =>
                {
                    lock (SearchDictionary)
                    {
                        return Search(query);
                    }
                }).ContinueWith((t) =>
                    {

                        lock (_visibleSearchResults)
                        {

                            // deselect the last selected item
                            if (_visibleSearchResults.Count > SelectedIndex)
                            {
                                _visibleSearchResults[SelectedIndex].IsSelected = false;
                            }

                            // clear visible results list
                            _visibleSearchResults.Clear();

                            // if the search query is empty, go back to the default treeview
                            if (string.IsNullOrEmpty(query))
                            {

                                foreach (var ele in BrowserRootCategories)
                                {
                                    ele.CollapseToLeaves();
                                    ele.SetVisibilityToLeaves(true);
                                }

                                // hide the top result
                                _topResult.Visibility = false;

                                return;
                            }

                            // otherwise, first collapse all
                            foreach (var root in BrowserRootCategories)
                            {
                                root.CollapseToLeaves();
                                root.SetVisibilityToLeaves(false);
                            }

                            //// if there are any results, add the top result
                            if (t.Result.Any() && t.Result.ElementAt(0) is NodeSearchElement)
                            {
                                _topResult.Items.Clear();

                                var firstRes = (t.Result.ElementAt(0) as NodeSearchElement);

                                var copy = firstRes.Copy();

                                var catName = firstRes.FullCategoryName.Replace(".", " > ");

                                // if the category name is too long, we strip off the interior categories
                                if (catName.Length > 50)
                                {
                                    var s = catName.Split('>').Select(x => x.Trim()).ToList();
                                    if (s.Count() > 4)
                                    {
                                        s = new List<string>()
                                        {
                                            s[0],
                                            "...",
                                            s[s.Count - 3],
                                            s[s.Count - 2],
                                            s[s.Count - 1]
                                        };
                                        catName = System.String.Join(" > ", s);
                                    }
                                }

                                var breadCrumb = new BrowserInternalElement(catName, _topResult);
                                breadCrumb.AddChild(copy);
                                _topResult.AddChild(breadCrumb);

                                _topResult.SetVisibilityToLeaves(true);
                                copy.ExpandToRoot();

                            }

                            // for all of the other results, show them in their category
                            foreach (var ele in _searchElements)
                            {
                                if ( t.Result.Contains(ele) )
                                {
                                    ele.Visibility = true;
                                    ele.ExpandToRoot();
                                }
                            }

                            // create an ordered list of visible search results
                            var baseBrowserItem = new BrowserRootElement("root");
                            foreach (var root in BrowserRootCategories)
                            {
                                baseBrowserItem.Items.Add(root);
                            }

                            baseBrowserItem.GetVisibleLeaves(ref _visibleSearchResults);

                            if (_visibleSearchResults.Any())
                            {
                                this.SelectedIndex = 0;
                                _visibleSearchResults[0].IsSelected = true;
                            }

                            SearchResults.Clear();
                            _visibleSearchResults.ToList().ForEach(x => SearchResults.Add( (NodeSearchElement) x));
                        }

                    }
                    , TaskScheduler.FromCurrentSynchronizationContext()); // run continuation in ui thread
        }