using System; using System.Text.Json.Serialization; namespace Flow.Launcher.Plugin { /// /// Represents a query that is sent to a plugin. /// public class Query { /// /// Original query, exactly how the user has typed into the search box. /// We don't recommend using this property directly. You should always use Search property. /// public string OriginalQuery { get; internal init; } /// /// Raw query, this includes action keyword if it has. /// It has handled built-in custom query hotkeys and built-in shortcuts, and it trims the whitespace. /// We don't recommend using this property directly. You should always use Search property. /// [Obsolete("RawQuery is renamed to TrimmedQuery. This property will be removed. Update the code to use TrimmedQuery instead.")] public string RawQuery { get => TrimmedQuery; internal init { TrimmedQuery = value; } } /// /// Original query but with trimmed whitespace. Includes action keyword. /// It has handled built-in custom query hotkeys and build-in shortcuts. /// If you need the exact original query from the search box, use OriginalQuery property instead. /// We don't recommend using this property directly. You should always use Search property. /// public string TrimmedQuery { get; internal init; } /// /// Determines whether the query was forced to execute again. /// For example, the value will be true when the user presses Ctrl + R. /// When this property is true, plugins handling this query should avoid serving cached results. /// public bool IsReQuery { get; internal set; } = false; /// /// Determines whether the query is a home query. /// public bool IsHomeQuery { get; internal init; } = false; /// /// Search part of a query. /// This will not include action keyword if exclusive plugin gets it, otherwise it should be same as TrimmedQuery. /// Since we allow user to switch a exclusive plugin to generic plugin, /// so this property will always give you the "real" query part of the query /// public string Search { get; internal init; } /// /// The search string split into a string array. /// Does not include the . /// public string[] SearchTerms { get; init; } /// /// Query can be splited into multiple terms by whitespace /// public const string TermSeparator = " "; /// /// User can set multiple action keywords seperated by whitespace /// public const string ActionKeywordSeparator = TermSeparator; /// /// Wildcard action keyword. Plugins using this value will be queried on every search. /// public const string GlobalPluginWildcardSign = "*"; /// /// The action keyword part of this query. /// For global plugins this value will be empty. /// public string ActionKeyword { get; init; } /// /// Splits by spaces and returns the first item. /// /// /// returns an empty string when does not have enough items. /// [JsonIgnore] public string FirstSearch => SplitSearch(0); [JsonIgnore] private string _secondToEndSearch; /// /// strings from second search (including) to last search /// [JsonIgnore] public string SecondToEndSearch => SearchTerms.Length > 1 ? (_secondToEndSearch ??= string.Join(' ', SearchTerms[1..])) : ""; /// /// Splits by spaces and returns the second item. /// /// /// returns an empty string when does not have enough items. /// [JsonIgnore] public string SecondSearch => SplitSearch(1); /// /// Splits by spaces and returns the third item. /// /// /// returns an empty string when does not have enough items. /// [JsonIgnore] public string ThirdSearch => SplitSearch(2); private string SplitSearch(int index) { return index < SearchTerms.Length ? SearchTerms[index] : string.Empty; } /// public override string ToString() => TrimmedQuery; } }