void CreateFieldItems(SearcherItem root, Type type, int depth)
        {
            var operators = GetOperatorsFromType(type);

            foreach (var op in operators)
            {
                root.AddChild(op);
            }

            depth--;
            if (depth <= 0)
            {
                return;
            }

            var infos = GetMemberInfos(type);

            foreach (var info in infos)
            {
                var itemType = info.MemberType == MemberTypes.Field
                    ? (info as FieldInfo)?.FieldType
                    : (info as PropertyInfo)?.PropertyType;
                var item = new TypeSearcherItem(itemType.GenerateTypeHandle(m_Stencil), info.Name);

                CreateFieldItems(item, itemType, depth);

                // We only display item with binary operators
                if (item.HasChildren)
                {
                    root.AddChild(item);
                }
            }
        }
        public bool OnSearcherSelectEntry(SearcherItem entry, Vector2 screenMousePosition)
        {
            if (entry == null || (entry as SearchNodeItem).NodeGUID.node == null)
            {
                return(false);
            }

            var nodeEntry = (entry as SearchNodeItem).NodeGUID;
            var node      = CopyNodeForGraph(nodeEntry.node);

            var windowRoot          = m_EditorWindow.rootVisualElement;
            var windowMousePosition = windowRoot.ChangeCoordinatesTo(windowRoot.parent, screenMousePosition); //- m_EditorWindow.position.position);
            var graphMousePosition  = m_GraphView.contentViewContainer.WorldToLocal(windowMousePosition);

            m_Graph.owner.RegisterCompleteObjectUndo("Add " + node.name);

            if (node is BlockNode blockNode)
            {
                if (!(target is ContextView contextView))
                {
                    return(false);
                }

                // Test against all current BlockNodes in the Context
                // Never allow duplicate BlockNodes
                if (contextView.contextData.blocks.Where(x => x.value.name == blockNode.name).FirstOrDefault().value != null)
                {
                    return(false);
                }

                // Insert block to Data
                blockNode.owner = m_Graph;
                int index = contextView.GetInsertionIndex(screenMousePosition);
                m_Graph.AddBlock(blockNode, contextView.contextData, index);
                return(true);
            }

            var drawState = node.drawState;

            drawState.position = new Rect(graphMousePosition, Vector2.zero);
            node.drawState     = drawState;
            m_Graph.AddNode(node);

            if (connectedPort != null)
            {
                var connectedSlot           = connectedPort.slot;
                var connectedSlotReference  = connectedSlot.owner.GetSlotReference(connectedSlot.id);
                var compatibleSlotReference = node.GetSlotReference(nodeEntry.compatibleSlotId);

                var fromReference = connectedSlot.isOutputSlot ? connectedSlotReference : compatibleSlotReference;
                var toReference   = connectedSlot.isOutputSlot ? compatibleSlotReference : connectedSlotReference;
                m_Graph.Connect(fromReference, toReference);

                nodeNeedsRepositioning = true;
                targetSlotReference    = compatibleSlotReference;
                targetPosition         = graphMousePosition;
            }

            return(true);
        }
Beispiel #3
0
 protected override IEnumerable <IGraphElementModel> CreateGraphElements(SearcherItem item)
 {
     return(item is GraphNodeModelSearcherItem graphItem
         ? graphItem.CreateElements.Invoke(
                new GraphNodeCreationData(m_GraphModel, Vector2.zero, SpawnFlags.Orphan))
         : Enumerable.Empty <IGraphElementModel>());
 }
Beispiel #4
0
        static bool OnItemSelected(SearcherItem item, Action <TypeHandle, TypeMember, BinaryOperatorKind> callback)
        {
            if (!(item is CriterionSearcherItem criterionItem))
            {
                return(false);
            }

            var componentType = TypeHandle.Unknown;
            var path          = new Stack <string>();
            var parent        = item.Parent;
            var memberType    = parent is TypeSearcherItem tsi ? tsi.Type : TypeHandle.Unknown;

            while (parent != null)
            {
                if (parent.Parent == null && parent is TypeSearcherItem typeItem)
                {
                    componentType = typeItem.Type;
                }
                else
                {
                    path.Push(parent.Name);
                }

                parent = parent.Parent;
            }

            var op = criterionItem.Operator;

            callback(componentType, new TypeMember(memberType, path.ToList()), op);
            return(true);
        }
