Example #1
0
        public static IEnumerable <SearchProposition> GetPropositions(this IQueryEngineFilter filter)
        {
            // Here is the order in which the propositions are applied
            // 1. Global proposition
            // 2. Custom propositions
            if (filter.metaInfo == null || filter.metaInfo.Count == 0)
            {
                return(Enumerable.Empty <SearchProposition>());
            }

            var propositionKeys = filter.metaInfo.Keys.Where(key => key.StartsWith(k_BaseSearchPropositionDataKey, StringComparison.Ordinal)).ToList();

            if (propositionKeys.Count == 0)
            {
                return(Enumerable.Empty <SearchProposition>());
            }

            var globalProposition = GetGlobalProposition(filter);

            if (!globalProposition.valid)
            {
                globalProposition = GetDefaultValidProposition();
            }
            var validPropositions  = propositionKeys.Select(key => filter.GetPropositionFromKey(key)).Where(p => p.valid);
            var customPropositions = MergePropositions(globalProposition, validPropositions);

            return(MergePropositions(globalProposition, customPropositions));
        }
Example #2
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);
        }
Example #3
0
        public static SearchProposition GetProposition(this IQueryEngineFilter filter, string label)
        {
            if (string.IsNullOrEmpty(label))
            {
                return(SearchProposition.invalid);
            }

            var key = GetPropositionKey(label);

            return(GetPropositionFromKey(filter, key));
        }
Example #4
0
        static IEnumerable <SearchProposition> GetPropositionsFromType(IQueryEngineFilter filter, Type type, string category = null, Type blockType = null, int priority = 0, Texture2D icon = null, Color color = default)
        {
            var filterId        = filter.token;
            var defaultOperator = filter.supportedOperators == null ? ":" : filter.supportedOperators.FirstOrDefault();

            if (type.IsEnum)
            {
                return(SearchUtils.FetchEnumPropositions(type, category, filterId, defaultOperator, blockType, priority, icon, color));
            }

            return(Enumerable.Empty <SearchProposition>());
        }
Example #5
0
        public static SearchProposition GetPropositionFromKey(this IQueryEngineFilter filter, string propositionKey)
        {
            if (!filter.metaInfo.TryGetValue(propositionKey, out var propositionDescriptionStr))
            {
                return(SearchProposition.invalid);
            }

            var propositionDescription = new SearchPropositionDescription();

            EditorJsonUtility.FromJsonOverwrite(propositionDescriptionStr, propositionDescription);
            return(propositionDescription.ToSearchProposition());
        }
Example #6
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);
        }
Example #7
0
        public static IQueryEngineFilter SetGlobalPropositionData(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 propositionDescription = new SearchPropositionDescription()
            {
                category   = category,
                help       = help,
                data       = data,
                priority   = priority,
                icon       = icon,
                type       = type?.FullName,
                moveCursor = moveCursor,
                color      = color
            };

            var propositionKey = GetGlobalPropositionKey();

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

            return(filter);
        }
Example #8
0
        public static SearchProposition GetGlobalProposition(this IQueryEngineFilter filter)
        {
            var key = GetGlobalPropositionKey();

            return(GetPropositionFromKey(filter, key));
        }
Example #9
0
 public FilterOperatorContext(IQueryEngineFilter filter)
 {
     this.filter = filter;
 }