public static IEnumerable <SearchItem> Select(SearchExpressionContext c) { if (c.args.Length < 2) { c.ThrowError($"Invalid arguments"); } // Select dataset var dataset = c.args[0].Execute(c); var results = dataset; var sIt = c.args.Skip(1).GetEnumerator(); while (sIt.MoveNext()) { var selector = sIt.Current; if (IsSelectorLiteral(selector)) { var selectorName = selector.innerText.ToString(); var selectorAlias = c.ResolveAlias(selector); results = TaskEvaluatorManager.EvaluateMainThread(results, item => { var selectedValue = SelectorManager.SelectValue(item, c.search, selectorName, out string suggestedSelectorName); AddSelectedValue(item, selector.innerText.ToString(), selectorAlias ?? suggestedSelectorName, selectedValue); return(item); }); } else { results = ProcessIterableSelector(c, results, selector); } } return(results); }
public static IEnumerable <SearchItem> ProcessValues <T>(IEnumerable <SearchItem> items, string outputValueFieldName, Func <SearchItem, T> processHandler) { var selectedItems = new List <SearchItem>(items); return(TaskEvaluatorManager.EvaluateMainThread <SearchItem>((yielder) => { foreach (var item in selectedItems) { var selectedValue = processHandler(item); if (selectedValue == null) { continue; } if (outputValueFieldName == null) { item.value = selectedValue; } else { item.SetField(outputValueFieldName, selectedValue); } yielder(item); } })); }
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); } }
public static IEnumerable <SearchItem> Compare(SearchExpressionContext c, Func <object, object, bool> comparer) { if (c.args.Length < 2 || c.args.Length > 3) { c.ThrowError($"Invalid arguments"); } if (c.args.Length == 3 && !IsSelectorLiteral(c.args[1])) { c.ThrowError($"Invalid selector"); } var setExpr = c.args[0]; if (!setExpr.types.IsIterable()) { c.ThrowError("Primary set is not iterable", setExpr.outerText); } string valueSelector = null; var compareExprIndex = 1; if (c.args.Length == 3) { valueSelector = c.args[1].innerText.ToString(); compareExprIndex++; } var compareExpr = c.args[compareExprIndex]; var compareValueItr = compareExpr.Execute(c).FirstOrDefault(e => e != null); if (compareValueItr == null) { c.ThrowError("Invalid comparer value", compareExpr.outerText); } var compareValue = compareValueItr.value; if (valueSelector == null) { return(setExpr.Execute(c).Where(item => item != null && comparer(item.GetValue(valueSelector), compareValue))); } return(TaskEvaluatorManager.EvaluateMainThread(setExpr.Execute(c), item => { var value = SelectorManager.SelectValue(item, c.search, valueSelector); if (value != null && comparer(value, compareValue)) { return item; } return null; }, 25)); }
public static IEnumerable <SearchItem> Selection(SearchExpressionContext c) { var selection = TaskEvaluatorManager.EvaluateMainThread(() => { var instanceIds = UnityEditor.Selection.instanceIDs; return(instanceIds.Select(id => { string assetPath = AssetDatabase.GetAssetPath(id); return new SelectionResult(id, assetPath); }).ToList()); }); foreach (var selectionResult in selection) { if (string.IsNullOrEmpty(selectionResult.assetPath)) { yield return(SearchExpression.CreateItem(selectionResult.instanceId, c.ResolveAlias("Selection"))); } else { yield return(SearchExpression.CreateItem(selectionResult.assetPath, c.ResolveAlias("Selection"))); } } }
public static IEnumerable <SearchItem> SceneName(SearchExpressionContext c) { var desc = TaskEvaluatorManager.EvaluateMainThread(() => EditorApplication.GetApplicationTitleDescriptor()); yield return(SearchExpression.CreateItem(desc.activeSceneName ?? string.Empty, c.ResolveAlias("SceneName"))); }
public static IEnumerable <SearchItem> DataPath(SearchExpressionContext c) { var dataPath = TaskEvaluatorManager.EvaluateMainThread(() => Application.dataPath); yield return(SearchExpression.CreateItem(dataPath ?? string.Empty, c.ResolveAlias("DataPath"))); }