Ejemplo n.º 1
0
        /// <summary>
        /// Creates LoadedTypeItem from given node search element
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        internal T CreateLoadedTypeItem <T>(NodeSearchElement element) where T : LoadedTypeItem, new()
        {
            var item = new T()
            {
                fullyQualifiedName = GetFullyQualifiedName(element),
                contextData        = element.CreationName,
                iconUrl            = new IconUrl(element.IconName, element.Assembly).Url,
                parameters         = element.Parameters,
                itemType           = element.Group.ToString().ToLower(),
                description        = element.Description,
                keywords           = element.SearchKeywords.Any()
                        ? element.SearchKeywords.Where(s => !string.IsNullOrEmpty(s)).Aggregate((x, y) => string.Format("{0}, {1}", x, y))
                        : string.Empty
            };

            //If this element is not a custom node then we are done. The icon url for custom node is different
            if (!element.ElementType.HasFlag(ElementTypes.CustomNode))
            {
                return(item);
            }

            var customNode = element as CustomNodeSearchElement;

            if (customNode != null)
            {
                item.iconUrl = new IconUrl(customNode.IconName, customNode.Path, true).Url;
            }

            return(item);
        }
Ejemplo n.º 2
0
        private void PopulateSearchCategories(IEnumerable <NodeSearchElement> nodes)
        {
            foreach (NodeSearchElement node in nodes)
            {
                var rootCategoryName = NodeSearchElement.SplitCategoryName(node.FullCategoryName).FirstOrDefault();

                var category = searchRootCategories.FirstOrDefault(sc => sc.Name == rootCategoryName);
                if (category == null)
                {
                    category = new SearchCategory(rootCategoryName);
                    searchRootCategories.Add(category);
                }

                var elementVM = MakeNodeSearchElementVM(node);
                elementVM.Category = GetCategoryViewModel(libraryRoot, node.Categories);

                category.AddMemberToGroup(elementVM);
            }

            // Update top result before we do not sort categories.
            if (searchRootCategories.Any())
            {
                UpdateTopResult(searchRootCategories.FirstOrDefault().MemberGroups.FirstOrDefault());
            }
            else
            {
                UpdateTopResult(null);
            }

            SortSearchCategoriesChildren();
        }
Ejemplo n.º 3
0
        private void RemoveEntry(NodeSearchElement entry)
        {
            var treeStack = new Stack <NodeCategoryViewModel>();
            var nameStack = new Stack <string>(entry.Categories);
            var target    = libraryRoot;

            while (nameStack.Any())
            {
                var next       = nameStack.Pop();
                var categories = target.SubCategories;
                var newTarget  = categories.FirstOrDefault(c => c.Name == next);
                if (newTarget == default(NodeCategoryViewModel))
                {
                    return;
                }
                treeStack.Push(target);
                target = newTarget;
            }
            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);
                target = parent;
            }
        }
Ejemplo n.º 4
0
        public void CanSplitCategoryNameWithValidInput()
        {
            var split = NodeSearchElement.SplitCategoryName("this is a root category").ToList();

            Assert.AreEqual(1, split.Count);
            Assert.AreEqual("this is a root category", split[0]);

            split = NodeSearchElement.SplitCategoryName("this is a root category.and").ToList();
            Assert.AreEqual(2, split.Count);
            Assert.AreEqual("this is a root category", split[0]);
            Assert.AreEqual("and", split[1]);

            split = NodeSearchElement.SplitCategoryName("this is a root category.and.this is a sub").ToList();
            Assert.AreEqual(3, split.Count);
            Assert.AreEqual("this is a root category", split[0]);
            Assert.AreEqual("and", split[1]);
            Assert.AreEqual("this is a sub", split[2]);

            split = NodeSearchElement.SplitCategoryName("this is a root category.and.this is a sub. with noodles").ToList();
            Assert.AreEqual(4, split.Count);
            Assert.AreEqual("this is a root category", split[0]);
            Assert.AreEqual("and", split[1]);
            Assert.AreEqual("this is a sub", split[2]);
            Assert.AreEqual(" with noodles", split[3]);

            split = NodeSearchElement.SplitCategoryName("this is a root category.").ToList();
            Assert.AreEqual(1, split.Count);
            Assert.AreEqual("this is a root category", split[0]);
        }
