示例#1
0
        public void TestCollapseToLeaves()
        {
            //Act
            browserItem.AddChild(rootItem);
            //We are adding five Browser elements more
            for (int i = 0; i < 5; i++)
            {
                var childItem = new BrowserInternalElement("Item" + i.ToString(), rootItem);
                childItem.Visibility = false;
                rootItem.AddChild(childItem);
            }
            List <BrowserItem> itemsList = new List <BrowserItem>();

            rootItem.GetVisibleLeaves(ref itemsList);

            rootItem.CollapseToLeaves();

            //Asert
            //When we called CollapseToLeaves the IsExpanded property should be false
            Assert.IsFalse(rootItem.IsExpanded);

            //Then we set the visibility to true
            rootItem.SetVisibilityToLeaves(true);

            //Asert
            //When we called SetVisibilityToLeaves the Visibility property is true
            Assert.IsTrue(rootItem.Visibility);
        }
示例#2
0
        /// <summary>
        /// Add a single category as a child of a category.  If the category already exists, just return that one.
        /// </summary>
        /// <param name="parent">The parent category </param>
        /// <param name="childCategoryName">The name of the child category (can't be nested)</param>
        /// <returns>The newly created category</returns>
        public BrowserItem TryAddChildCategory(BrowserItem parent, string childCategoryName)
        {
            var newCategoryName = parent.Name + CATEGORY_DELIMITER + childCategoryName;

            // support long nested categories like Math.Math.StaticMembers.Abs
            var parentItem = parent as BrowserInternalElement;

            while (parentItem != null)
            {
                var grandParent = parentItem.Parent;
                if (null == grandParent)
                {
                    break;
                }

                newCategoryName = grandParent.Name + CATEGORY_DELIMITER + newCategoryName;
                parentItem      = grandParent as BrowserInternalElement;
            }

            if (ContainsCategory(newCategoryName))
            {
                return(GetCategoryByName(newCategoryName));
            }

            var tempCat = new BrowserInternalElement(childCategoryName, parent);

            parent.AddChild(tempCat);

            return(tempCat);
        }
示例#3
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);
        }
示例#4
0
        public void CanAddCategory()
        {
            var model = new SearchViewModel();
            var root = model.AddRootCategory("Peter");
            var leafCat = new BrowserInternalElement("Boyer", root);
            root.Items.Add(leafCat);

            Assert.Contains(leafCat, root.Items );
            Assert.Contains( root, model.BrowserRootCategories );
        }
示例#5
0
        public void CanAddCategory()
        {
            var root    = search.TryAddRootCategory("Peter");
            var leafCat = new BrowserInternalElement("Boyer", root);

            root.Items.Add(leafCat);

            Assert.Contains(leafCat, root.Items);
            Assert.Contains(root, search.BrowserRootCategories);
        }
示例#6
0
        public void CanAddCategory()
        {
            var model   = new SearchViewModel();
            var root    = model.AddRootCategory("Peter");
            var leafCat = new BrowserInternalElement("Boyer", root);

            root.Items.Add(leafCat);

            Assert.Contains(leafCat, root.Items);
            Assert.Contains(root, model.BrowserRootCategories);
        }
