示例#1
0
        static bool TryGetScenePath(SearchItem item, out string path)
        {
            path = item.data as string;
            if (!string.IsNullOrEmpty(path))
            {
                return(true);
            }

            if (!GlobalObjectId.TryParse(item.id, out var gid))
            {
                return(false);
            }

            var scenePath = AssetDatabase.GUIDToAssetPath(gid.assetGUID);

            if (string.IsNullOrEmpty(scenePath))
            {
                return(false);
            }

            item.data = path = scenePath;
            return(true);
        }
示例#2
0
        internal static SerializedProperty GetSerializedProperty(SearchItem item, SearchColumn column, out SerializedObject so)
        {
            foreach (var m in SelectorManager.Match(column.selector, item.provider?.type))
            {
                var selectorArgs = new SearchSelectorArgs(m, item);
                if (selectorArgs.name == null)
                {
                    continue;
                }
                var property = GetSerializedProperty(item, selectorArgs.name, out so);
                if (property == null)
                {
                    so?.Dispose();
                    continue;
                }

                so.UpdateIfRequiredOrScript();
                return(property);
            }

            so = null;
            return(null);
        }
示例#3
0
        static bool GetRange(SearchItem item, ref RangeDouble range)
        {
            if (item == null)
            {
                return(false);
            }
            if (!range.start.HasValue)
            {
                if (Utils.TryGetNumber(item.value, out var rs))
                {
                    range.start = rs;
                }
            }
            else if (!range.end.HasValue)
            {
                if (Utils.TryGetNumber(item.value, out var re))
                {
                    range.end = re;
                }
            }

            return(range.valid);
        }
示例#4
0
            public static void Setter(SearchItem item, SearchColumn column, object newValue, bool multiple)
            {
                if (!(newValue is SerializedProperty newValueProperty))
                {
                    return;
                }

                if (!multiple)
                {
                    newValueProperty.serializedObject.ApplyModifiedProperties();
                }
                else
                {
                    var property = GetSerializedProperty(item, column, out var so);
                    if (property != null && so != null)
                    {
                        so.CopyFromSerializedProperty(newValueProperty);
                        so.ApplyModifiedProperties();

                        property.Dispose();
                        so.Dispose();
                    }
                }
            }
 public bool Equals(SearchItem x, SearchItem y) => DefaultComparer(GetValueToCompare(x), GetValueToCompare(y)) == 0;
示例#6
0
 public virtual bool Contains(SearchItem item)
 {
     throw new NotSupportedException();
 }
示例#7
0
 public virtual bool Remove(SearchItem item)
 {
     throw new NotSupportedException();
 }
 [SearchSelector("options", priority: 9)] static object GetSearchItemOptions(SearchItem item) => item.options;
示例#9
0
 public virtual void Add(SearchItem item)
 {
     throw new NotSupportedException();
 }
示例#10
0
            public static object Getter(SearchItem item, SearchColumn column)
            {
                var p = GetSerializedProperty(item, column, out var _);

                return(p);
            }
示例#11
0
 internal void OnEnable()
 {
     item = ((SearchServiceItem)serializedObject.targetObject).item;
 }
