Refactoring Query initialisation

This commit is contained in:
bao-qian
2015-11-03 05:09:54 +00:00
parent f5d3df65b0
commit 288ac62448
4 changed files with 36 additions and 66 deletions

View File

@@ -10,7 +10,7 @@ namespace Wox.Plugin
/// 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; }
public string RawQuery { get; internal set; }
/// <summary>
/// Search part of a query.
@@ -23,7 +23,7 @@ namespace Wox.Plugin
/// <summary>
/// The raw query splited into a string array.
/// </summary>
public string[] Terms { get; }
internal string[] Terms { private get; set; }
public const string Seperater = " ";
@@ -77,52 +77,12 @@ namespace Wox.Plugin
[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")]
public string ActionName { get; private set; }
public string ActionName { get; internal set; }
[Obsolete("Use Search instead, this property will be removed in v1.3.0")]
public List<string> ActionParameters { get; private set; }
public Query(string rawQuery)
{
// replace multiple white spaces with one white space
Terms = rawQuery.Split(new[] { Seperater }, StringSplitOptions.RemoveEmptyEntries);
RawQuery = String.Join(Seperater, Terms.ToArray());
ActionParameters = new List<string>();
ParseQuery();
}
private void ParseQuery()
{
if (String.IsNullOrEmpty(RawQuery)) return;
string[] strings = RawQuery.Split(' ');
//todo:not exactly correct. query that didn't containing a space should be a valid query
if (strings.Length == 1) return; //we consider a valid query must contain a space
ActionName = strings[0];
for (int i = 1; i < strings.Length; i++)
{
if (!String.IsNullOrEmpty(strings[i]))
{
ActionParameters.Add(strings[i]);
}
}
}
public List<string> ActionParameters { get; internal set; }
[Obsolete("Use Search instead, this method will be removed in v1.3.0")]
public string GetAllRemainingParameter()
{
string[] strings = RawQuery.Split(new char[] { ' ' }, 2, StringSplitOptions.None);
if (strings.Length > 1)
{
return strings[1];
}
return String.Empty;
}
public string GetAllRemainingParameter() => Search;
}
}