Exemple #1
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));

        }
Exemple #2
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 != Visibility.Visible)
                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) || query == "Search...")
                            {

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

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

                                return;
                            }

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

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

                                _topResult.SetVisibilityToLeaves(Visibility.Visible);
                                _topResult.IsExpanded = true;
                            }

                            // for all of the other results, show them in their category
                            foreach (var ele in _browserLeaves)
                            {
                                if (t.Result.Contains(ele))
                                {
                                    ele.Visibility = Visibility.Visible;
                                    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;
                            }
                        }

                    }
                    , TaskScheduler.FromCurrentSynchronizationContext()); // run continuation in ui thread
        }
Exemple #3
0
        private void InitializeCore()
        {
            SelectedIndex = 0;
            SearchResults = new ObservableCollection<SearchElementBase>();
            Visible = false;
            searchText = "";

            topResult = this.Model.AddRootCategoryToStart("Top Result");
            
            this.Model.RequestSync += ModelOnRequestSync;
            this.Model.Executed += ExecuteElement;
        }
Exemple #4
0
        /// <summary>
        ///     The class constructor.
        /// </summary>
        /// <param name="bench"> Reference to dynBench object for logging </param>
        public SearchViewModel()
        {
            SelectedIndex = 0;
            RevitApiSearchElements = new List<SearchElementBase>();
            NodeCategories = new Dictionary<string, CategorySearchElement>();
            SearchDictionary = new SearchDictionary<SearchElementBase>();
            SearchResults = new ObservableCollection<SearchElementBase>();
            MaxNumSearchResults = 20;
            Visible = Visibility.Collapsed;
            _SearchText = "";
            IncludeRevitAPIElements = false; // revit api
            Regions = new ObservableDictionary<string, RegionBase>();
            //Regions.Add("Include Nodes from Package Manager", DynamoCommands.PackageManagerRegionCommand );
            Regions.Add("Include Experimental Revit API Nodes", new RevitAPIRegion());

            _topResult = this.AddRootCategory("Top Result");
            this.AddRootCategory(BuiltinNodeCategories.CORE);
            this.AddRootCategory(BuiltinNodeCategories.LOGIC);
            this.AddRootCategory(BuiltinNodeCategories.CREATEGEOMETRY);
            this.AddRootCategory(BuiltinNodeCategories.MODIFYGEOMETRY);
            this.AddRootCategory(BuiltinNodeCategories.REVIT);
            this.AddRootCategory(BuiltinNodeCategories.IO);
            this.AddRootCategory(BuiltinNodeCategories.SCRIPTING);
            this.AddRootCategory(BuiltinNodeCategories.ANALYZE);
        }
Exemple #5
0
 public BrowserRootElement AddRootCategory(string name)
 {
     var ele = new BrowserRootElement(name, BrowserRootCategories);
     BrowserRootCategories.Add(ele);
     this._browserCategoryDict.Add(name, ele);
     return ele;
 }
        public void RemoveEmptyRootCategory(BrowserRootElement rootEle)
        {
            if (!ContainsCategory(rootEle.Name))
                return;

            BrowserRootCategories.Remove(rootEle);
        }
        /// <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
        }
 /// <summary>
 /// Add a root category, assuming it doesn't already exist
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 private BrowserRootElement AddRootCategory(string name)
 {
     var ele = new BrowserRootElement(name, BrowserRootCategories);
     BrowserRootCategories.Add(ele);
     return ele;
 }
        /// <summary>
        ///     The class constructor.
        /// </summary>
        /// <param name="bench"> Reference to dynBench object for logging </param>
        public SearchViewModel()
        {
            SelectedIndex = 0;
            RevitApiSearchElements = new List<SearchElementBase>();
            NodeCategories = new Dictionary<string, CategorySearchElement>();
            SearchDictionary = new SearchDictionary<SearchElementBase>();
            SearchResults = new ObservableCollection<SearchElementBase>();
            MaxNumSearchResults = 35;
            Visible = false;
            searchText = "";
            IncludeRevitAPIElements = true; // revit api

            _topResult = this.AddRootCategory("Top Result");
            this.AddRootCategory(BuiltinNodeCategories.CORE);
            this.AddRootCategory(BuiltinNodeCategories.LOGIC);
            this.AddRootCategory(BuiltinNodeCategories.GEOMETRY);
            this.AddRootCategory(BuiltinNodeCategories.REVIT);
            this.AddRootCategory(BuiltinNodeCategories.ANALYZE);
            this.AddRootCategory(BuiltinNodeCategories.IO);
        }
Exemple #10
0
 /// <summary>
 /// Add a root category, assuming it doesn't already exist
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 internal BrowserRootElement AddRootCategoryToStart(string name)
 {
     var ele = new BrowserRootElement(name, BrowserRootCategories);
     BrowserRootCategories.Insert(0, ele);
     return ele;
 }
Exemple #11
0
            public void Execute(object parameters)
            {
                if (item is PackageManagerSearchElement)
                {
                    item.IsExpanded = !item.IsExpanded;
                    return;
                }

                if (item is SearchElementBase)
                {
                    ((SearchElementBase)item).Execute();
                    return;
                }
                var endState = !item.IsExpanded;

                if (item is BrowserInternalElement)
                {
                    BrowserInternalElement element = (BrowserInternalElement)item;
                    foreach (var ele in element.Siblings)
                    {
                        ele.IsExpanded = false;
                    }

                    //Walk down the tree expanding anything nested one layer deep
                    //this can be removed when we have the hierachy implemented properly
                    if (element.Items.Count == 1)
                    {
                        BrowserItem subElement = element.Items[0];

                        while (subElement.Items.Count == 1)
                        {
                            subElement.IsExpanded = true;
                            subElement            = subElement.Items[0];
                        }

                        subElement.IsExpanded = true;
                    }
                }

                if (item is BrowserRootElement)
                {
                    BrowserRootElement element = (BrowserRootElement)item;
                    foreach (var ele in element.Siblings)
                    {
                        ele.IsExpanded = false;
                    }


                    //Walk down the tree expanding anything nested one layer deep
                    //this can be removed when we have the hierachy implemented properly
                    if (element.Items.Count == 1)
                    {
                        BrowserItem subElement = element.Items[0];

                        while (subElement.Items.Count == 1)
                        {
                            subElement.IsExpanded = true;
                            subElement            = subElement.Items[0];
                        }

                        subElement.IsExpanded = true;
                    }
                }
                item.IsExpanded = endState;
            }
Exemple #12
0
        private void InitializeCore()
        {
            SelectedIndex = 0;
            NodeCategories = new Dictionary<string, CategorySearchElement>();
            SearchDictionary = new SearchDictionary<SearchElementBase>();
            SearchResults = new ObservableCollection<SearchElementBase>();
            MaxNumSearchResults = 35;
            Visible = false;
            searchText = "";

            _topResult = this.AddRootCategory("Top Result");
            this.AddRootCategory(BuiltinNodeCategories.CORE);
            this.AddRootCategory(BuiltinNodeCategories.LOGIC);
            this.AddRootCategory(BuiltinNodeCategories.GEOMETRY);
            this.AddRootCategory(BuiltinNodeCategories.REVIT);
            this.AddRootCategory(BuiltinNodeCategories.ANALYZE);
            this.AddRootCategory(BuiltinNodeCategories.IO);
        }