public NodeSearchElementViewModel(NodeSearchElement element, SearchViewModel svm) { Model = element; searchViewModel = svm; Model.VisibilityChanged += ModelOnVisibilityChanged; if (searchViewModel != null) Clicked += searchViewModel.OnSearchElementClicked; ClickedCommand = new DelegateCommand(OnClicked); }
public new bool Equals(NodeSearchElement other) { return(other is CustomNodeSearchElement && this.Equals(other as CustomNodeSearchElement)); }
private NodeSearchElementViewModel MakeNodeSearchElementVM(NodeSearchElement entry) { var element = entry as CustomNodeSearchElement; var elementVM = element != null ? new CustomNodeSearchElementViewModel(element, this) : new NodeSearchElementViewModel(entry, this); elementVM.RequestBitmapSource += SearchViewModelRequestBitmapSource; return elementVM; }
private void ExecuteElement(NodeSearchElement element) { // create node var guid = Guid.NewGuid(); dynamoViewModel.ExecuteCommand( new DynamoViewModel.CreateNodeCommand(guid, element.FullName, 0, 0, true, true)); // select node var placedNode = dynamoViewModel.Model.Nodes.Find((node) => node.GUID == guid); if (placedNode != null) { DynamoSelection.Instance.ClearSelection(); DynamoSelection.Instance.Selection.Add(placedNode); } }
internal void RemoveEntry(NodeSearchElement entry) { var branch = GetTreeBranchToNode(libraryRoot, entry); if (!branch.Any()) return; var treeStack = new Stack<NodeCategoryViewModel>(branch.Reverse()); var target = treeStack.Pop(); var location = target.Entries.Select((e, i) => new { e.Model, i }) .FirstOrDefault(x => entry == x.Model); if (location == null) return; target.Entries.RemoveAt(location.i); while (!target.Items.Any() && treeStack.Any()) { var parent = treeStack.Pop(); parent.SubCategories.Remove(target); parent.Items.Remove(target); // Check to see if all items under "parent" are removed, leaving behind only one // entry that is "ClassInformationViewModel" (a class used to show ClassInformationView). // If that is the case, remove the "ClassInformationViewModel" at the same time. if (parent.Items.Count == 1 && parent.Items[0] is ClassInformationViewModel) parent.Items.RemoveAt(0); target = parent; } // After removal of category "target" can become the class. // In this case we need to add target to existing classes contaiiner // (ClassesNodeCategoryViewModel) or create new one. // For example we have a structure. // // Top // │ // Sub1_1 // ┌────────────┤ // Sub2_1 Classes // ┌────────┤ │ // Classes Member2 Sub2_2 // │ │ // Sub3_1 Member3 // │ // Member1 // // Let's remove "Member1". Before next code we have removed entry "Member1" and // categories "Sub3_1", "Classes". "Sub2_1" is "target" as soon as it has one item in // Items collection. Next code will deattach from "Sub1_1" and attach target to another // "Classes" category. // Structure should become. // // Top // │ // Sub1_1 // │ // Classes // ┌──────────┤ // Sub2_1 Sub2_2 // │ │ // Member2 Member3 // if (treeStack.Any() && !target.SubCategories.Any()) { var parent = treeStack.Pop(); // Do not continue if parent is already in classes container. if (parent is ClassesNodeCategoryViewModel && parent.SubCategories.Contains(target)) return; // Do not continue as soon as our target is not class. if (target.SubCategories.Any()) return; if (!(parent.SubCategories[0] is ClassesNodeCategoryViewModel)) parent.SubCategories.Insert(0, new ClassesNodeCategoryViewModel(parent)); if (!parent.SubCategories[0].SubCategories.Contains(target)) { // Reattach target from parent to classes container. parent.SubCategories.Remove(target); parent.SubCategories[0].SubCategories.Add(target); } } }
private static IEnumerable<NodeCategoryViewModel> GetTreeBranchToNode( NodeCategoryViewModel rootNode, NodeSearchElement leafNode) { var nodesOnBranch = new Stack<NodeCategoryViewModel>(); var nameStack = new Stack<string>(leafNode.Categories.Reverse()); var target = rootNode; bool isCheckedForClassesCategory = false; while (nameStack.Any()) { var next = nameStack.Pop(); var categories = target.SubCategories; var newTarget = categories.FirstOrDefault(c => c.Name == next); if (newTarget == null) { // The last entry in categories list can be a class name. When the desired class // cannot be located with "MyAssembly.MyNamespace.ClassCandidate" pattern, try // searching with "MyAssembly.MyNamespace.Classes.ClassCandidate" instead. This // is because a class always resides under a "ClassesNodeCategoryViewModel" node. // if (!isCheckedForClassesCategory && nameStack.Count == 0) { nameStack.Push(next); nameStack.Push(Configurations.ClassesDefaultName); isCheckedForClassesCategory = true; continue; } return Enumerable.Empty<NodeCategoryViewModel>(); } nodesOnBranch.Push(target); target = newTarget; } nodesOnBranch.Push(target); return nodesOnBranch; }
public bool ContainsClassOrMember(NodeSearchElement member) { var memberViewModel = new NodeSearchElementViewModel(member, null); // TODO(Vladimir): classes functionality. //if (Classes.Any(cl => cl.Equals(member))) return true; // Search among member groups. return MemberGroups.Any(group => group.ContainsMember(memberViewModel)); }
internal void UpdateEntry(NodeSearchElement entry) { var rootNode = libraryRoot; foreach (var categoryName in entry.Categories) { var tempNode = rootNode.SubCategories.FirstOrDefault(item => item.Name == categoryName); // Root node can be null, if there is classes-viewmodel between updated entry and current category. if (tempNode == null) { // Get classes. var classes = rootNode.SubCategories.FirstOrDefault(); // Search in classes. tempNode = classes.SubCategories.FirstOrDefault(item => item.Name == categoryName); } rootNode = tempNode; } var entryVM = rootNode.Entries.FirstOrDefault(foundEntryVM => foundEntryVM.Name == entry.Name); entryVM.Model = entry; }
/// <summary> /// Initializes a new instance of the <see cref="DragDropNodeSearchElementInfo"/> class. /// </summary> /// <param name="searchElement">Element to drag on the canvas</param> public DragDropNodeSearchElementInfo(NodeSearchElement searchElement) { this.SearchElement = searchElement; }
/// <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> /// 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++; }
private static NodeSearchElementViewModel CreateCustomNodeViewModel(NodeSearchElement element) { return new NodeSearchElementViewModel(element, null); }
/// <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); }