/// <summary> /// If Revit API elements are shown, hides them. Otherwise, /// shows them. Update search when done with either. /// </summary> public void ToggleIncludingRevitAPIElements() { if (!IncludeRevitAPIElements) { this.RemoveCategory(BuiltinNodeCategories.REVIT_API); foreach (var ele in RevitApiSearchElements) { SearchDictionary.Remove(ele, ele.Name); if (!(ele is CategorySearchElement)) { SearchDictionary.Remove(ele, BuiltinNodeCategories.REVIT_API + "." + ele.Name); } } } else { var revitCat = this.AddCategory(BuiltinNodeCategories.REVIT_API); bool addToCat = !revitCat.Items.Any(); // add elements to search foreach (var ele in RevitApiSearchElements) { if (addToCat) { revitCat.Items.Add(ele); } SearchDictionary.Add(ele, ele.Name); if (!(ele is CategorySearchElement)) { SearchDictionary.Add(ele, BuiltinNodeCategories.REVIT_API + "." + ele.Name); } } } }
/// <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); }
internal void RemoveNode(Guid funcId) { // remove from search dictionary SearchDictionary.Remove((x) => x is CustomNodeSearchElement && ((CustomNodeSearchElement)x).Guid == funcId); // remove from browser leaves _searchElements.Where(x => x is CustomNodeSearchElement && ((CustomNodeSearchElement)x).Guid == funcId).ToList().ForEach(x => _searchElements.Remove(x)); }
internal void RemoveNode(string nodeName) { // remove from search dictionary SearchDictionary.Remove((ele) => (ele).Name == nodeName); SearchDictionary.Remove((ele) => (ele).Name.EndsWith("." + nodeName)); // remove from browser leaves _searchElements.Where(x => x.Name == nodeName).ToList().ForEach(x => _searchElements.Remove(x)); }
/// <summary> /// Performs a search using the given string as query, but does not update /// the SearchResults object. /// </summary> /// <returns> Returns a list with a maximum MaxNumSearchResults elements.</returns> /// <param name="search"> The search query </param> internal IEnumerable <SearchElementBase> Search(string search) { if (string.IsNullOrEmpty(search)) { return(_searchElements); } return(SearchDictionary.Search(search, MaxNumSearchResults)); }
/// <summary> /// Performs a search using the given string as query, but does not update /// the SearchResults object. /// </summary> /// <returns> Returns a list with a maximum MaxNumSearchResults elements.</returns> /// <param name="search"> The search query </param> internal List <SearchElementBase> Search(string search) { if (string.IsNullOrEmpty(search) || search == "Search...") { return(_browserLeaves); } return(SearchDictionary.Search(search, MaxNumSearchResults)); }
/// <summary> /// Adds a PackageHeader, recently downloaded from the Package Manager, to Search /// </summary> /// <param name="packageHeader">A PackageHeader object</param> public void Add(PackageHeader packageHeader) { var searchEle = new PackageManagerSearchElement(packageHeader); SearchDictionary.Add(searchEle, searchEle.Name); if (packageHeader.keywords != null && packageHeader.keywords.Count > 0) { SearchDictionary.Add(searchEle, packageHeader.keywords); } SearchDictionary.Add(searchEle, searchEle.Description); SearchAndUpdateResultsSync(SearchText); }
public void Remove(string nodeName) { // get the node, return if not found var nodes = _browserLeaves.Where(x => x.Name == nodeName); if (!nodes.Any()) { return; } // remove from search dictionary SearchDictionary.Remove((ele) => (ele).Name == nodeName); SearchDictionary.Remove((ele) => (ele).Name.EndsWith("." + nodeName)); // remove from browser leaves _browserLeaves.Where(x => x.Name == nodeName).ToList().ForEach(x => _browserLeaves.Remove(x)); // get the category if it doesn't exist, then remove it foreach (var node in nodes) { var categoryName = ((SearchElementBase)node).FullCategoryName; var parentCategoryName = ((BrowserInternalElement)node).Parent.Name; if (!NodeCategories.ContainsKey(categoryName)) { return; } // first level category var pcategory = NodeCategories[parentCategoryName]; pcategory.NumElements--; if (pcategory.NumElements == 0) { this.RemoveCategory(pcategory.Name); } // immediate category var category = NodeCategories[categoryName]; category.NumElements--; if (category.NumElements == 0) { this.RemoveCategory(category.Name); } } }
private void InitializeCore() { NodeCategories = new Dictionary <string, CategorySearchElement>(); SearchDictionary = new SearchDictionary <SearchElementBase>(); MaxNumSearchResults = 15; // pre-populate the search categories this.AddRootCategory(BuiltinNodeCategories.CORE); this.AddRootCategory(LibraryServices.Categories.BuiltIns); this.AddRootCategory(LibraryServices.Categories.Operators); this.AddRootCategory(BuiltinNodeCategories.GEOMETRY); this.AddRootCategory(BuiltinNodeCategories.REVIT); this.AddRootCategory(BuiltinNodeCategories.ANALYZE); this.AddRootCategory("Units"); this.AddRootCategory("Office"); this.AddRootCategory("Migration"); }
public bool Add(CustomNodeInfo nodeInfo) { var nodeEle = new CustomNodeSearchElement(nodeInfo); nodeEle.Executed += this.OnExecuted; if (SearchDictionary.Contains(nodeEle)) { return(this.Refactor(nodeInfo)); } SearchDictionary.Add(nodeEle, nodeEle.Name); SearchDictionary.Add(nodeEle, nodeInfo.Category + "." + nodeEle.Name); TryAddCategoryAndItem(nodeInfo.Category, nodeEle); return(true); }
/// <summary> /// Add a custom node to search. /// </summary> /// <param name="workspace">A dynWorkspace to add</param> /// <param name="name">The name to use</param> public void Add(string name, string category, string description, Guid functionId) { if (name == "Home") { return; } // create the node in search var nodeEle = new NodeSearchElement(name, description, functionId); if (SearchDictionary.Contains(nodeEle)) { return; } SearchDictionary.Add(nodeEle, nodeEle.Name); SearchDictionary.Add(nodeEle, category + "." + nodeEle.Name); TryAddCategoryAndItem(category, nodeEle); NodeCategories[category].NumElements++; }
/// <summary> /// Adds a local DynNode to search /// </summary> /// <param name="dynNode">A Dynamo node object</param> public void Add(Type t) { // get name, category, attributes (this is terribly ugly...) var attribs = t.GetCustomAttributes(typeof(NodeNameAttribute), false); var name = ""; if (attribs.Length > 0) { name = (attribs[0] as NodeNameAttribute).Name; } attribs = t.GetCustomAttributes(typeof(NodeCategoryAttribute), false); var cat = ""; if (attribs.Length > 0) { cat = (attribs[0] as NodeCategoryAttribute).ElementCategory; } attribs = t.GetCustomAttributes(typeof(NodeSearchTagsAttribute), false); var tags = new List <string>(); if (attribs.Length > 0) { tags = (attribs[0] as NodeSearchTagsAttribute).Tags; } attribs = t.GetCustomAttributes(typeof(NodeDescriptionAttribute), false); var description = ""; if (attribs.Length > 0) { description = (attribs[0] as NodeDescriptionAttribute).ElementDescription; } var searchEle = new NodeSearchElement(name, description, tags, t.FullName); searchEle.Executed += this.OnExecuted; attribs = t.GetCustomAttributes(typeof(NodeSearchableAttribute), false); bool searchable = true; if (attribs.Length > 0) { searchable = (attribs[0] as NodeSearchableAttribute).IsSearchable; } searchEle.SetSearchable(searchable); attribs = t.GetCustomAttributes(typeof(NotSearchableInHomeWorkspace), false); if (attribs.Length > 0) { this.NodesHiddenInHomeWorkspace.Add(searchEle); if (this.DynamoModel != null && this.DynamoModel.CurrentWorkspace != null && this.DynamoModel.CurrentWorkspace is HomeWorkspaceModel) { searchEle.SetSearchable(false); } } attribs = t.GetCustomAttributes(typeof(NotSearchableInCustomNodeWorkspace), false); if (attribs.Length > 0) { this.NodesHiddenInCustomNodeWorkspace.Add(searchEle); if (this.DynamoModel != null && this.DynamoModel.CurrentWorkspace != null && this.DynamoModel.CurrentWorkspace is CustomNodeWorkspaceModel) { searchEle.SetSearchable(false); } } if (!string.IsNullOrEmpty(cat)) { SearchDictionary.Add(searchEle, cat + "." + searchEle.Name); } TryAddCategoryAndItem(cat, searchEle); SearchDictionary.Add(searchEle, searchEle.Name); if (tags.Count > 0) { // reduce the weight in search by adding white space tags.ForEach(x => SearchDictionary.Add(searchEle, x + "++++++++")); } SearchDictionary.Add(searchEle, description); }
/// <summary> /// Adds DesignScript function groups /// </summary> /// <param name="func"></param> public void Add(IEnumerable <FunctionGroup> functionGroups) { if (null == functionGroups) { return; } foreach (var functionGroup in functionGroups) { var functions = functionGroup.Functions.ToList(); if (!functions.Any()) { continue; } bool isOverloaded = functions.Count > 1; foreach (var function in functions) { //Don't add the functions that are not visible in library. if (!function.IsVisibleInLibrary) { continue; } // For overloaded functions, only parameters are displayed // for this item. E.g, for Count(), on UI it is: // // -> Abs // +----------------+ // | dValue: double | // +----------------+ // | nValue: int | // +----------------+ var displayString = function.UserFriendlyName; var category = function.Category; // do not add GetType method names to search if (displayString.Contains("GetType")) { continue; } if (isOverloaded) { var args = string.Join(", ", function.Parameters.Select(p => p.ToString())); if (!string.IsNullOrEmpty(args)) { displayString = displayString + "(" + args + ")"; } } var searchElement = new DSFunctionNodeSearchElement(displayString, function); searchElement.SetSearchable(true); searchElement.FullCategoryName = category; searchElement.Executed += this.OnExecuted; // Add this search eleemnt to the search view TryAddCategoryAndItem(category, searchElement); // function.QualifiedName is the search string for this // element SearchDictionary.Add(searchElement, function.QualifiedName); // add all search tags function.GetSearchTags().ToList().ForEach(x => SearchDictionary.Add(searchElement, x)); } } }
/// <summary> /// Adds a local DynNode to search /// </summary> /// <param name="dynNode">A Dynamo node object</param> public void Add(Type t) { // get name, category, attributes (this is terribly ugly...) var attribs = t.GetCustomAttributes(typeof(NodeNameAttribute), false); var name = ""; if (attribs.Length > 0) { name = (attribs[0] as NodeNameAttribute).Name; } attribs = t.GetCustomAttributes(typeof(NodeCategoryAttribute), false); var cat = ""; if (attribs.Length > 0) { cat = (attribs[0] as NodeCategoryAttribute).ElementCategory; } attribs = t.GetCustomAttributes(typeof(NodeSearchTagsAttribute), false); var tags = new List <string>(); if (attribs.Length > 0) { tags = (attribs[0] as NodeSearchTagsAttribute).Tags; } attribs = t.GetCustomAttributes(typeof(NodeDescriptionAttribute), false); var description = ""; if (attribs.Length > 0) { description = (attribs[0] as NodeDescriptionAttribute).ElementDescription; } var searchEle = new NodeSearchElement(name, description, tags); attribs = t.GetCustomAttributes(typeof(NodeSearchableAttribute), false); bool searchable = true; if (attribs.Length > 0) { searchable = (attribs[0] as NodeSearchableAttribute).IsSearchable; } searchEle.SetSearchable(searchable); // if it's a revit search element, keep track of it if (cat.Equals(BuiltinNodeCategories.REVIT_API)) { this.RevitApiSearchElements.Add(searchEle); if (!IncludeRevitAPIElements) { return; } } if (!string.IsNullOrEmpty(cat)) { SearchDictionary.Add(searchEle, cat + "." + searchEle.Name); } TryAddCategoryAndItem(cat, searchEle); SearchDictionary.Add(searchEle, searchEle.Name); if (tags.Count > 0) { SearchDictionary.Add(searchEle, tags); } SearchDictionary.Add(searchEle, description); }
/// <summary> /// Adds the Home Workspace to search. /// </summary> private void AddHomeToSearch() { SearchDictionary.Add(new WorkspaceSearchElement("Home", "Navigate to Home Workspace"), "Home"); }