示例#12
0
        public static GUIContent FormatDescription(SearchItem item, SearchContext context, float availableSpace, bool useColor = true)
        {
            var desc = item.GetDescription(context);

            if (desc != null && item.options.HasAny(SearchItemOptions.Compacted))
            {
                desc = desc.Replace("\n", " ");
            }
            if (String.IsNullOrEmpty(desc))
            {
                return(Styles.emptyContent);
            }
            var content = Take(desc);

            if (item.options == SearchItemOptions.None || Event.current.type != EventType.Repaint)
            {
                return(content);
            }

            var truncatedDesc = desc;
            var truncated     = false;

            if (useColor)
            {
                if (item.options.HasAny(SearchItemOptions.Ellipsis))
                {
                    int maxCharLength = Utils.GetNumCharactersThatFitWithinWidth(Styles.itemDescription, truncatedDesc + "...", availableSpace);
                    if (maxCharLength < 0)
                    {
                        maxCharLength = truncatedDesc.Length;
                    }
                    truncated = desc.Length > maxCharLength;
                    if (truncated)
                    {
                        if (item.options.HasAny(SearchItemOptions.RightToLeft))
                        {
                            truncatedDesc = "..." + desc.Replace("<b>", "").Replace("</b>", "");
                            truncatedDesc = truncatedDesc.Substring(Math.Max(0, truncatedDesc.Length - maxCharLength));
                        }
                        else
                        {
                            truncatedDesc = desc.Substring(0, Math.Min(maxCharLength, desc.Length)) + "...";
                        }
                    }
                }

                if (context != null)
                {
                    if (item.options.HasAny(SearchItemOptions.Highlight))
                    {
                        var parts = context.searchQuery.Split('*', ' ', '.').Where(p => p.Length > 2);
                        foreach (var p in parts)
                        {
                            truncatedDesc = Regex.Replace(truncatedDesc, Regex.Escape(p), string.Format(Styles.highlightedTextColorFormat, "$0"), RegexOptions.IgnoreCase);
                        }
                    }
                    else if (item.options.HasAny(SearchItemOptions.FuzzyHighlight))
                    {
                        long score   = 1;
                        var  matches = new List <int>();
                        var  sq      = Utils.CleanString(context.searchQuery.ToLowerInvariant());
                        if (FuzzySearch.FuzzyMatch(sq, Utils.CleanString(truncatedDesc), ref score, matches))
                        {
                            truncatedDesc = RichTextFormatter.FormatSuggestionTitle(truncatedDesc, matches);
                        }
                    }
                }
            }

            content.text = truncatedDesc;
            if (truncated)
            {
                content.tooltip = Utils.StripHTML(desc);
            }

            return(content);
        }
示例#13
0
 public void OnItemExecuted(SearchItem item)
 {
 }
 public static object SelectValue(SearchItem item, SearchContext context, string selectorName)
 {
     return(SelectValue(item, context, selectorName, out var _));
 }
        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);
            }

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

                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;
                }

                #if USE_PROPERTY_DATABASE
                view.StoreProperty(recordKey, itemValue, suggestedSelectorName);
                #endif

                return(itemValue);
            }
        }
 internal SearchSelectorArgs(SelectorMatch match, SearchItem current)
 {
     groups       = match.groups;
     this.current = current;
 }
 public void DoubleClick(SearchItem item)
 {
 }
示例#18
0
 public IDisposable Push(SearchItem item)
 {
     items.Push(item);
     return(new PushPopScope <SearchItem>(items));
 }
 public int GetHashCode(SearchItem obj) => GetValueToCompare(obj).GetHashCode();
示例#20
0
 public PropertyItem(int id, int depth, SearchItem ltd)
     : base(id, depth, ltd != null ? ltd.id : "root")
 {
     m_Data = ltd;
 }
 [SearchSelector("data", priority: 9)] static object GetSearchItemData(SearchItem item) => item.data?.ToString();
示例#22
0
 static object GetAssetFilename(SearchItem item)
 {
     return(Path.GetFileName(GetAssetPath(item)));
 }
示例#23
0
 protected abstract void OnAggregateResult(SearchExpressionContext currentContext, SearchItem currentItem);
 [SearchSelector("thumbnail", priority: 9)] static object GetSearchItemThumbnail(SearchItem item) => item.GetThumbnail(item.context, cacheThumbnail: false);
示例#25
0
 public bool OpenContextualMenu(Event evt, SearchItem item)
 {
     return false;
 }
示例#26
0
 protected override void OnAggregateResult(SearchExpressionContext currentContext, SearchItem currentItem)
 {
     m_Aggregator = m_OnAggregateResult(currentContext, currentItem, m_Aggregator);
 }
示例#27
0
        static object GetAssetName(SearchItem item)
        {
            var obj = item.ToObject();

            return(obj?.name);
        }
示例#28
0
 public virtual int IndexOf(SearchItem item)
 {
     throw new NotImplementedException();
 }
示例#29
0
 public virtual void Insert(int index, SearchItem item)
 {
     throw new NotSupportedException();
 }
 [SearchSelector("score", priority: 9)] static object GetSearchItemScore(SearchItem item) => item.score;