コード例 #1
0
        public override void Draw(Rect screenRect, ICollection <int> selection)
        {
            if (Event.current.type == EventType.Repaint)
            {
                AdvancedDropdownGUI.LoadStyles();
            }

            if (Event.current.type == EventType.Repaint)
            {
                m_NextFrame?.Invoke();
                m_NextFrame = null;
            }

            if (m_PropertyTable != null)
            {
                using (SearchMonitor.GetView())
                {
                    m_PropertyTable.OnGUI(screenRect);
                }
            }
            else
            {
                GUI.Label(screenRect, L10n.Tr("No table configuration selected"), Styles.noResult);
            }
        }
コード例 #2
0
        private IEnumerable <SearchItem> EvaluateExpression(SearchContext context, SearchProvider expressionProvider)
        {
            if (string.IsNullOrEmpty(context.searchText) || context.options.HasAny(SearchFlags.QueryString))
            {
                yield break;
            }

            var rootExpression = ParseExpression(context, expressionProvider);

            if (rootExpression == null || (rootExpression.types.HasAny(SearchExpressionType.QueryString) &&
                                           rootExpression.parameters.Length == 0 && rootExpression.innerText == rootExpression.outerText))
            {
                yield break;
            }

            #if USE_PROPERTY_DATABASE
            using (SearchMonitor.GetView())
            #endif
            {
                var evaluationFlags = SearchExpressionExecutionFlags.ThreadedEvaluation;
                var it = rootExpression.Execute(context, evaluationFlags).GetEnumerator();
                while (EvaluateExpression(context, expressionProvider, it))
                {
                    yield return(it.Current);
                }

                #if USE_SEARCH_MODULE
                TableView.SetupColumns(context, rootExpression);
                #endif
            }
        }
コード例 #3
0
        private void IncrementalLoad(string indexPath)
        {
            var loadTask = new Task("Read", $"Loading {name.ToLowerInvariant()} search index", (task, data) => Setup(), this);

            loadTask.RunThread(() =>
            {
                var step = 0;
                loadTask.Report($"Loading {indexPath}...");
                var fileBytes = File.ReadAllBytes(indexPath);

                loadTask.Report(++step, step + 1);
                if (!index.LoadBytes(fileBytes))
                {
                    Debug.LogError($"Failed to load {indexPath}.");
                }

                var deletedAssets = new HashSet <string>();
                foreach (var d in index.GetDocuments())
                {
                    if (d.valid && !File.Exists(d.source))
                    {
                        deletedAssets.Add(d.source);
                    }
                }

                bytes = fileBytes;
                loadTask.Report($"Checking for changes...");
                loadTask.Report(++step, step + 1);
                Dispatcher.Enqueue(() =>
                {
                    if (!this)
                    {
                        loadTask.Resolve(null, completed: true);
                        return;
                    }

                    var diff = SearchMonitor.GetDiff(index.timestamp, deletedAssets, path =>
                    {
                        if (index.SkipEntry(path, true))
                        {
                            return(false);
                        }

                        if (!index.TryGetHash(path, out var hash) || !hash.isValid)
                        {
                            return(true);
                        }

                        return(hash != index.GetDocumentHash(path));
                    });
                    if (!diff.empty)
                    {
                        IncrementalUpdate(diff);
                    }

                    loadTask.Resolve(new TaskData(fileBytes, index));
                });
            });
        }
コード例 #4
0
        internal static void OnPostprocessAllAssets(string[] imported, string[] deleted, string[] movedTo, string[] movedFrom)
        {
            if (!Utils.IsMainProcess())
            {
                return;
            }

            SearchMonitor.RaiseContentRefreshed(imported, deleted.Concat(movedFrom).Distinct().ToArray(), movedTo);
        }
