2025-01-26 12:37:41 +00:00
|
|
|
|
using System.Text.Json.Serialization;
|
2013-12-19 15:51:20 +00:00
|
|
|
|
|
2020-04-21 09:12:17 +00:00
|
|
|
|
namespace Flow.Launcher.Plugin
|
2013-12-19 15:51:20 +00:00
|
|
|
|
{
|
2025-02-24 07:37:13 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Represents a query that is sent to a plugin.
|
|
|
|
|
|
/// </summary>
|
2013-12-19 15:51:20 +00:00
|
|
|
|
public class Query
|
|
|
|
|
|
{
|
2015-01-26 09:46:55 +00:00
|
|
|
|
/// <summary>
|
2025-05-02 04:26:14 +00:00
|
|
|
|
/// Raw query, this includes action keyword if it has.
|
|
|
|
|
|
/// It has handled buildin custom query shortkeys and build-in shortcuts, and it trims the whitespace.
|
2015-01-26 09:46:55 +00:00
|
|
|
|
/// We didn't recommend use this property directly. You should always use Search property.
|
|
|
|
|
|
/// </summary>
|
2021-09-06 17:31:07 +00:00
|
|
|
|
public string RawQuery { get; internal init; }
|
2015-01-26 09:46:55 +00:00
|
|
|
|
|
2023-06-06 09:57:44 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Determines whether the query was forced to execute again.
|
2023-06-07 20:19:47 +00:00
|
|
|
|
/// For example, the value will be true when the user presses Ctrl + R.
|
2023-06-06 09:57:44 +00:00
|
|
|
|
/// When this property is true, plugins handling this query should avoid serving cached results.
|
|
|
|
|
|
/// </summary>
|
2023-06-07 20:19:47 +00:00
|
|
|
|
public bool IsReQuery { get; internal set; } = false;
|
2023-06-06 09:57:44 +00:00
|
|
|
|
|
2025-06-02 03:16:22 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Determines whether the query is a home query.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public bool IsHomeQuery { get; internal init; } = false;
|
|
|
|
|
|
|
2015-01-26 09:46:55 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Search part of a query.
|
2015-02-06 10:13:22 +00:00
|
|
|
|
/// This will not include action keyword if exclusive plugin gets it, otherwise it should be same as RawQuery.
|
2023-06-18 19:29:40 +00:00
|
|
|
|
/// Since we allow user to switch a exclusive plugin to generic plugin,
|
2015-10-31 16:02:56 +00:00
|
|
|
|
/// so this property will always give you the "real" query part of the query
|
2015-01-26 09:46:55 +00:00
|
|
|
|
/// </summary>
|
2021-09-06 17:31:07 +00:00
|
|
|
|
public string Search { get; internal init; }
|
2015-01-26 09:46:55 +00:00
|
|
|
|
|
2015-10-31 16:02:56 +00:00
|
|
|
|
/// <summary>
|
2021-09-07 22:07:21 +00:00
|
|
|
|
/// The search string split into a string array.
|
2023-06-18 19:29:40 +00:00
|
|
|
|
/// Does not include the <see cref="ActionKeyword"/>.
|
2015-10-31 16:02:56 +00:00
|
|
|
|
/// </summary>
|
2021-09-07 22:07:21 +00:00
|
|
|
|
public string[] SearchTerms { get; init; }
|
2021-09-21 02:51:07 +00:00
|
|
|
|
|
2015-11-05 20:44:14 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Query can be splited into multiple terms by whitespace
|
|
|
|
|
|
/// </summary>
|
2021-09-06 17:31:07 +00:00
|
|
|
|
public const string TermSeparator = " ";
|
2021-09-07 22:07:21 +00:00
|
|
|
|
|
2015-11-05 20:44:14 +00:00
|
|
|
|
/// <summary>
|
2025-02-21 04:59:56 +00:00
|
|
|
|
/// User can set multiple action keywords seperated by whitespace
|
2015-11-05 20:44:14 +00:00
|
|
|
|
/// </summary>
|
2025-02-21 04:59:56 +00:00
|
|
|
|
public const string ActionKeywordSeparator = TermSeparator;
|
2015-10-31 16:02:56 +00:00
|
|
|
|
|
2015-11-02 00:09:42 +00:00
|
|
|
|
/// <summary>
|
2023-06-18 19:29:40 +00:00
|
|
|
|
/// Wildcard action keyword. Plugins using this value will be queried on every search.
|
2015-11-02 00:09:42 +00:00
|
|
|
|
/// </summary>
|
2015-11-05 20:44:14 +00:00
|
|
|
|
public const string GlobalPluginWildcardSign = "*";
|
2015-11-02 00:09:42 +00:00
|
|
|
|
|
2023-06-18 19:29:40 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// The action keyword part of this query.
|
|
|
|
|
|
/// For global plugins this value will be empty.
|
|
|
|
|
|
/// </summary>
|
2021-09-06 17:31:07 +00:00
|
|
|
|
public string ActionKeyword { get; init; }
|
2015-01-26 09:46:55 +00:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-06-18 19:29:40 +00:00
|
|
|
|
/// Splits <see cref="SearchTerms"/> by spaces and returns the first item.
|
2015-01-26 09:46:55 +00:00
|
|
|
|
/// </summary>
|
2023-06-18 19:29:40 +00:00
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// returns an empty string when <see cref="SearchTerms"/> does not have enough items.
|
|
|
|
|
|
/// </remarks>
|
2025-02-24 07:37:13 +00:00
|
|
|
|
[JsonIgnore]
|
2015-10-31 16:02:56 +00:00
|
|
|
|
public string FirstSearch => SplitSearch(0);
|
2025-05-02 04:26:14 +00:00
|
|
|
|
|
2022-09-01 02:34:47 +00:00
|
|
|
|
[JsonIgnore]
|
2021-09-06 17:31:07 +00:00
|
|
|
|
private string _secondToEndSearch;
|
2025-05-02 04:26:14 +00:00
|
|
|
|
|
2015-01-26 09:46:55 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// strings from second search (including) to last search
|
|
|
|
|
|
/// </summary>
|
2022-09-01 02:34:47 +00:00
|
|
|
|
[JsonIgnore]
|
2021-10-01 22:04:02 +00:00
|
|
|
|
public string SecondToEndSearch => SearchTerms.Length > 1 ? (_secondToEndSearch ??= string.Join(' ', SearchTerms[1..])) : "";
|
2015-01-26 09:46:55 +00:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-06-18 19:29:40 +00:00
|
|
|
|
/// Splits <see cref="SearchTerms"/> by spaces and returns the second item.
|
2015-01-26 09:46:55 +00:00
|
|
|
|
/// </summary>
|
2023-06-18 19:29:40 +00:00
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// returns an empty string when <see cref="SearchTerms"/> does not have enough items.
|
|
|
|
|
|
/// </remarks>
|
2022-09-01 02:34:47 +00:00
|
|
|
|
[JsonIgnore]
|
2015-10-31 16:02:56 +00:00
|
|
|
|
public string SecondSearch => SplitSearch(1);
|
2015-01-26 09:46:55 +00:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-06-18 19:29:40 +00:00
|
|
|
|
/// Splits <see cref="SearchTerms"/> by spaces and returns the third item.
|
2015-01-26 09:46:55 +00:00
|
|
|
|
/// </summary>
|
2023-06-18 19:29:40 +00:00
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// returns an empty string when <see cref="SearchTerms"/> does not have enough items.
|
|
|
|
|
|
/// </remarks>
|
2022-09-01 02:34:47 +00:00
|
|
|
|
[JsonIgnore]
|
2015-10-31 16:02:56 +00:00
|
|
|
|
public string ThirdSearch => SplitSearch(2);
|
2015-01-26 09:46:55 +00:00
|
|
|
|
|
|
|
|
|
|
private string SplitSearch(int index)
|
|
|
|
|
|
{
|
2021-09-07 22:07:21 +00:00
|
|
|
|
return index < SearchTerms.Length ? SearchTerms[index] : string.Empty;
|
2015-01-26 09:46:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-18 19:29:40 +00:00
|
|
|
|
/// <inheritdoc />
|
2015-10-31 16:02:56 +00:00
|
|
|
|
public override string ToString() => RawQuery;
|
2013-12-19 15:51:20 +00:00
|
|
|
|
}
|
2022-08-08 04:31:38 +00:00
|
|
|
|
}
|