Ejemplo n.º 5
0
        private void SearchBox_OnKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                NodeSearchElement simpleNode = ResultsList.Items[0] as NodeSearchElement;
                if (simpleNode == null)
                {
                    return;
                }

                try
                {
                    var dynMethod = simpleNode.GetType().GetMethod("ConstructNewNodeModel",
                                                                   BindingFlags.NonPublic | BindingFlags.Instance);
                    var obj = dynMethod.Invoke(simpleNode, new object[] { });
                    var nM  = obj as NodeModel;

                    MonocleViewExtension.dynView.ExecuteCommand(new DynamoModel.CreateNodeCommand(nM, 0, 0, true, false));
                }
                catch (Exception)
                {
                    //do nothing
                }
            }
        }
        public void CustomNodePropertiesWindowValidateCategories()
        {
            // sample CN #1
            var CN1_Info = new CustomNodeInfo(
                Guid.NewGuid(),
                "category test node 1",
                "base.level1.level2.level3",
                "A node for testing CN dialog categories drop - down",
                @"C:\temp\category_test_node_1.dyf");

            // sample CN #2
            var CN2_Info = new CustomNodeInfo(
                Guid.NewGuid(),
                "category test node 2",
                "base.level1.level2.level3.level4.level5",
                "A node for testing CN dialog categories drop - down",
                @"C:\temp\category_test_node_2.dyf");

            var CN1_Mock = new Mock <ICustomNodeSource>();
            var CN2_Mock = new Mock <ICustomNodeSource>();

            var CN1_element = new CustomNodeSearchElement(CN1_Mock.Object, CN1_Info);
            var CN2_element = new CustomNodeSearchElement(CN2_Mock.Object, CN2_Info);

            var provider       = new NodeItemDataProvider(new NodeSearchModel());
            var CN1_LoadedType = provider.CreateLoadedTypeItem <LoadedTypeItem>(CN1_element);
            var CN2_LoadedType = provider.CreateLoadedTypeItem <LoadedTypeItem>(CN2_element);

            var elements = new NodeSearchElement[] { CN1_element, CN2_element };

            // Call function used to populate Add-ons categories drop-down in CN properties window
            List <string> addOnCategories = Dynamo.Controls.DynamoView.getUniqueAddOnCategories(elements).ToList();

            // Expected results
            var CN1_expectedQualifiedName = "dyf://base.level1.level2.level3.category test node 1";
            var CN2_expectedQualifiedName = "dyf://base.level1.level2.level3.level4.level5.category test node 2";

            // Expected unique categories that will be populated for the drop-down in the function above
            string[] expectedCategories = new string[]
            {
                "base",
                "base.level1",
                "base.level1.level2",
                "base.level1.level2.level3",
                "base.level1.level2.level3.level4",
                "base.level1.level2.level3.level4.level5"
                // Should not include node names at bottom levels
            };

            // Verify expected results
            Assert.AreEqual(CN1_expectedQualifiedName, CN1_LoadedType.fullyQualifiedName);
            Assert.AreEqual(CN2_expectedQualifiedName, CN2_LoadedType.fullyQualifiedName);
            Assert.AreEqual(addOnCategories.Count, expectedCategories.Length);

            for (int i = 0; i < addOnCategories.Count; i++)
            {
                Assert.AreEqual(addOnCategories[i], expectedCategories[i]);
            }
        }
Ejemplo n.º 7
0
        private static NodeSearchElementViewModel MakeNodeSearchElementVM(NodeSearchElement entry)
        {
            var element = entry as CustomNodeSearchElement;

            return(element != null
                ? new CustomNodeSearchElementViewModel(element)
                : new NodeSearchElementViewModel(entry));
        }
Ejemplo n.º 8
0
 private void LibraryItem_OnMouseLeave(object sender, MouseEventArgs e)
 {
     TreeViewItem treeViewItem = sender as TreeViewItem;
     NodeSearchElement nodeSearchElement = treeViewItem.Header as NodeSearchElement;
     if (nodeSearchElement == null)
         return;
     DynamoCommands.HideLibItemInfoBubbleCommand.Execute(null);
 }
Ejemplo n.º 9
0
        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)));
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        public NodeSearchElementViewModel(NodeSearchElement element, SearchViewModel svm)
        {
            Model           = element;
            searchViewModel = svm;

            Model.PropertyChanged += ModelOnPropertyChanged;
            if (searchViewModel != null)
            {
                Clicked += searchViewModel.OnSearchElementClicked;
            }
            ClickedCommand = new DelegateCommand(OnClicked);
        }
