/// <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 (ContainsCategory(categoryName)) { return(GetCategoryByName(categoryName)); } if (!NodeCategories.ContainsKey(categoryName)) { NodeCategories.Add(categoryName, new CategorySearchElement(categoryName)); } // otherwise split the category name var splitCat = SplitCategoryName(categoryName); // attempt to add root element if (splitCat.Count == 1) { return(this.TryAddRootCategory(categoryName)); } // attempt to add root category var currentCat = TryAddRootCategory(splitCat[0]); for (var i = 1; i < splitCat.Count; i++) { currentCat = TryAddChildCategory(currentCat, splitCat[i]); } return(currentCat); }
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); } } }
/// <summary> /// Add a category, given a delimited name /// </summary> /// <param name="categoryName">The comma delimited name </param> /// <returns>The newly created item</returns> internal BrowserItem AddCategory(string categoryName) { if (string.IsNullOrEmpty(categoryName)) { return(this.TryAddRootCategory("Uncategorized")); } if (ContainsCategory(categoryName)) { return(GetCategoryByName(categoryName)); } if (!NodeCategories.ContainsKey(categoryName)) { var cat = new CategorySearchElement(categoryName); cat.Executed += this.OnExecuted; NodeCategories.Add(categoryName, cat); } // otherwise split the category name var splitCat = SplitCategoryName(categoryName); // attempt to add root element if (splitCat.Count == 1) { return(this.TryAddRootCategory(categoryName)); } if (splitCat.Count == 0) { return(null); } // attempt to add root category var currentCat = TryAddRootCategory(splitCat[0]); for (var i = 1; i < splitCat.Count; i++) { currentCat = TryAddChildCategory(currentCat, splitCat[i]); } return(currentCat); }
/// <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); } }
/// <summary> /// Attempts to remove all traces of a particular custom node from Dynamo, assuming the node is not in a loaded workspace. /// </summary> /// <param name="guid"></param> public void Remove(Guid guid) { if (loadedNodes.ContainsKey(guid)) { loadedNodes.Remove(guid); } if (nodePaths.ContainsKey(guid)) { nodePaths.Remove(guid); } if (NodeCategories.ContainsKey(guid)) { NodeCategories.Remove(guid); } var nodeName = NodeNames.Where((x) => x.Value == guid).ToList(); nodeName.ForEach((pair) => { NodeNames.Remove(pair.Key); dynSettings.Controller.SearchViewModel.Remove(pair.Key); }); dynSettings.Controller.SearchViewModel.SearchAndUpdateResults(); dynSettings.Controller.FSchemeEnvironment.RemoveSymbol(guid.ToString()); }