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); }
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); }
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); }
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;
public virtual bool Contains(SearchItem item) { throw new NotSupportedException(); }
public virtual bool Remove(SearchItem item) { throw new NotSupportedException(); }
[SearchSelector("options", priority: 9)] static object GetSearchItemOptions(SearchItem item) => item.options;
public virtual void Add(SearchItem item) { throw new NotSupportedException(); }
public static object Getter(SearchItem item, SearchColumn column) { var p = GetSerializedProperty(item, column, out var _); return(p); }
internal void OnEnable() { item = ((SearchServiceItem)serializedObject.targetObject).item; }
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); }
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) { }
public IDisposable Push(SearchItem item) { items.Push(item); return(new PushPopScope <SearchItem>(items)); }
public int GetHashCode(SearchItem obj) => GetValueToCompare(obj).GetHashCode();
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();
static object GetAssetFilename(SearchItem item) { return(Path.GetFileName(GetAssetPath(item))); }
protected abstract void OnAggregateResult(SearchExpressionContext currentContext, SearchItem currentItem);
[SearchSelector("thumbnail", priority: 9)] static object GetSearchItemThumbnail(SearchItem item) => item.GetThumbnail(item.context, cacheThumbnail: false);
public bool OpenContextualMenu(Event evt, SearchItem item) { return false; }
protected override void OnAggregateResult(SearchExpressionContext currentContext, SearchItem currentItem) { m_Aggregator = m_OnAggregateResult(currentContext, currentItem, m_Aggregator); }
static object GetAssetName(SearchItem item) { var obj = item.ToObject(); return(obj?.name); }
public virtual int IndexOf(SearchItem item) { throw new NotImplementedException(); }
public virtual void Insert(int index, SearchItem item) { throw new NotSupportedException(); }
[SearchSelector("score", priority: 9)] static object GetSearchItemScore(SearchItem item) => item.score;