Ejemplo n.º 12
0
        public NodeSearchElementViewModel(NodeSearchElement element, SearchViewModel svm)
        {
            Model           = element;
            searchViewModel = svm;

            Model.VisibilityChanged += ModelOnVisibilityChanged;
            if (searchViewModel != null)
            {
                Clicked += searchViewModel.OnSearchElementClicked;
            }
            ClickedCommand = new DelegateCommand(OnClicked);

            LoadFonts();
        }
Ejemplo n.º 13
0
 /// Gets fully qualified name for the given node search element
 /// </summary>
 public static string GetFullyQualifiedName(NodeSearchElement element)
 {
     //If the node search element is part of a package, then we need to prefix pkg:// for it
     if (element.ElementType.HasFlag(ElementTypes.Packaged))
     {
         //Use FullCategory and name as read from _customization.xml file
         return(string.Format("{0}{1}.{2}", "pkg://", element.FullCategoryName, element.Name));
     }
     else if (element.ElementType.HasFlag(ElementTypes.CustomNode))
     {
         //Use FullCategory and name as read from _customization.xml file
         return(string.Format("{0}{1}", "dyf://", element.FullName));
     }
     return(element.FullName);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// 获取正在搜索的元素的全名(用于模糊搜索)
 /// </summary>
 public static string GetFullyQualifiedName(NodeSearchElement element)
 {
     //如果正在搜索的是包名(),则在前面加上pkg://前缀
     if (element.ElementType.HasFlag(ElementTypes.Packaged))
     {
         //Use FullCategory and name as read from _customization.xml file
         return(string.Format("{0}{1}.{2}", "pkg://", element.FullCategoryName, element.Name));
     }
     //如果是一个自定义节点的名字
     else if (element.ElementType.HasFlag(ElementTypes.CustomNode))
     {
         //Use FullCategory and name as read from _customization.xml file
         return(string.Format("{0}{1}", "dyf://", element.FullName));
     }
     return(element.FullName);
 }
Ejemplo n.º 15
0
        private void LibraryItem_OnMouseEnter(object sender, MouseEventArgs e)
        {
            TreeViewItem treeViewItem = sender as TreeViewItem;
            NodeSearchElement nodeSearchElement = treeViewItem.Header as NodeSearchElement;
            if (nodeSearchElement == null)
                return;

            Point pointToScreen_TopLeft = treeViewItem.PointToScreen(new Point(0, 0));
            Point topLeft = this.PointFromScreen(pointToScreen_TopLeft);
            Point pointToScreen_BotRight = new Point(pointToScreen_TopLeft.X + treeViewItem.ActualWidth, pointToScreen_TopLeft.Y + treeViewItem.ActualHeight);
            Point botRight = this.PointFromScreen(pointToScreen_BotRight);
            string infoBubbleContent = nodeSearchElement.Description;
            InfoBubbleDataPacket data = new InfoBubbleDataPacket(InfoBubbleViewModel.Style.LibraryItemPreview, topLeft,
                botRight, infoBubbleContent, InfoBubbleViewModel.Direction.Left);
            DynamoCommands.ShowLibItemInfoBubbleCommand.Execute(data);
        }
Ejemplo n.º 16
0
        public NodeSearchElementViewModel(NodeSearchElement element, SearchViewModel svm)
        {
            Model           = element;
            searchViewModel = svm;

            Model.VisibilityChanged += ModelOnVisibilityChanged;
            if (searchViewModel != null)
            {
                Clicked += searchViewModel.OnSearchElementClicked;
                CreateAndConnectToPort += searchViewModel.OnRequestConnectToPort;
            }
            ClickedCommand          = new DelegateCommand(OnClicked);
            CreateAndConnectCommand = new DelegateCommand <PortModel>(OnRequestCreateAndConnectToPort);

            LoadFonts();
        }
Ejemplo n.º 17
0
        private void ExecuteElement(NodeSearchElement element)
        {
            // create node
            var guid = Guid.NewGuid();

            dynamoViewModel.ExecuteCommand(
                new DynamoModel.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);
            }
        }
Ejemplo n.º 18
0
        public void CanSplitCategoryNameWithInvalidInput()
        {
            var split = NodeSearchElement.SplitCategoryName("").ToList();

            Assert.AreEqual(0, split.Count);

            split = NodeSearchElement.SplitCategoryName("this is a root category.").ToList();
            Assert.AreEqual(1, split.Count);
            Assert.AreEqual("this is a root category", split[0]);

            split = NodeSearchElement.SplitCategoryName(".this is a root category.").ToList();
            Assert.AreEqual(1, split.Count);
            Assert.AreEqual("this is a root category", split[0]);

            split = NodeSearchElement.SplitCategoryName("...").ToList();
            Assert.AreEqual(0, split.Count);
        }