Beispiel #5
0
        public GraphElementSearcherDatabase AddFunctionMembers(IFunctionModel functionModel)
        {
            if (functionModel == null)
            {
                return(this);
            }

            SearcherItem parent = null;
            IEnumerable <IVariableDeclarationModel> members = functionModel.FunctionParameterModels.Union(
                functionModel.FunctionVariableModels);

            foreach (IVariableDeclarationModel declarationModel in members)
            {
                if (parent == null)
                {
                    parent = SearcherItemUtility.GetItemFromPath(Items, k_FunctionMembers);
                }

                parent.AddChild(new GraphNodeModelSearcherItem(
                                    new TypeSearcherItemData(declarationModel.DataType, SearcherItemTarget.Variable),
                                    data => data.CreateVariableNode(declarationModel),
                                    declarationModel.Name.Nicify()
                                    ));
            }

            return(this);
        }
        protected override void OnGraphElementsCreated(SearcherItem searcherItem,
                                                       IEnumerable <IGraphElementModel> elements)
        {
            if (m_DetailsPanel == null)
            {
                return;
            }

            if (m_Description == null)
            {
                m_Description = new VisualElement {
                    name = "nodeDescription"
                };
                m_Scrollview.Add(m_Description);
            }

            var elementList = elements.ToList();

            if (!elementList.Any() || !(elementList.First() is IDotsNodeModel baseDotsNodeModel))
            {
                return;
            }

            m_Description.Clear();
            NodeDocumentationFormatter formatter = new SearcherNodeDocumentationFormatter(m_Description);

            formatter.DocumentNode(searcherItem, baseDotsNodeModel);
        }
Beispiel #7
0
        public GraphElementSearcherDatabase AddGraphAssetMembers(IGraphModel graph)
        {
            SearcherItem parent         = null;
            TypeHandle   voidTypeHandle = Stencil.GenerateTypeHandle(typeof(void));

            foreach (var functionModel in graph.NodeModels.OfType <FunctionModel>())
            {
                if (parent == null)
                {
                    parent = SearcherItemUtility.GetItemFromPath(Items, graph.Name);
                }

                if (functionModel.ReturnType == voidTypeHandle)
                {
                    parent.AddChild(new StackNodeModelSearcherItem(
                                        new GraphAssetSearcherItemData(graph.AssetModel),
                                        data => data.CreateFunctionRefCallNode(functionModel),
                                        functionModel.Title
                                        ));
                    continue;
                }

                parent.AddChild(new GraphNodeModelSearcherItem(
                                    new GraphAssetSearcherItemData(graph.AssetModel),
                                    data => data.CreateFunctionRefCallNode(functionModel),
                                    functionModel.Title
                                    ));
            }

            return(this);
        }
Beispiel #8
0
        public GraphElementSearcherDatabase AddGraphVariables(IGraphModel graphModel)
        {
            SearcherItem parent       = null;
            var          vsGraphModel = (VSGraphModel)graphModel;

            foreach (IVariableDeclarationModel declarationModel in vsGraphModel.GraphVariableModels)
            {
                if (parent == null)
                {
                    parent = SearcherItemUtility.GetItemFromPath(Items, k_GraphVariables);
                }

                parent.AddChild(new GraphNodeModelSearcherItem(
                                    new TypeSearcherItemData(declarationModel.DataType, SearcherItemTarget.Variable),
                                    data => ((VSGraphModel)data.GraphModel).CreateVariableNode(
                                        declarationModel,
                                        data.Position,
                                        data.SpawnFlags
                                        ),
                                    declarationModel.Name.Nicify()
                                    ));
            }

            return(this);
        }
