private IEnumerable <RootNodeCategoryViewModel> CategorizeEntries(IEnumerable <NodeSearchElement> entries, bool expanded) { var tempRoot = entries.GroupByRecursive <NodeSearchElement, string, NodeCategoryViewModel>( element => element.Categories, (name, subs, es) => { var category = new NodeCategoryViewModel(name, es.OrderBy(en => en.Name).Select(MakeNodeSearchElementVM), subs); category.IsExpanded = expanded; category.RequestBitmapSource += SearchViewModelRequestBitmapSource; category.RequestReturnFocusToSearch += OnRequestFocusSearch; return(category); }, ""); var result = tempRoot.SubCategories.Select(cat => { var rootCat = new RootNodeCategoryViewModel(cat.Name, cat.Entries, cat.SubCategories) { IsExpanded = expanded }; rootCat.RequestReturnFocusToSearch += OnRequestFocusSearch; return(rootCat); }); tempRoot.Dispose(); return(result.OrderBy(cat => cat.Name)); }
private IEnumerable <RootNodeCategoryViewModel> CategorizeEntries(IEnumerable <NodeSearchElement> entries, bool expanded) { var tempRoot = entries.GroupByRecursive <NodeSearchElement, string, NodeCategoryViewModel>( element => element.Categories, (name, subs, es) => { var category = new NodeCategoryViewModel(name, es.OrderBy(en => en.Name).Select(MakeNodeSearchElementVM), subs); category.IsExpanded = expanded; category.RequestBitmapSource += SearchViewModelRequestBitmapSource; category.RequestReturnFocusToSearch += OnRequestFocusSearch; return(category); }, ""); var result = tempRoot.SubCategories.Select(cat => { var rootCat = new RootNodeCategoryViewModel(cat.Name, cat.Entries, cat.SubCategories) { IsExpanded = expanded }; rootCat.RequestReturnFocusToSearch += OnRequestFocusSearch; // Since all the root categories will be new RootNodeCategoryViewModel objects, // we should dispose the old ones. Since they are still watching for subcategories' // property changes, they will never be garbage collected. cat.Dispose(); return(rootCat); }); tempRoot.Dispose(); return(result.OrderBy(cat => cat.Name)); }
public void BrowserInternalElementToBoolConverterTest() { var converter = new NodeCategoryVMToBoolConverter(); var NcVM = new NodeCategoryViewModel(""); var RncVM = new RootNodeCategoryViewModel(""); var CncVM = new ClassesNodeCategoryViewModel(RncVM); object result; //1. Element is null. //2. Element is NodeCategoryViewModel. //2. Element is RootNodeCategoryViewModel. //2. Element is ClassesNodeCategoryViewModel. // 1 case result = converter.Convert(null, null, null, null); Assert.AreEqual(false, result); // 2 case result = converter.Convert(NcVM, null, null, null); Assert.AreEqual(true, result); // 3 case result = converter.Convert(RncVM, null, null, null); Assert.AreEqual(false, result); // 4 case result = converter.Convert(CncVM, null, null, null); Assert.AreEqual(false, result); }
public void RootElementToBoolConverterTest() { var converter = new RootElementVMToBoolConverter(); var RncVM = new RootNodeCategoryViewModel(""); object result; //1. Element is null. //2. Element is RootNodeCategoryViewModel. // 1 case result = converter.Convert(null, null, null, null); Assert.AreEqual(false, result); // 2 case result = converter.Convert(RncVM, null, null, null); Assert.AreEqual(true, result); }
public void ElementTypeToBoolConverterTest() { ElementTypeToBoolConverter converter = new ElementTypeToBoolConverter(); var NseVM = new NodeSearchElementViewModel( new NodeModelSearchElement(new TypeLoadData(typeof(Dynamo.Nodes.Symbol))), null); var NcVM = new NodeCategoryViewModel(""); var RncVM = new RootNodeCategoryViewModel(""); var CncVM = new ClassesNodeCategoryViewModel(RncVM); object result; //1. Element is null. //2. Element is NodeSearchElement. //3. Element is NodeCategoryViewModel. //4. Element is RootNodeCategoryViewModel. //5. Element is RootNodeCategoryViewModel with ClassesNodeCategoryViewModel. // 1 case result = converter.Convert(null, null, null, null); Assert.AreEqual(false, result); // 2 case result = converter.Convert(NseVM, null, null, null); Assert.AreEqual(false, result); // 3 case result = converter.Convert(NcVM, null, null, null); Assert.AreEqual(true, result); // 4 case result = converter.Convert(RncVM, null, null, null); Assert.AreEqual(true, result); // 5 case RncVM.SubCategories.Add(CncVM); result = converter.Convert(RncVM, null, null, null); Assert.AreEqual(false, result); }
/// <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; } // deselect the last selected item if (visibleSearchResults.Count > SelectedIndex) { visibleSearchResults[SelectedIndex].IsSelected = false; } // if the search query is empty, go back to the default treeview if (string.IsNullOrEmpty(query)) { return; } // clear visible results list visibleSearchResults.Clear(); foreach (var category in SearchRootCategories) { category.DisposeTree(); } SearchRootCategories.Clear(); if (string.IsNullOrEmpty(query)) { return; } var result = Model.Search(query).Where(r => r.IsVisibleInSearch).Take(MaxNumSearchResults).ToList(); // Add top result var firstRes = result.FirstOrDefault(); if (firstRes == null) { return; //No results } var topResultCategory = new RootNodeCategoryViewModel("Top Result"); SearchRootCategories.Add(topResultCategory); var copy = MakeNodeSearchElementVM(firstRes); var catName = MakeShortCategoryString(firstRes.FullCategoryName); var breadCrumb = new NodeCategoryViewModel(catName) { IsExpanded = true }; breadCrumb.Entries.Add(copy); topResultCategory.SubCategories.Add(breadCrumb); topResultCategory.Visibility = true; topResultCategory.IsExpanded = true; SearchRootCategories.AddRange(CategorizeEntries(result, true)); visibleSearchResults.AddRange(SearchRootCategories.SelectMany(GetVisibleSearchResults)); if (visibleSearchResults.Any()) { SelectedIndex = 0; visibleSearchResults[0].IsSelected = true; } SearchResults.Clear(); foreach (var x in visibleSearchResults) { SearchResults.Add(x); } }