Esempio n. 1
0
        private SearchRequest BuildFromSearchQuery(SearchExpressionNode node, string searchQuery)
        {
            var providers = new List <SearchProvider>();

            if (node.source?.type == ExpressionType.Provider)
            {
                var selectedProviderName = Convert.ToString(node.source.value);
                if (!m_AdditionalProviders.TryGetValue(selectedProviderName, out var selectedProvider))
                {
                    selectedProvider = SearchService.GetProvider(selectedProviderName);
                }
                if (selectedProvider != null)
                {
                    providers.Add(selectedProvider);
                }
            }
            else if (node.source == null)
            {
                providers.AddRange(SearchService.Providers.Where(p => p.active));
            }
            else
            {
                throw new NotSupportedException($"Evaluation of source node {node.source.id} of type {node.source.type} is not supported.");
            }

            requestCount++;
            return(new SearchRequest(node.type, SearchService.CreateContext(providers, searchQuery, m_SearchOptions)));
        }
Esempio n. 2
0
        public static List <SearchItem> GetAllSearchQueryItems(SearchContext context)
        {
            s_SavedQueries = s_SavedQueries ?? GetAllQueries();
            var queryProvider = SearchService.GetProvider(Providers.Query.type);

            return(s_SavedQueries.Where(query => query && query.providerIds.Any(id => context.filters.Any(f => f.isEnabled && f.provider.name.id == id))).Select(query =>
            {
                var id = GlobalObjectId.GetGlobalObjectIdSlow(query).ToString();
                var description = string.IsNullOrEmpty(query.description) ? $"{query.searchQuery} - {AssetDatabase.GetAssetPath(query)}" : query.description;
                var thumbnail = query.icon ? query.icon : Icons.favorite;
                return queryProvider.CreateItem(context, id, query.name, description, thumbnail, query);
            }).ToList());
        }
Esempio n. 3
0
        public static List <SearchItem> GetAllSearchQueryItems()
        {
            var queryProvider = SearchService.GetProvider(Providers.Query.type);

            return(s_SearchQueryItems ?? (s_SearchQueryItems = SearchQuery.GetAllQueries().Select(query =>
            {
                var item = queryProvider.CreateItem(AssetDatabase.GetAssetPath(query.GetInstanceID()));
                item.label = string.IsNullOrEmpty(query.title) ? query.name : query.title;
                item.thumbnail = query.icon ? query.icon : Icons.favorite;
                item.description = string.IsNullOrEmpty(query.description) ? $"{query.searchQuery} - {AssetDatabase.GetAssetPath(query)}" : query.description;
                item.data = query;
                return item;
            }).ToList()));
        }
Esempio n. 4
0
        internal IEnumerable <SearchItem> SelectReferences(SearchItem item, string type, int depth)
        {
            var obj = item.provider?.toObject?.Invoke(item, typeof(UnityEngine.Object));

            if (!obj)
            {
                return(Enumerable.Empty <SearchItem>());
            }

            var assetProvider = SearchService.GetProvider("asset");

            return(SearchUtils.GetReferences(obj, depth)
                   .Where(path => string.IsNullOrEmpty(type) || AssetDatabase.GetMainAssetTypeAtPath(path)?.Name == type)
                   .Select(path => assetProvider.CreateItem(path)));
        }
Esempio n. 5
0
        public static List <SearchItem> GetAllSearchQueryItems(SearchContext context = null)
        {
            s_SavedQueries = s_SavedQueries ?? GetAllQueries();
            var queryProvider = SearchService.GetProvider(Providers.Query.type);

            return(s_SavedQueries.Where(query => query && context == null || query.providerIds.Any(id => context.providers.Any(p => p.name.id == id))).Select(query =>
            {
                var item = queryProvider.CreateItem(AssetDatabase.GetAssetPath(query.GetInstanceID()));
                item.label = query.name;
                item.thumbnail = query.icon ? query.icon : Icons.favorite;
                item.description = string.IsNullOrEmpty(query.description) ? $"{query.searchQuery} - {AssetDatabase.GetAssetPath(query)}" : query.description;
                item.data = query;
                return item;
            }).ToList());
        }
Esempio n. 6
0
        private SearchRequest BuildSearchRequest(SearchExpressionNode node)
        {
            var searchQuery = Convert.ToString(node.value);

            if (node.variables != null)
            {
                // Replace constants
                foreach (var v in node.variables)
                {
                    if (v.type != ExpressionType.Value)
                    {
                        continue;
                    }

                    var constantValue = Convert.ToString(v.source.value);
                    if (String.IsNullOrEmpty(constantValue))
                    {
                        UnityEngine.Debug.LogWarning($"Constant value is null for {v.source.id}");
                    }

                    searchQuery = searchQuery.Replace($"${v.name}", constantValue);
                }

                foreach (var v in node.variables)
                {
                    if (v.type == ExpressionType.Value)
                    {
                        continue;
                    }

                    switch (v.type)
                    {
                    case ExpressionType.Search:
                    case ExpressionType.Select:
                    {
                        var varName = v.name;
                        return(BuildRequest(v.source).Join(varValue =>
                            {
                                var selectNode = new SearchExpressionNode(node.type, node.source, searchQuery.Replace($"${varName}", varValue));
                                return BuildRequest(selectNode);
                            }));
                    }

                    case ExpressionType.Undefined:
                        break;

                    default:
                        throw new NotSupportedException($"Evaluation of variable {v.name} of type {v.type} not supported");
                    }
                }
            }

            var providers = new List <SearchProvider>();

            if (node.source?.type == ExpressionType.Provider)
            {
                var selectedProviderName = Convert.ToString(node.source.value);
                if (!m_AdditionalProviders.TryGetValue(selectedProviderName, out var selectedProvider))
                {
                    selectedProvider = SearchService.GetProvider(selectedProviderName);
                }
                if (selectedProvider != null)
                {
                    providers.Add(selectedProvider);
                }
            }
            else if (node.source == null)
            {
                providers.AddRange(SearchService.Providers.Where(p => p.active));
            }
            else
            {
                throw new NotSupportedException($"Evaluation of source node {node.source.id} of type {node.source.type} is not supported.");
            }

            requestCount++;
            return(new SearchRequest(node.type, SearchService.CreateContext(providers, searchQuery, m_SearchOptions)));
        }