Beispiel #9
0
        public GraphElementSearcherDatabase AddConstructors(Type type, BindingFlags bindingFlags)
        {
            SearcherItem parent = null;

            foreach (ConstructorInfo constructorInfo in type.GetConstructors(bindingFlags))
            {
                if (parent == null)
                {
                    parent = SearcherItemUtility.GetItemFromPath(Items, type.FriendlyName(false));
                }

                MethodDetails details = constructorInfo.GetMethodDetails();
                parent.AddChild(new GraphNodeModelSearcherItem(
                                    new ConstructorSearcherItemData(constructorInfo),
                                    data => ((VSGraphModel)data.GraphModel).CreateFunctionCallNode(
                                        constructorInfo,
                                        data.Position,
                                        data.SpawnFlags
                                        ),
                                    details.MethodName,
                                    details.Details
                                    ));
            }

            return(this);
        }
Beispiel #10
0
        public GraphElementSearcherDatabase AddUnaryOperators()
        {
            SearcherItem parent = SearcherItemUtility.GetItemFromPath(Items, k_Operator);

            foreach (UnaryOperatorKind kind in Enum.GetValues(typeof(UnaryOperatorKind)))
            {
                if (kind == UnaryOperatorKind.PostDecrement || kind == UnaryOperatorKind.PostIncrement)
                {
                    parent.AddChild(new StackNodeModelSearcherItem(
                                        new UnaryOperatorSearcherItemData(kind),
                                        data => data.CreateUnaryStatementNode(kind),
                                        kind.ToString()
                                        ));
                    continue;
                }

                parent.AddChild(new GraphNodeModelSearcherItem(
                                    new UnaryOperatorSearcherItemData(kind),
                                    data => data.CreateUnaryStatementNode(kind),
                                    kind.ToString()
                                    ));
            }

            return(this);
        }
Beispiel #11
0
        public void TestFind_Null()
        {
            var parent = new SearcherItem("parent");
            var child  = parent.Find("child");

            Assert.IsNull(child);
        }
        public Searcher.Searcher LoadSearchWindow()
        {
            GenerateNodeEntries();

            //create empty root for searcher tree
            var root       = new List <SearcherItem>();
            var dummyEntry = new NodeEntry();

            foreach (var nodeEntry in currentNodeEntries)
            {
                SearcherItem item   = null;
                SearcherItem parent = null;
                for (int i = 0; i < nodeEntry.title.Length; i++)
                {
                    var pathEntry = nodeEntry.title[i];
                    List <SearcherItem> children = parent != null ? parent.Children : root;
                    item = children.Find(x => x.Name == pathEntry);

                    if (item == null)
                    {
                        //if we have slot entries and are at a leaf, add the slot name to the entry title
                        if (nodeEntry.compatibleSlotId != -1 && i == nodeEntry.title.Length - 1)
                        {
                            item = new SearchNodeItem(pathEntry + ": " + nodeEntry.slotName, nodeEntry);
                        }
                        //if we don't have slot entries and are at a leaf, add userdata to the entry
                        else if (nodeEntry.compatibleSlotId == -1 && i == nodeEntry.title.Length - 1)
                        {
                            item = new SearchNodeItem(pathEntry, nodeEntry);
                        }
                        //if we aren't a leaf, don't add user data
                        else
                        {
                            item = new SearchNodeItem(pathEntry, dummyEntry);
                        }

                        if (parent != null)
                        {
                            parent.AddChild(item);
                        }
                        else
                        {
                            children.Add(item);
                        }
                    }

                    parent = item;

                    if (parent.Depth == 0 && !root.Contains(parent))
                    {
                        root.Add(parent);
                    }
                }
            }

            var nodeDatabase = SearcherDatabase.Create(root, string.Empty, false);

            return(new Searcher.Searcher(nodeDatabase, new SearchWindowAdapter("Create Node")));
        }