示例#7
0
        /// <summary>
        ///     Add a category, given a delimited name
        /// </summary>
        /// <param name="categoryName">The comma delimited name </param>
        /// <returns>The newly created item</returns>
        public BrowserItem AddCategory(string categoryName)
        {
            // if already added, return immediately
            if (_browserCategoryDict.ContainsKey(categoryName))
            {
                return(_browserCategoryDict[categoryName]);
            }

            // otherwise split the categoryname
            var splitCat = new List <string>();

            if (categoryName.Contains(CATEGORY_DELIMITER))
            {
                splitCat = categoryName.Split(CATEGORY_DELIMITER).ToList();
            }
            else
            {
                splitCat.Add(categoryName);
            }

            // attempt to add root element
            if (splitCat.Count == 1)
            {
                return(this.AddRootCategory(categoryName));
            }

            var currentCatName = splitCat[0];

            // attempt to add all other categoires
            var currentCat = (BrowserItem)BrowserRootCategories.FirstOrDefault((x) => x.Name == splitCat[0]);

            if (currentCat == null)
            {
                currentCat = AddRootCategory(splitCat[0]);
            }

            for (var i = 1; i < splitCat.Count; i++)
            {
                currentCatName = currentCatName + CATEGORY_DELIMITER + splitCat[i];

                var tempCat = currentCat.Items.FirstOrDefault((x) => x.Name == splitCat[i]);
                if (tempCat == null)
                {
                    tempCat = new BrowserInternalElement(splitCat[i], currentCat);
                    currentCat.AddChild((BrowserInternalElement)tempCat);
                    _browserCategoryDict.Add(currentCatName, tempCat);
                }

                currentCat = tempCat;
            }

            return(currentCat);
        }
示例#8
0
        public void CanRemoveRootCategoryWithInternalElements()
        {
            var root    = (BrowserRootElement)search.TryAddRootCategory("Peter");
            var leafCat = new BrowserInternalElement("Boyer", root);

            root.Items.Add(leafCat);

            Assert.Contains(leafCat, root.Items);
            Assert.Contains(root, search.BrowserRootCategories);

            search.RemoveCategory("Peter");
            Assert.False(search.BrowserRootCategories.Contains(root));
        }
示例#9
0
        public void CanRemoveCategoryWithDelimiters()
        {
            var model = new SearchViewModel();
            var root = model.AddRootCategory("Peter");
            var leaf = new BrowserInternalElement("Boyer", root);
            root.AddChild(leaf);

            Assert.Contains(leaf, root.Items);
            Assert.Contains(root, model.BrowserRootCategories);

            model.RemoveCategory("Peter.Boyer");
            Assert.True( model.BrowserRootCategories.Contains(root) );
            Assert.False( root.Items.Contains(leaf) );
        }
示例#10
0
        public void CanRunRemoveCategoryIfCategoryDoesntExist()
        {
            var model = new SearchViewModel();
            var root = model.AddRootCategory("Peter");
            var leaf = new BrowserInternalElement("Boyer", root);
            root.AddChild(leaf);

            Assert.Contains(leaf, root.Items);
            Assert.Contains(root, model.BrowserRootCategories);

            model.RemoveCategory("Peter.Rabbit");
            Assert.True(model.BrowserRootCategories.Contains(root));
            Assert.True(root.Items.Contains(leaf));
        }
示例#11
0
        public void CanRemoveCategoryWithDelimiters()
        {
            var model = new SearchViewModel();
            var root  = model.AddRootCategory("Peter");
            var leaf  = new BrowserInternalElement("Boyer", root);

            root.AddChild(leaf);

            Assert.Contains(leaf, root.Items);
            Assert.Contains(root, model.BrowserRootCategories);

            model.RemoveCategory("Peter.Boyer");
            Assert.True(model.BrowserRootCategories.Contains(root));
            Assert.False(root.Items.Contains(leaf));
        }
示例#12
0
        /// <summary>
        ///     Attempt to add a new category to the browser and an item as one of its children
        /// </summary>
        /// <param name="category">The name of the category - a string possibly separated with one period </param>
        /// <param name="item">The item to add as a child of that category</param>
        public void TryAddCategoryAndItem(string category, BrowserInternalElement item)
        {
            var cat = this.AddCategory(category);

            cat.AddChild(item);

            item.FullCategoryName = category;

            var searchEleItem = item as SearchElementBase;

            if (searchEleItem != null)
            {
                _searchElements.Add(searchEleItem);
            }
        }
示例#13
0
        public void CanRunRemoveCategoryIfCategoryDoesntExist()
        {
            var model = new SearchViewModel();
            var root  = model.AddRootCategory("Peter");
            var leaf  = new BrowserInternalElement("Boyer", root);

            root.AddChild(leaf);

            Assert.Contains(leaf, root.Items);
            Assert.Contains(root, model.BrowserRootCategories);

            model.RemoveCategory("Peter.Rabbit");
            Assert.True(model.BrowserRootCategories.Contains(root));
            Assert.True(root.Items.Contains(leaf));
        }
