PowerToys/Wox.Plugin/Query.cs

89 lines
2.9 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
2015-11-01 00:02:56 +08:00
using System.Linq;
2013-12-19 23:51:20 +08:00
2014-01-29 18:33:24 +08:00
namespace Wox.Plugin
2013-12-19 23:51:20 +08:00
{
public class Query
{
/// <summary>
/// Raw query, this includes action keyword if it has
/// We didn't recommend use this property directly. You should always use Search property.
/// </summary>
2015-11-03 13:09:54 +08:00
public string RawQuery { get; internal set; }
/// <summary>
/// Search part of a query.
2015-02-06 18:13:22 +08:00
/// This will not include action keyword if exclusive plugin gets it, otherwise it should be same as RawQuery.
2015-11-01 00:02:56 +08:00
/// 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
/// </summary>
public string Search { get; internal set; }
2015-11-01 00:02:56 +08:00
/// <summary>
/// The raw query splited into a string array.
/// </summary>
2015-11-03 13:09:54 +08:00
internal string[] Terms { private get; set; }
2015-11-01 00:02:56 +08:00
public const string Seperater = " ";
2015-11-02 08:09:42 +08:00
/// <summary>
/// * is used for System Plugin
/// </summary>
public const string WildcardSign = "*";
2015-11-01 00:02:56 +08:00
internal string ActionKeyword { get; set; }
/// <summary>
/// Return first search split by space if it has
/// </summary>
2015-11-01 00:02:56 +08:00
public string FirstSearch => SplitSearch(0);
/// <summary>
/// strings from second search (including) to last search
/// </summary>
public string SecondToEndSearch
{
get
{
var index = String.IsNullOrEmpty(ActionKeyword) ? 1 : 2;
return String.Join(Seperater, Terms.Skip(index).ToArray());
}
}
/// <summary>
/// Return second search split by space if it has
/// </summary>
2015-11-01 00:02:56 +08:00
public string SecondSearch => SplitSearch(1);
/// <summary>
/// Return third search split by space if it has
/// </summary>
2015-11-01 00:02:56 +08:00
public string ThirdSearch => SplitSearch(2);
private string SplitSearch(int index)
{
2015-11-01 00:02:56 +08:00
try
{
return String.IsNullOrEmpty(ActionKeyword) ? Terms[index] : Terms[index + 1];
2015-11-01 00:02:56 +08:00
}
catch (IndexOutOfRangeException)
{
return String.Empty;
}
}
2015-11-01 00:02:56 +08:00
public override string ToString() => RawQuery;
[Obsolete("Use Search instead, A plugin developer shouldn't care about action name, as it may changed by users. " +
"this property will be removed in v1.3.0")]
2015-11-03 13:09:54 +08:00
public string ActionName { get; internal set; }
[Obsolete("Use Search instead, this property will be removed in v1.3.0")]
2015-11-03 13:09:54 +08:00
public List<string> ActionParameters { get; internal set; }
2014-02-28 23:21:01 +08:00
[Obsolete("Use Search instead, this method will be removed in v1.3.0")]
2015-11-03 13:09:54 +08:00
public string GetAllRemainingParameter() => Search;
2013-12-19 23:51:20 +08:00
}
}