Esempio n. 1
0
 static IEnumerable <SearchProposition> MergePropositions(SearchProposition baseProposition, IEnumerable <SearchProposition> overridePropositions)
 {
     foreach (var overrideProposition in overridePropositions)
     {
         yield return(MergeProposition(baseProposition, overrideProposition));
     }
 }
Esempio n. 2
0
        public static void AddPropositionsFromFilterAttributes <TData, TAttribute>(this QueryEngine <TData> engine, string category = null,
                                                                                   int priority = 0, string data = null, Type type = null, Texture2D icon = null, Color color = default,
                                                                                   TextCursorPlacement moveCursor = TextCursorPlacement.MoveAutoComplete, Func <SearchProposition, SearchProposition> propositionTransformation = null)
            where TAttribute : QueryEngineFilterAttribute
        {
            var queryEngineFunctions = TypeCache.GetMethodsWithAttribute <TAttribute>();

            foreach (var mi in queryEngineFunctions)
            {
                var attr = mi.GetAttribute <TAttribute>();
                if (!engine.TryGetFilter(attr.token, out var filter))
                {
                    continue;
                }
                var    op    = attr.supportedOperators == null ? ">" : attr.supportedOperators[0];
                var    value = op == ":" ? "" : "1";
                var    label = attr.token;
                string help  = null;

                if (mi.ReturnType == typeof(Vector2))
                {
                    value = "(,)";
                }
                if (mi.ReturnType == typeof(Vector3))
                {
                    value = "(,,)";
                }
                if (mi.ReturnType == typeof(Vector4))
                {
                    value = "(,,,)";
                }

                var replacement = $"{attr.token}{op}{value}";

                var descriptionAttr = mi.GetAttribute <System.ComponentModel.DescriptionAttribute>();
                if (descriptionAttr != null)
                {
                    help = descriptionAttr.Description;
                }

                var proposition = new SearchProposition(label: label,
                                                        category: category,
                                                        replacement: replacement,
                                                        help: help,
                                                        data: data,
                                                        priority: priority,
                                                        icon: icon,
                                                        type: type,
                                                        color: color,
                                                        moveCursor: moveCursor);

                if (propositionTransformation != null)
                {
                    proposition = propositionTransformation(proposition);
                }

                filter.AddOrUpdatePropositionData(proposition);
            }
        }
Esempio n. 3
0
 public static SearchPropositionDescription FromSearchProposition(SearchProposition proposition)
 {
     return(new SearchPropositionDescription()
     {
         label = proposition.label,
         category = proposition.category,
         replacement = proposition.replacement,
         help = proposition.help,
         data = proposition.data?.ToString() ?? Utils.FastToLower(proposition.label),
         priority = proposition.priority,
         icon = proposition.icon,
         type = proposition.type?.FullName,
         moveCursor = proposition.moveCursor,
         color = proposition.color
     });
 }
Esempio n. 4
0
        static SearchProposition MergeProposition(SearchProposition baseProposition, SearchProposition overrideProposition)
        {
            var merged = new SearchProposition(
                category: string.IsNullOrEmpty(overrideProposition.category) ? baseProposition.category : overrideProposition.category,
                label: string.IsNullOrEmpty(overrideProposition.label) ? baseProposition.label : overrideProposition.label,
                replacement: string.IsNullOrEmpty(overrideProposition.replacement) ? baseProposition.replacement : overrideProposition.replacement,
                help: string.IsNullOrEmpty(overrideProposition.help) ? baseProposition.help : overrideProposition.help,
                priority: overrideProposition.priority == 0 ? baseProposition.priority : overrideProposition.priority,
                moveCursor: overrideProposition.moveCursor == TextCursorPlacement.MoveAutoComplete ? baseProposition.moveCursor : overrideProposition.moveCursor,
                icon: overrideProposition.icon ? overrideProposition.icon : baseProposition.icon,
                type: overrideProposition.type ?? baseProposition.type,
                data: (overrideProposition.data == null || (overrideProposition.data is string s && string.IsNullOrEmpty(s))) ? baseProposition.data : overrideProposition.data,
                color: overrideProposition.color == default(Color) ? baseProposition.color : overrideProposition.color);

            return(merged);
        }
Esempio n. 5
0
        public static IQueryEngineFilter AddPropositionsFromFilterType(this IQueryEngineFilter filter, string category = null, string help = null, string data = null,
                                                                       int priority = 0, Texture2D icon = null, System.Type type = null, Color color = default, TextCursorPlacement moveCursor = TextCursorPlacement.MoveAutoComplete)
        {
            var typePropositions    = GetPropositionsFromType(filter, filter.type, category, type, priority, icon, color);
            var propositionOverride = new SearchProposition(category: category, label: string.Empty, help: help, data: data, priority: priority, icon: icon, type: type, color: color, moveCursor: moveCursor);
            var propositions        = MergePropositions(typePropositions, propositionOverride);

            foreach (var proposition in propositions)
            {
                var propositionDescription = SearchPropositionDescription.FromSearchProposition(proposition);
                var propositionKey         = GetPropositionKey(propositionDescription.label);
                filter.AddOrUpdateMetaInfo(propositionKey, EditorJsonUtility.ToJson(propositionDescription));
            }

            return(filter);
        }
Esempio n. 6
0
        public static bool Show(SearchContext context, Rect parentRect, SearchField searchField)
        {
            var te = searchField.GetTextEditor();

            if (te.controlID != GUIUtility.keyboardControl)
            {
                return(false);
            }

            parent       = parentRect;
            options      = new SearchPropositionOptions(context, te.cursorIndex, te.text);
            propositions = SearchProposition.Fetch(context, options);

            enabled = propositions.Count > 0;
            if (!enabled)
            {
                return(false);
            }

            SearchAnalytics.SendEvent(null, SearchAnalytics.GenericEventType.QuickSearchAutoCompleteTab, string.Join(",", options.tokens));
            UpdateCompleteList(te, options);
            return(true);
        }
Esempio n. 7
0
        static IQueryEngineFilter AddOrUpdatePropositionData(this IQueryEngineFilter filter, SearchProposition proposition)
        {
            var propositionDescription = SearchPropositionDescription.FromSearchProposition(proposition);

            var propositionKey = GetPropositionKey(proposition.label);

            filter.AddOrUpdateMetaInfo(propositionKey, EditorJsonUtility.ToJson(propositionDescription));

            return(filter);
        }