示例#14
0
        /// <summary>
        /// Add a single category as a child of a category.  If the category already exists, just return that one.
        /// </summary>
        /// <param name="parent">The parent category </param>
        /// <param name="childCategoryName">The name of the child category (can't be nested)</param>
        /// <returns>The newly created category</returns>
        public BrowserItem TryAddChildCategory(BrowserItem parent, string childCategoryName)
        {
            var newCategoryName = parent.Name + CATEGORY_DELIMITER + childCategoryName;

            if (ContainsCategory(newCategoryName))
            {
                return(GetCategoryByName(newCategoryName));
            }

            var tempCat = new BrowserInternalElement(childCategoryName, parent);

            parent.AddChild(tempCat);

            return(tempCat);
        }
        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);
        }
示例#16
0
        /// <summary>
        ///     Attempt to add a new category to the browser and an item as one of its children
        /// </summary>
        /// <param name="category">The name of the category - a string possibly separated with one period </param>
        /// <param name="item">The item to add as a child of that category</param>
        public void TryAddCategoryAndItem(string category, BrowserInternalElement item)
        {
            if (!NodeCategories.ContainsKey(category))
            {
                NodeCategories.Add(category, new CategorySearchElement(category));
            }

            var cat = this.AddCategory(category);

            cat.AddChild(item);

            item.FullCategoryName = category;

            var searchEleItem = item as SearchElementBase;

            if (searchEleItem != null)
            {
                _browserLeaves.Add(searchEleItem);
            }
        }
示例#17
0
 internal static BrowserInternalElementViewModel WrapExplicit(BrowserInternalElement elem)
 {
     return(new BrowserInternalElementViewModel(elem));
 }
示例#18
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));
        }
示例#19
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));

        }
示例#20
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
        }
示例#21
0
        /// <summary>
        /// Add a single category as a child of a category.  If the category already exists, just return that one.
        /// </summary>
        /// <param name="parent">The parent category </param>
        /// <param name="childCategoryName">The name of the child category (can't be nested)</param>
        /// <returns>The newly created category</returns>
        public BrowserItem TryAddChildCategory(BrowserItem parent, string childCategoryName)
        {
            var newCategoryName = parent.Name + CATEGORY_DELIMITER + childCategoryName;
            if (ContainsCategory(newCategoryName))
            {
                return GetCategoryByName(newCategoryName);
            }

            var tempCat = new BrowserInternalElement(childCategoryName, parent);
            parent.AddChild(tempCat);

            return tempCat;
        }
示例#22
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
        }
示例#23
0
        /// <summary>
        ///     Add a category, given a delimited name
        /// </summary>
        /// <param name="categoryName">The comma delimited name </param>
        /// <returns>The newly created item</returns>
        public BrowserItem AddCategory(string categoryName)
        {
            // if already added, return immediately
            if (_browserCategoryDict.ContainsKey(categoryName) )
            {
                return _browserCategoryDict[categoryName];
            }

            // otherwise split the categoryname
            var splitCat = new List<string>();
            if (categoryName.Contains(CATEGORY_DELIMITER))
            {
                splitCat = categoryName.Split(CATEGORY_DELIMITER).ToList();
            }
            else
            {
                splitCat.Add(categoryName);
            }

            // attempt to add root element
            if (splitCat.Count == 1)
            {
                return this.AddRootCategory(categoryName);
            }

            var currentCatName = splitCat[0];

            // attempt to add all other categoires
            var currentCat = (BrowserItem) BrowserRootCategories.FirstOrDefault((x) => x.Name == splitCat[0]);
            if (currentCat == null)
            {
                currentCat = AddRootCategory(splitCat[0]);
            }

            for (var i = 1; i < splitCat.Count; i++)
            {
                currentCatName = currentCatName + CATEGORY_DELIMITER + splitCat[i];

                var tempCat = currentCat.Items.FirstOrDefault((x) => x.Name == splitCat[i]);
                if (tempCat == null)
                {
                    tempCat = new BrowserInternalElement(splitCat[i], currentCat);
                    currentCat.AddChild( (BrowserInternalElement) tempCat);
                    _browserCategoryDict.Add(currentCatName, tempCat);
                }

                currentCat = tempCat;

            }

            return currentCat;
        }