Beispiel #13
0
 private string MakePath(SearcherItem searcherItem, char separator)
 {
     if (searcherItem.Parent == null)
     {
         return(searcherItem.Name);
     }
     return(MakePath(searcherItem.Parent, separator) + separator + searcherItem.Name);
 }
Beispiel #14
0
        internal static SearcherDatabase Populate <T>(Func <Type, bool> filter = null, Func <Type, string> nameResolver = null, Func <Type, string> categoryResolver = null)
        {
            var list = new List <SearcherItem>();
            var dict = new Dictionary <string, SearcherItem>();

            var types = TypeCache.GetTypesDerivedFrom <T>();

            foreach (var type in types)
            {
                if (type.IsGenericType || type.IsAbstract || type.ContainsGenericParameters || type.IsInterface)
                {
                    continue;
                }

                if (!TypeConstruction.CanBeConstructed(type))
                {
                    continue;
                }

                if (filter != null && !filter(type))
                {
                    continue;
                }

                try
                {
                    var typeItem = new TypeSearcherItem(type, nameResolver != null ? nameResolver(type) : string.Empty);
                    var category = categoryResolver != null?categoryResolver(type) : type.Namespace ?? "Global";

                    if (!string.IsNullOrEmpty(category))
                    {
                        if (!dict.TryGetValue(category, out var item))
                        {
                            dict[category] = item = new SearcherItem(category);
                            list.Add(item);
                        }
                        item.AddChild(typeItem);
                    }
                    else
                    {
                        list.Add(typeItem);
                    }
                }
                catch (Exception)
                {
                    // ignored
                }
            }

            foreach (var kvp in dict)
            {
                kvp.Value.Children.Sort(CompareByName);
            }

            list.Sort(CompareByName);

            return(new SearcherDatabase(list));
        }
Beispiel #15
0
 bool OnTypeSelected(SearcherItem item)
 {
     if (item is TypeSearcherItem typeItem && TypeConstruction.TryConstruct <T>(typeItem.Type, out var instance))
     {
         Target = instance;
         return(true);
     }
     return(false);
 }
Beispiel #16
0
        public GraphElementSearcherDatabase AddMethods(
            Type type,
            BindingFlags bindingFlags,
            Dictionary <string, List <Type> > blackList = null
            )
        {
            SearcherItem parent = null;

            foreach (MethodInfo methodInfo in type.GetMethods(bindingFlags)
                     .Where(m => !m.IsSpecialName &&
                            m.GetCustomAttribute <ObsoleteAttribute>() == null &&
                            m.GetCustomAttribute <HiddenAttribute>() == null &&
                            !m.Name.StartsWith("get_", StringComparison.Ordinal) &&
                            !m.Name.StartsWith("set_", StringComparison.Ordinal) &&
                            !m.GetParameters().Any(p => p.ParameterType.IsByRef || p.IsOut || p.ParameterType.IsPointer) &&
                            !SearcherItemCollectionUtility.IsMethodBlackListed(m, blackList))
                     .OrderBy(m => m.Name))
            {
                if (parent == null)
                {
                    parent = SearcherItemUtility.GetItemFromPath(Items, type.FriendlyName(false));
                }

                MethodDetails details = methodInfo.GetMethodDetails();

                if (methodInfo.ReturnType == typeof(void))
                {
                    parent.AddChild(new StackNodeModelSearcherItem(
                                        new MethodSearcherItemData(methodInfo),
                                        data => ((StackBaseModel)data.StackModel).CreateFunctionCallNode(
                                            methodInfo,
                                            data.Index,
                                            data.SpawnFlags
                                            ),
                                        details.MethodName,
                                        details.Details
                                        ));
                    continue;
                }

                if (!methodInfo.ReturnType.IsPointer)
                {
                    parent.AddChild(new GraphNodeModelSearcherItem(
                                        new MethodSearcherItemData(methodInfo),
                                        data => ((VSGraphModel)data.GraphModel).CreateFunctionCallNode(
                                            methodInfo,
                                            data.Position,
                                            data.SpawnFlags
                                            ),
                                        details.MethodName,
                                        details.Details
                                        ));
                }
            }

            return(this);
        }
