コード例 #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();
                    }
                }
            }
コード例 #5
0
 public bool Equals(SearchItem x, SearchItem y) => DefaultComparer(GetValueToCompare(x), GetValueToCompare(y)) == 0;
コード例 #6
0
ファイル: SearchList.cs プロジェクト: leek9d/UnityCsReference
 public virtual bool Contains(SearchItem item)
 {
     throw new NotSupportedException();
 }
コード例 #7
0
ファイル: SearchList.cs プロジェクト: leek9d/UnityCsReference
 public virtual bool Remove(SearchItem item)
 {
     throw new NotSupportedException();
 }
コード例 #8
0
 [SearchSelector("options", priority: 9)] static object GetSearchItemOptions(SearchItem item) => item.options;
コード例 #9
0
ファイル: SearchList.cs プロジェクト: leek9d/UnityCsReference
 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)
 {
 }
コード例 #14
0
 public static object SelectValue(SearchItem item, SearchContext context, string selectorName)
 {
     return(SelectValue(item, context, selectorName, out var _));
 }
コード例 #15
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);
            }

            #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);
            }
        }
コード例 #16
0
 internal SearchSelectorArgs(SelectorMatch match, SearchItem current)
 {
     groups       = match.groups;
     this.current = current;
 }
コード例 #17
0
 public void DoubleClick(SearchItem item)
 {
 }
コード例 #18
0
 public IDisposable Push(SearchItem item)
 {
     items.Push(item);
     return(new PushPopScope <SearchItem>(items));
 }
コード例 #19
0
 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;
 }
コード例 #21
0
 [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);
コード例 #24
0
 [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
ファイル: SearchList.cs プロジェクト: leek9d/UnityCsReference
 public virtual int IndexOf(SearchItem item)
 {
     throw new NotImplementedException();
 }
コード例 #29
0
ファイル: SearchList.cs プロジェクト: leek9d/UnityCsReference
 public virtual void Insert(int index, SearchItem item)
 {
     throw new NotSupportedException();
 }
コード例 #30
0
 [SearchSelector("score", priority: 9)] static object GetSearchItemScore(SearchItem item) => item.score;