示例#24
0
        public void CanRemoveRootCategoryWithInternalElements()
        {
            var root = (BrowserRootElement)search.TryAddRootCategory("Peter");
            var leafCat = new BrowserInternalElement("Boyer", root);
            root.Items.Add(leafCat);

            Assert.Contains( leafCat, root.Items );
            Assert.Contains(root, search.BrowserRootCategories);

            search.RemoveCategory("Peter");
            Assert.False(search.BrowserRootCategories.Contains(root));
        }
示例#25
0
        /// <summary>
        ///     Attempt to add a new category to the browser and an item as one of its children
        /// </summary>
        /// <param name="category">The name of the category - a string possibly separated with one period </param>
        /// <param name="item">The item to add as a child of that category</param>
        public void TryAddCategoryAndItem( string category, BrowserInternalElement item )
        {
            if (!NodeCategories.ContainsKey(category))
            {
                NodeCategories.Add(category, new CategorySearchElement(category));
            }

            var cat = this.AddCategory(category);
            cat.AddChild(item);

            item.FullCategoryName = category;

            var searchEleItem = item as SearchElementBase;
            if (searchEleItem != null)
                _browserLeaves.Add(searchEleItem);
        }
示例#26
0
 public void SetUp()
 {
     browserItem = new BrowserInternalElement();
     rootItem    = new BrowserInternalElement("Root Node", null);
 }
示例#27
0
        /// <summary>
        /// Add a single category as a child of a category.  If the category already exists, just return that one.
        /// </summary>
        /// <param name="parent">The parent category </param>
        /// <param name="childCategoryName">The name of the child category (can't be nested)</param>
        /// <returns>The newly created category</returns>
        public BrowserItem TryAddChildCategory(BrowserItem parent, string childCategoryName)
        {
            var newCategoryName = parent.Name + CATEGORY_DELIMITER + childCategoryName;

            // support long nested categories like Math.Math.StaticMembers.Abs
            var parentItem  = parent as BrowserInternalElement;
            while (parentItem != null)
            {
                var grandParent = parentItem.Parent;
                if (null == grandParent)
                    break;

                newCategoryName = grandParent.Name + CATEGORY_DELIMITER + newCategoryName;
                parentItem = grandParent as BrowserInternalElement;
            }

            if (ContainsCategory(newCategoryName))
            {
                return GetCategoryByName(newCategoryName);
            }

            var tempCat = new BrowserInternalElement(childCategoryName, parent);
            parent.AddChild(tempCat);

            return tempCat;
        }
示例#28
0
        /// <summary>
        ///     Attempt to add a new category to the browser and an item as one of its children
        /// </summary>
        /// <param name="category">The name of the category - a string possibly separated with one period </param>
        /// <param name="item">The item to add as a child of that category</param>
        public void TryAddCategoryAndItem( string category, BrowserInternalElement item )
        {
            var cat = this.AddCategory(category);
            cat.AddChild(item);

            item.FullCategoryName = category;

            var searchEleItem = item as SearchElementBase;
            if (searchEleItem != null)
                _searchElements.Add(searchEleItem);
        }
示例#29
0
        public void CanAddCategory()
        {
            var root = search.TryAddRootCategory("Peter");
            var leafCat = new BrowserInternalElement("Boyer", root);
            root.Items.Add(leafCat);

            Assert.Contains( leafCat, root.Items );
            Assert.Contains(root, search.BrowserRootCategories);
            
        }
 public BrowserInternalElementViewModel(BrowserInternalElement model)
     : base(model)
 {
 }