Beispiel #17
0
        public GraphElementSearcherDatabase AddControlFlows()
        {
            AddIfCondition(IfConditionMode.Basic);
            AddIfCondition(IfConditionMode.Advanced);
            AddIfCondition(IfConditionMode.Complete);

            SearcherItem parent    = null;
            var          loopTypes = TypeCache.GetTypesDerivedFrom <LoopStackModel>();

            foreach (var loopType in loopTypes.Where(t => !t.IsAbstract))
            {
                if (parent == null)
                {
                    parent = SearcherItemUtility.GetItemFromPath(Items, k_ControlFlow);
                }

                var name = $"{VseUtility.GetTitle(loopType)}{k_LoopStack}";
                parent.AddChild(new StackNodeModelSearcherItem(
                                    new ControlFlowSearcherItemData(loopType),
                                    data =>
                {
                    var stackModel = (StackBaseModel)data.StackModel;
                    var elements   = new List <IGraphElementModel>();

                    var graphModel    = (VSGraphModel)stackModel.GraphModel;
                    var stackPosition = new Vector2(
                        stackModel.Position.x + k_StackOffset.x,
                        stackModel.Position.y + k_StackOffset.y
                        );

                    LoopStackModel loopStack = graphModel.CreateLoopStack(
                        loopType,
                        stackPosition,
                        data.SpawnFlags
                        );

                    var node = loopStack.CreateLoopNode(
                        stackModel,
                        data.Index,
                        data.SpawnFlags);

                    elements.Add(node);
                    elements.Add(loopStack);

                    var edge = data.SpawnFlags.IsOrphan()
                            ? graphModel.CreateOrphanEdge(loopStack.InputPort, node.OutputPort)
                            : graphModel.CreateEdge(loopStack.InputPort, node.OutputPort);
                    elements.Add(edge);

                    return(elements.ToArray());
                },
                                    name
                                    ));
            }

            return(this);
        }
Beispiel #18
0
        public ScriptView(ScriptsConfiguration config, Action drawHackGuiAction, Action saveAssetAction)
        {
            ScriptModified = false;

            this.config          = config;
            this.saveAssetAction = saveAssetAction;
            editorResources      = EditorResources.LoadOrDefault();
            ViewRange            = new IntRange(0, config.EditorPageLength - 1);

            styleSheets.Add(StyleSheet);
            if (EditorGUIUtility.isProSkin)
            {
                styleSheets.Add(DarkStyleSheet);
            }
            CustomStyleSheet = config.EditorCustomStyleSheet;
            if (CustomStyleSheet)
            {
                styleSheets.Add(CustomStyleSheet);
            }

            var commentItem     = new SearcherItem("Comment");
            var labelItem       = new SearcherItem("Label");
            var genericTextItem = new SearcherItem("Generic Text", config.InsertLineKey != KeyCode.None
                ? $"{(config.InsertLineModifier != EventModifiers.None ? $"{config.InsertLineModifier}+" : string.Empty)}{config.InsertLineKey}"
                : null);
            var commandsItem = new SearcherItem("Commands");

            foreach (var commandId in Command.CommandTypes.Keys.OrderBy(k => k))
            {
                commandsItem.AddChild(new SearcherItem(char.ToLowerInvariant(commandId[0]) + commandId.Substring(1)));
            }
            searchItems = new List <SearcherItem> {
                commandsItem, genericTextItem, labelItem, commentItem
            };

            Add(new IMGUIContainer(drawHackGuiAction));
            Add(new IMGUIContainer(() => HandleKeyDownEvent(null)));

            linesContainer = new VisualElement();
            Add(linesContainer);

            paginationView = new PaginationView(SelectNextPage, SelectPreviousPage);
            paginationView.style.display = DisplayStyle.None;
            Add(paginationView);

            infoLabel      = new Label("Loading, please wait...");
            infoLabel.name = "InfoLabel";
            ColorUtility.TryParseHtmlString(EditorGUIUtility.isProSkin ? "#cccccc" : "#555555", out var color);
            infoLabel.style.color = color;
            Add(infoLabel);

            RegisterCallback <KeyDownEvent>(HandleKeyDownEvent, TrickleDown.TrickleDown);
            RegisterCallback <MouseDownEvent>(HandleMouseDownEvent, TrickleDown.TrickleDown);

            new ContextualMenuManipulator(ContextMenu).target = this;
        }
        public static void AddToSearcherDatabase(IGraphModel graphModel, GraphElementSearcherDatabase db)
        {
            SearcherItem parent = db.Items.GetItemFromPath("Fake");

            parent.AddChild(new GraphNodeModelSearcherItem(graphModel,
                                                           new NodeSearcherItemData(typeof(Type3FakeNodeModel)),
                                                           data => data.CreateNode <Type3FakeNodeModel>(),
                                                           nameof(Type3FakeNodeModel)
                                                           ));
        }
