static AdvancedObjectSelector GenerateAdvancedObjectSelectorWrapper(Dictionary <int, AdvancedObjectSelectorValidator> validators, AdvancedObjectSelectorAttribute attribute, AdvancedObjectSelectorHandler handler) { if (!validators.TryGetValue(attribute.id.GetHashCode(), out var validator)) { throw new CustomAttributeFormatException($"Advanced Object Selector id \"{attribute.id}\" does not have a matching validator."); } var priority = attribute.defaultPriority; var active = attribute.defaultActive; var displayName = string.IsNullOrEmpty(attribute.displayName) ? SearchUtils.ToPascalWithSpaces(attribute.id) : attribute.displayName; if (SearchSettings.TryGetObjectSelectorSettings(attribute.id, out var settings)) { priority = settings.priority; active = settings.active; } return(new AdvancedObjectSelector(attribute.id, displayName, priority, active, handler, validator)); }
/// <summary> /// Create a new SearchProvider /// </summary> /// <param name="id">Search Provider unique id.</param> /// <param name="displayName">Provider pretty name, use to display in UI.</param> /// <param name="fetchItemsHandler">Handler responsible to populate a list of SearchItems according to a query.</param> public SearchProvider(string id, string displayName, Func <SearchContext, List <SearchItem>, SearchProvider, object> fetchItemsHandler) { if (String.IsNullOrEmpty(id)) { throw new ArgumentException("provider id must be non-empty", nameof(id)); } this.id = id; type = id; active = true; name = displayName ?? SearchUtils.ToPascalWithSpaces(id); actions = new List <SearchAction>(); fetchItems = fetchItemsHandler ?? ((context, items, provider) => null); fetchThumbnail = (item, context) => item.thumbnail ?? Icons.quicksearch; fetchPreview = null; fetchLabel = (item, context) => item.label ?? item.id ?? String.Empty; fetchDescription = null; priority = 100; showDetails = false; showDetailsOptions = ShowDetailsOptions.Default; filterId = $"{id}:"; defaultContext = new SearchContext(this); }
/// <summary> /// Extended constructor to build a search action. /// </summary> /// <param name="providerId">Provider Id that supports this action.</param> /// <param name="name">Label name when displaying the action in the Action Menu</param> /// <param name="icon">Icon when displaying the action in the Action Menu</param> /// <param name="tooltip">Tooltip assocoated with the when displayed in the Action Menu</param> /// <param name="handler">Handler that will execute the action.</param> public SearchAction(string providerId, string name, Texture2D icon, string tooltip, Action <SearchItem> handler) : this(providerId, name, new GUIContent(SearchUtils.ToPascalWithSpaces(name), icon, tooltip ?? name), handler) { }
/// <summary> /// Extended constructor to build a search action. /// </summary> /// <param name="providerId">Provider Id that supports this action.</param> /// <param name="name">Label name when displaying the action in the Action Menu</param> /// <param name="icon">Icon when displaying the action in the Action Menu</param> /// <param name="tooltip">Tooltip associated with the when displayed in the Action Menu</param> public SearchAction(string providerId, string name, Texture2D icon = null, string tooltip = null) : this(providerId, name, new GUIContent(SearchUtils.ToPascalWithSpaces(name), icon, tooltip ?? name)) { }