Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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
            }
        }
Ejemplo n.º 3
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);
            }
        }
        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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
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);
            }
        }