Beispiel #20
0
        public void TestFind_NotNull()
        {
            var parent = new SearcherItem("parent");

            parent.AddChild(new SearcherItem("child"));

            var child = parent.Find("child");

            Assert.NotNull(child);
            Assert.AreEqual(child.Name, "child");
        }
        bool AddStep(SearcherItem item)
        {
            if (item is TypeSearcherItem typeItem)
            {
                m_BuildSteps.Add(BuildPipeline.CreateStepFromType(typeItem.Type));
                MarkDirty();
                return(true);
            }

            return(false);
        }
        public GraphElementSearcherDatabase AddGraphsMethods()
        {
            string[] assetGUIDs = AssetDatabase.FindAssets($"t:{typeof(VSGraphAssetModel).Name}");
            List <Tuple <IGraphModel, FunctionModel> > methods = assetGUIDs.SelectMany(assetGuid =>
            {
                string assetPath = AssetDatabase.GUIDToAssetPath(assetGuid);
                VSGraphAssetModel graphAssetModel = AssetDatabase.LoadAssetAtPath <VSGraphAssetModel>(assetPath);

                if (!graphAssetModel || graphAssetModel.GraphModel == null)
                {
                    return(Enumerable.Empty <Tuple <IGraphModel, FunctionModel> >());
                }

                var functionModels = graphAssetModel.GraphModel.NodeModels.OfExactType <FunctionModel>()
                                     .Select(fm => new Tuple <IGraphModel, FunctionModel>(fm.GraphModel, fm));

                return(functionModels.Concat(graphAssetModel.GraphModel.NodeModels.OfExactType <EventFunctionModel>()
                                             .Select(fm => new Tuple <IGraphModel, FunctionModel>(fm.GraphModel, fm))));
            }).ToList();

            if (methods.Count == 0)
            {
                return(this);
            }

            TypeHandle voidTypeHandle = typeof(void).GenerateTypeHandle(Stencil);

            foreach (Tuple <IGraphModel, FunctionModel> method in methods)
            {
                IGraphModel   graphModel    = method.Item1;
                FunctionModel functionModel = method.Item2;
                string        graphName     = graphModel.AssetModel.Name;
                SearcherItem  graphRoot     = SearcherItemUtility.GetItemFromPath(Items, $"{k_Graphs}/{graphName}");

                if (functionModel.ReturnType == voidTypeHandle)
                {
                    graphRoot.AddChild(new StackNodeModelSearcherItem(
                                           new FunctionRefSearcherItemData(graphModel, functionModel),
                                           data => data.CreateFunctionRefCallNode(functionModel),
                                           () => $"{k_Function} {functionModel.Title}"
                                           ));
                    continue;
                }

                graphRoot.AddChild(new GraphNodeModelSearcherItem(
                                       new FunctionRefSearcherItemData(graphModel, functionModel),
                                       data => data.CreateFunctionRefCallNode(functionModel),
                                       () => $"{k_Function} {functionModel.Title}"
                                       ));
            }

            return(this);
        }