Ejemplo n.º 19
0
        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;
        }
Ejemplo n.º 20
0
        /// <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++;
        }
Ejemplo n.º 21
0
        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);
        }
Ejemplo n.º 22
0
        private void PopulateSearchCategories(IEnumerable <NodeSearchElement> nodes)
        {
            foreach (NodeSearchElement node in nodes)
            {
                var rootCategoryName = NodeSearchElement.SplitCategoryName(node.FullCategoryName).FirstOrDefault();

                var category = searchRootCategories.FirstOrDefault(sc => sc.Name == rootCategoryName);
                if (category == null)
                {
                    category = new SearchCategory(rootCategoryName);
                    searchRootCategories.Add(category);
                }

                var elementVM = MakeNodeSearchElementVM(node);
                elementVM.Category = GetCategoryViewModel(libraryRoot, node.Categories);

                category.AddMemberToGroup(elementVM);
            }

            if (nodes.Count() == 0)
            {
                return;
            }

            // Clone top node.
            var topNode = new NodeSearchElementViewModel(MakeNodeSearchElementVM(nodes.First()));

            topNode.IsTopResult = true;

            SortSearchCategoriesChildren();

            var topCategory = new SearchCategory(Dynamo.Wpf.Properties.Resources.SearchViewTopResult, true);

            topCategory.AddMemberToGroup(topNode);
            searchRootCategories.Insert(0, topCategory);

            selectionNavigator.UpdateRootCategories(SearchRootCategories);
        }
        /// <summary>
        /// This builds the string to search by based on the user selections
        /// </summary>
        private static string SetSearchName(NodeSearchElement nsm)
        {
            string returnString = (nsm.Name).SimplifyString();

            switch (_searchCriteriaFlag)
            {
            case 1:
                returnString = (nsm.Name).SimplifyString();
                break;

            case 2:
                returnString = nsm.Description.SimplifyString();
                break;

            case 3:
                returnString = (nsm.Name + nsm.Description).SimplifyString();
                break;

            case 4:
                returnString = (nsm.FullName).SimplifyString();
                break;

            case 5:
                returnString = (nsm.Name + nsm.FullName).SimplifyString();
                break;

            case 6:
                returnString = (nsm.FullName + nsm.Description).SimplifyString();
                break;

            case 7:
                returnString = (nsm.Name + nsm.FullName + nsm.Description).SimplifyString();
                break;
            }

            return(returnString);
        }
Ejemplo n.º 24
0
        private void PopulateSearchCategories(IEnumerable <NodeSearchElement> nodes)
        {
            foreach (NodeSearchElement node in nodes)
            {
                var rootCategoryName = NodeSearchElement.SplitCategoryName(node.FullCategoryName).FirstOrDefault();

                var category = searchRootCategories.FirstOrDefault(sc => sc.Name == rootCategoryName);
                if (category == null)
                {
                    category = new SearchCategory(rootCategoryName);
                    searchRootCategories.Add(category);
                }

                var elementVM = MakeNodeSearchElementVM(node);
                elementVM.Category = GetCategoryViewModel(libraryRoot, node.Categories);

                category.AddMemberToGroup(elementVM);
            }

            // Order found categories by name.
            searchRootCategories = new ObservableCollection <SearchCategory>(searchRootCategories.OrderBy(x => x.Name));

            SortSearchCategoriesChildren();
        }
Ejemplo n.º 25
0
 private static NodeSearchElementViewModel CreateCustomNodeViewModel(NodeSearchElement element)
 {
     return(new NodeSearchElementViewModel(element, null));
 }
Ejemplo n.º 26
0
        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);
                }
            }
        }
Ejemplo n.º 27
0
        /// <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);
        }
Ejemplo n.º 28
0
        /// <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>
        /// Returns true if the user input matches the name of the filtered node element.
        /// </summary>
        /// <returns>True or false</returns>
        private bool QuerySearchElements(NodeSearchElement e, string input)
        {
            StringComparison stringComparison = StringComparison.CurrentCultureIgnoreCase;

            return(e.Name.IndexOf(input, stringComparison) >= 0);
        }
Ejemplo n.º 30
0
 public NodeSearchElementViewModel(NodeSearchElement element)
 {
     Model = element;
     Model.PropertyChanged += ModelOnPropertyChanged;
     ClickedCommand         = new DelegateCommand(Model.ProduceNode);
 }