コード例 #5
0
        public static object SelectValue(SearchItem item, SearchContext context, string selectorName, out string suggestedSelectorName)
        {
            suggestedSelectorName = selectorName;
            if (item.TryGetValue(selectorName, context, out var field))
            {
                return(field.value);
            }

            if (string.IsNullOrEmpty(selectorName))
            {
                return(null);
            }

            using (var view = SearchMonitor.GetView())
            {
                if (view.TryLoadProperty(item.key, selectorName, out var recordKey, out var cv, out suggestedSelectorName))
                {
                    return(cv);
                }

                string localSuggestedSelectorName = null;
                string providerType = item.provider.type;
                var    itemValue    = TaskEvaluatorManager.EvaluateMainThread(() =>
                {
                    foreach (var m in Match(selectorName, providerType))
                    {
                        var selectorArgs  = new SearchSelectorArgs(m, item);
                        var selectedValue = m.selector.select(selectorArgs);
                        if (selectedValue != null)
                        {
                            if (selectorArgs.name != null)
                            {
                                localSuggestedSelectorName = selectorArgs.name;
                            }
                            return(selectedValue);
                        }
                    }

                    return(null);
                });

                if (itemValue == null)
                {
                    return(null);
                }

                if (!string.IsNullOrEmpty(localSuggestedSelectorName))
                {
                    suggestedSelectorName = localSuggestedSelectorName;
                }

                view.StoreProperty(recordKey, itemValue, suggestedSelectorName);

                return(itemValue);
            }
        }
コード例 #6
0
        public bool TryLoadProperty(PropertyDatabaseRecordKey recordKey, out object data)
        {
            if (propertyDatabaseView.TryLoad(recordKey, out data))
            {
                SearchMonitor.Log("Load property", recordKey, data);
                return(true);
            }

            SearchMonitor.Log("<color=red>Failed</color> to load property", recordKey);
            return(false);
        }
コード例 #7
0
 public bool TryLoadAlias(PropertyDatabaseRecordKey recordKey, out string alias)
 {
     if (!propertyAliasesView.TryLoad(recordKey, out object aliasObj))
     {
         SearchMonitor.Log("<color=red>Failed</color> to load alias", recordKey);
         alias = null;
         return(false);
     }
     alias = aliasObj as string;
     SearchMonitor.Log("Load alias", recordKey, alias);
     return(alias != null);
 }
コード例 #8
0
        public bool TryLoadProperty(ulong documentKey, string propertyName, out PropertyDatabaseRecordKey recordKey, out object value, out string alias)
        {
            var propertyHash = PropertyDatabase.CreatePropertyHash(propertyName);

            recordKey = PropertyDatabase.CreateRecordKey(documentKey, propertyHash);
            if (!propertyAliasesView.TryLoad(recordKey, out object aliasObj))
            {
                value = null;
                alias = propertyName;
                SearchMonitor.Log($"<color=red>Failed</color> to load {propertyName} without alias", recordKey, propertyName);
                return(false);
            }

            alias = (aliasObj as string) ?? propertyName;
            if (propertyDatabaseView.TryLoad(recordKey, out value))
            {
                SearchMonitor.Log($"Load property {propertyName}", recordKey, value);
                return(true);
            }

            SearchMonitor.Log($"<color=red>Failed</color> to load property {propertyName}", recordKey, propertyName);
            return(false);
        }
コード例 #9
0
        protected override void RowGUI(RowGUIArgs args)
        {
            var evt     = Event.current;
            var rowRect = args.rowRect;

            isRenaming = isRenaming || args.isRenaming;
            if (args.item is SearchQueryCategoryTreeViewItem ctvi)
            {
                if (evt.type == EventType.Repaint)
                {
                    Styles.categoryLabel.Draw(rowRect, rowRect.Contains(evt.mousePosition), false, false, false);
                }

                EditorGUI.BeginDisabledGroup(!searchView.CanSaveQuery());
                var addBtn = new Rect(rowRect.xMax - 21f, rowRect.y, 22f, 22f);
                if (GUI.Button(addBtn, ctvi.addBtnContent, Styles.toolbarButton))
                {
                    switch (ctvi.content.text)
                    {
                    case userQuery:
                        searchView.SaveUserSearchQuery();
                        break;

                    case projectQuery:
                        searchView.SaveProjectSearchQuery();
                        break;
                    }
                }
                EditorGUI.EndDisabledGroup();

                var labelBtn = rowRect;
                labelBtn.width -= 20f;
                if (GUI.Button(labelBtn, Utils.GUIContentTemp($"{ctvi.content.text} ({ctvi.children.Count})", ctvi.content.tooltip), Styles.categoryLabel))
                {
                    SetExpanded(args.item.id, !IsExpanded(args.item.id));
                }
            }
            else if (args.item is SearchQueryTreeViewItem tvi)
            {
                if (!tvi.IsValid())
                {
                    SearchQueryAsset.ResetSearchQueryItems();
                    Reload();
                    return;
                }

                if (!args.isRenaming && evt.type == EventType.Repaint)
                {
                    var hovered = rowRect.Contains(evt.mousePosition);

                    using (var view = SearchMonitor.GetView())
                    {
                        if (tvi.query != null)
                        {
                            DrawQueryLabelAndIcon(rowRect, args, tvi, hovered, true);
                            DrawItemCount(tvi.query.itemCount, rowRect, hovered, args.selected);
                        }
                    }
                }
            }
        }