Beispiel #23
0
 public static void AddAtPath(this List <SearcherItem> items, SearcherItem item, string path = "")
 {
     if (!string.IsNullOrEmpty(path))
     {
         SearcherItem parent = SearcherItemUtility.GetItemFromPath(items, path);
         parent.AddChild(item);
     }
     else
     {
         items.Add(item);
     }
 }
Beispiel #24
0
        public GraphElementSearcherDatabase AddConstants(Type type)
        {
            TypeHandle handle = type.GenerateTypeHandle(Stencil);

            SearcherItem parent = SearcherItemUtility.GetItemFromPath(Items, k_Constant);

            parent.AddChild(new GraphNodeModelSearcherItem(
                                new TypeSearcherItemData(handle, SearcherItemTarget.Constant),
                                data => data.CreateConstantNode("", handle),
                                $"{type.FriendlyName().Nicify()} {k_Constant}"
                                ));

            return(this);
        }
Beispiel #25
0
        public GraphElementSearcherDatabase AddExtensionMethods(Type type)
        {
            Dictionary <Type, List <MethodInfo> > extensions = TypeSystem.GetExtensionMethods(Stencil.GetAssemblies());

            if (!extensions.TryGetValue(type, out var methodInfos))
            {
                return(this);
            }

            SearcherItem parent = null;

            foreach (MethodInfo methodInfo in methodInfos
                     .Where(m => !m.GetParameters().Any(p => p.ParameterType.IsByRef || p.IsOut)))
            {
                if (parent == null)
                {
                    parent = SearcherItemUtility.GetItemFromPath(Items, type.FriendlyName(false));
                }

                MethodDetails details = methodInfo.GetMethodDetails();

                if (methodInfo.ReturnType != typeof(void))
                {
                    parent.AddChild(new GraphNodeModelSearcherItem(
                                        new MethodSearcherItemData(methodInfo),
                                        data => ((VSGraphModel)data.GraphModel).CreateFunctionCallNode(
                                            methodInfo,
                                            data.Position,
                                            data.SpawnFlags
                                            ),
                                        details.MethodName,
                                        details.Details
                                        ));
                    continue;
                }

                parent.AddChild(new StackNodeModelSearcherItem(
                                    new MethodSearcherItemData(methodInfo),
                                    data => ((StackBaseModel)data.StackModel).CreateFunctionCallNode(
                                        methodInfo,
                                        data.Index,
                                        data.SpawnFlags
                                        ),
                                    details.MethodName,
                                    details.Details
                                    ));
            }

            return(this);
        }
Beispiel #26
0
        public GraphElementSearcherDatabase AddFields(Type type, BindingFlags bindingFlags)
        {
            SearcherItem parent = null;

            foreach (FieldInfo fieldInfo in type.GetFields(bindingFlags)
                     .OrderBy(f => f.Name)
                     .Where(f => f.GetCustomAttribute <ObsoleteAttribute>() == null &&
                            f.GetCustomAttribute <HiddenAttribute>() == null))
            {
                if (parent == null)
                {
                    parent = SearcherItemUtility.GetItemFromPath(Items, type.FriendlyName(false));
                }

                parent.AddChild(new GraphNodeModelSearcherItem(
                                    new FieldSearcherItemData(fieldInfo),
                                    data =>
                {
                    INodeModel nodeModel = ((VSGraphModel)data.GraphModel).CreateGetPropertyGroupNode(
                        data.Position,
                        data.SpawnFlags
                        );
                    ((GetPropertyGroupNodeModel)nodeModel).AddMember(fieldInfo.GetUnderlyingType(), fieldInfo.Name);
                    return(nodeModel);
                },
                                    fieldInfo.Name
                                    ));

                if (fieldInfo.CanWrite())
                {
                    parent.AddChild(new StackNodeModelSearcherItem(
                                        new FieldSearcherItemData(fieldInfo),
                                        data =>
                    {
                        INodeModel nodeModel = ((StackBaseModel)data.StackModel).CreateSetPropertyGroupNode(
                            data.Index
                            );
                        ((SetPropertyGroupNodeModel)nodeModel).AddMember(
                            fieldInfo.GetUnderlyingType(),
                            fieldInfo.Name
                            );
                        return(nodeModel);
                    },
                                        fieldInfo.Name
                                        ));
                }
            }

            return(this);
        }
