2015-01-26 17:46:55 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
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
|
|
|
|
|
{
|
2015-01-26 17:46:55 +08:00
|
|
|
|
/// <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>
|
|
|
|
|
public string RawQuery { get; internal set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Search part of a query.
|
|
|
|
|
/// This will not include action keyword if regular plugin gets it, and if a system plugin gets it, it should be same as RawQuery.
|
|
|
|
|
/// Since we allow user to switch a regular plugin to system plugin, so this property will always give you the "real" query part of
|
|
|
|
|
/// the query
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string Search { get; internal set; }
|
|
|
|
|
|
|
|
|
|
internal string GetActionKeyword()
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(RawQuery))
|
|
|
|
|
{
|
|
|
|
|
var strings = RawQuery.Split(' ');
|
|
|
|
|
if (strings.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
return strings[0];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Return first search split by space if it has
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string FirstSearch
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return SplitSearch(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// strings from second search (including) to last search
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string SecondToEndSearch
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(Search)) return string.Empty;
|
|
|
|
|
|
|
|
|
|
var strings = Search.Split(' ');
|
|
|
|
|
if (strings.Length > 1)
|
|
|
|
|
{
|
|
|
|
|
return Search.Substring(Search.IndexOf(' ') + 1);
|
|
|
|
|
}
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Return second search split by space if it has
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string SecondSearch
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return SplitSearch(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Return third search split by space if it has
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string ThirdSearch
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return SplitSearch(2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string SplitSearch(int index)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(Search)) return string.Empty;
|
|
|
|
|
|
|
|
|
|
var strings = Search.Split(' ');
|
|
|
|
|
if (strings.Length > index)
|
|
|
|
|
{
|
|
|
|
|
return strings[index];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return 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")]
|
2013-12-19 23:51:20 +08:00
|
|
|
|
public string ActionName { get; private set; }
|
2015-01-26 17:46:55 +08:00
|
|
|
|
|
|
|
|
|
[Obsolete("Use Search instead, this property will be removed in v1.3.0")]
|
2013-12-19 23:51:20 +08:00
|
|
|
|
public List<string> ActionParameters { get; private set; }
|
|
|
|
|
|
|
|
|
|
public Query(string rawQuery)
|
|
|
|
|
{
|
|
|
|
|
RawQuery = rawQuery;
|
2013-12-20 19:38:10 +08:00
|
|
|
|
ActionParameters = new List<string>();
|
2013-12-19 23:51:20 +08:00
|
|
|
|
ParseQuery();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ParseQuery()
|
|
|
|
|
{
|
2013-12-20 19:38:10 +08:00
|
|
|
|
if (string.IsNullOrEmpty(RawQuery)) return;
|
|
|
|
|
|
|
|
|
|
string[] strings = RawQuery.Split(' ');
|
2014-02-28 23:21:01 +08:00
|
|
|
|
//todo:not exactly correct. query that didn't containing a space should be a valid query
|
2013-12-22 00:44:56 +08:00
|
|
|
|
if (strings.Length == 1) return; //we consider a valid query must contain a space
|
|
|
|
|
|
2013-12-20 19:38:10 +08:00
|
|
|
|
ActionName = strings[0];
|
2013-12-22 00:44:56 +08:00
|
|
|
|
for (int i = 1; i < strings.Length; i++)
|
2013-12-20 19:38:10 +08:00
|
|
|
|
{
|
2013-12-22 00:44:56 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(strings[i]))
|
2013-12-20 19:38:10 +08:00
|
|
|
|
{
|
|
|
|
|
ActionParameters.Add(strings[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-19 23:51:20 +08:00
|
|
|
|
}
|
2014-02-28 23:21:01 +08:00
|
|
|
|
|
2015-01-26 17:46:55 +08:00
|
|
|
|
[Obsolete("Use Search instead, this method will be removed in v1.3.0")]
|
2014-02-28 23:21:01 +08:00
|
|
|
|
public string GetAllRemainingParameter()
|
|
|
|
|
{
|
2014-03-17 01:53:51 +08:00
|
|
|
|
|
2015-01-26 17:46:55 +08:00
|
|
|
|
string[] strings = RawQuery.Split(new char[] { ' ' }, 2, System.StringSplitOptions.None);
|
2014-02-28 23:21:01 +08:00
|
|
|
|
if (strings.Length > 1)
|
|
|
|
|
{
|
2014-03-17 01:53:51 +08:00
|
|
|
|
return strings[1];
|
2014-02-28 23:21:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
2013-12-19 23:51:20 +08:00
|
|
|
|
}
|
|
|
|
|
}
|