コード例 #10
0
        public static SerializedProperty FindProperty(UnityEngine.Object obj, string propertyPath, out SerializedObject so)
        {
            if (!obj)
            {
                so = null;
                return(null);
            }

            so = new SerializedObject(obj);
            var property = so.FindProperty(propertyPath);

            if (property != null)
            {
                return(property);
            }

            #if USE_PROPERTY_DATABASE
            using (var view = SearchMonitor.GetView())
            #endif
            {
                #if USE_PROPERTY_DATABASE
                var unresolvedPropertyPath = $"{obj.GetType().Name}.{propertyPath}";
                var propertyPathRecordKey  = PropertyDatabase.CreateRecordKey(obj.GetType().Name, unresolvedPropertyPath);
                if (view.TryLoadAlias(propertyPathRecordKey, out var resolvedPropertyPath))
                {
                    if (string.IsNullOrEmpty(resolvedPropertyPath))
                    {
                        so?.Dispose();
                        return(null);
                    }

                    var resolvedProperty = so.FindProperty(resolvedPropertyPath);
                    if (resolvedProperty != null)
                    {
                        return(resolvedProperty);
                    }
                }
                #endif

                property = so.FindProperty($"m_{propertyPath}");
                if (property != null)
                {
                    #if USE_PROPERTY_DATABASE
                    view.StoreAlias(propertyPathRecordKey, property.propertyPath);
                    #endif
                    return(property);
                }

                property = so.GetIterator();
                var next = property.NextVisible(true);
                while (next)
                {
                    if (property.name.EndsWith(propertyPath, StringComparison.OrdinalIgnoreCase))
                    {
                        #if USE_PROPERTY_DATABASE
                        view.StoreAlias(propertyPathRecordKey, property.propertyPath);
                        #endif
                        return(property);
                    }
                    next = property.NextVisible(property.hasChildren);
                }

                #if USE_PROPERTY_DATABASE
                view.StoreAlias(propertyPathRecordKey, string.Empty);
                #endif
                so?.Dispose();
                so = null;
                return(null);
            }
        }
コード例 #11
0
 public void Invalidate(PropertyDatabaseRecordKey recordKey)
 {
     SearchMonitor.Log("Invalidate record", recordKey);
     propertyDatabaseView.Invalidate(recordKey);
     propertyAliasesView.Invalidate(recordKey);
 }
コード例 #12
0
 public void InvalidateDocument(string documentKey)
 {
     SearchMonitor.Log("Invalidate document");
     propertyDatabaseView.Invalidate(documentKey);
     propertyAliasesView.Invalidate(documentKey);
 }
コード例 #13
0
 public void StoreAlias(PropertyDatabaseRecordKey key, string alias)
 {
     propertyAliasesView.Store(key, alias);
     SearchMonitor.Log("Store alias", key, alias);
 }
コード例 #14
0
 public void StoreProperty(PropertyDatabaseRecordKey recordKey, object value)
 {
     propertyDatabaseView.Store(recordKey, value);
     SearchMonitor.Log("Store property", recordKey, value);
 }
コード例 #15
0
 public SearchDatabase Reload(string settingsPath)
 {
     m_IndexSettingsPath = settingsPath;
     SearchMonitor.RaiseContentRefreshed(new[] { settingsPath }, new string[0], new string[0]);
     return(Reload(LoadSettings(settingsPath)));
 }