Beispiel #27
0
        private int ComputeScoreForMatch(string[] queryTerms, SearcherItem matchItem)
        {
            // Scoring Criteria:
            // - Exact name match is most preferred.
            // - Partial name match is next.
            // - Exact synonym match is next.
            // - Partial synonym match is next.
            // - No match is last.
            int score = 0;

            // Split the entry name so that we can remove suffix that looks like "Clamp: In(4)"
            var nameSansSuffix = matchItem.Name.Split(':').First();

            int nameCharactersMatched = 0;

            foreach (var queryWord in queryTerms)
            {
                if (nameSansSuffix.Contains(queryWord, StringComparison.OrdinalIgnoreCase))
                {
                    score += 100000;
                    nameCharactersMatched += queryWord.Length;
                }

                // Check for synonym matches -- give a bonus to each
                if (matchItem.Synonyms != null)
                {
                    foreach (var syn in matchItem.Synonyms)
                    {
                        if (syn.Equals(queryWord, StringComparison.OrdinalIgnoreCase))
                        {
                            score += 10000;
                        }
                        else if (syn.Contains(queryWord, StringComparison.OrdinalIgnoreCase))
                        {
                            score += 1000;
                            score -= (syn.Length - queryWord.Length);
                        }
                    }
                }
            }

            if (nameCharactersMatched > 0)
            {
                int unmatchedCharacters = (nameSansSuffix.Length - nameCharactersMatched);
                score -= unmatchedCharacters;
            }

            return(score);
        }
Beispiel #28
0
        public void EditModel(bool isToggled, SearcherItem boundSearchItem)
        {
            var propertySearcherItem = (PropertySearcherItem)boundSearchItem;

            var action = isToggled
                ? EditPropertyGroupNodeAction.EditType.Add
                : EditPropertyGroupNodeAction.EditType.Remove;

            propertySearcherItem.Enabled = isToggled;

            var memberReference = new TypeMember(propertySearcherItem.MemberInfo.UnderlyingType,
                                                 BuildMemberPath(propertySearcherItem));

            m_Store.Dispatch(new EditPropertyGroupNodeAction(action, m_PropertyGroupModel, memberReference));
        }
Beispiel #29
0
        public GraphElementSearcherDatabase AddBinaryOperators()
        {
            SearcherItem parent = SearcherItemUtility.GetItemFromPath(Items, k_Operator);

            foreach (BinaryOperatorKind kind in Enum.GetValues(typeof(BinaryOperatorKind)))
            {
                parent.AddChild(new GraphNodeModelSearcherItem(
                                    new BinaryOperatorSearcherItemData(kind),
                                    data => data.CreateBinaryOperatorNode(kind),
                                    kind.ToString()
                                    ));
            }

            return(this);
        }
Beispiel #30
0
        public static bool TryAddEnumItem(
            this List <SearcherItem> items,
            SearcherItem itemToAdd,
            ITypeMetadata meta,
            string parentName = ""
            )
        {
            if (meta.IsEnum)
            {
                items.AddAtPath(itemToAdd, parentName + "/" + k_Enums);
                return(true);
            }

            return(false);
        }