mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
* Added CultureInfo (CA1307: Specify StringComparison for clarity / CA1304: Specify CultureInfo) * Check arguments and throw ArgumentNullException (CA1062: Validate arguments of public methods) * Changed url parameter from string to System.Uri and added null checks (CA1054: URI parameters should not be strings) * Rethrow exception without specifying the exception explicitly (CA2200: Rethrow to preserve stack details) * Changed from Collection property to methods for PluginMetadata::ActionKeywords (CA2227: Collection properties should be read only) * Changed from Collection property to methods for Result::GetTitleHighlightData (CA2227: Collection properties should be read only) * Made Collection property read-only and added parameter in constructor for Result::SubTitleHighlightData (CA2227: Collection properties should be read only) * Made Collection property read only and added parameter in constructor for ResultUpdatedEventArgs::Results (CA2227: Collection properties should be read only) * CA1507: Use nameof in place of string * Removed initialization for ThemeManager::_disposed (CA1805: Do not initialize unnecessarily) * Changed Query::Terms array property to ReadOnlyCollection and added private set (CA1819: Properties should not return arrays) * CA1060: Move P/Invokes to NativeMethods class * CA1806: Do not ignore method results * CA2101: Specify marshaling for P/Invoke string arguments * Removed unnecessary empty interface IFeatures (CA1040: Avoid empty interfaces) - Removed IFeatures interface and references - Renamed IFeatures.cs to IContextMenu.cs according to guidelines * Added comments for CultureInfo (CA1307: Specify StringComparison for clarity / CA1304: Specify CultureInfo) * Added localization for Wox.Plugin and localized strings in FilesFolders.cs
111 lines
3.5 KiB
C#
111 lines
3.5 KiB
C#
// Copyright (c) Microsoft Corporation
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Mono.Collections.Generic;
|
|
|
|
namespace Wox.Plugin
|
|
{
|
|
public class Query
|
|
{
|
|
internal Query()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="Query"/> class.
|
|
/// to allow unit tests for plug ins
|
|
/// </summary>
|
|
public Query(string rawQuery, string search, ReadOnlyCollection<string> terms, string actionKeyword = "")
|
|
{
|
|
Search = search;
|
|
RawQuery = rawQuery;
|
|
Terms = terms;
|
|
ActionKeyword = actionKeyword;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets 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>
|
|
/// Gets search part of a query.
|
|
/// This will not include action keyword if exclusive plugin gets it, otherwise it should be same as RawQuery.
|
|
/// 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; }
|
|
|
|
/// <summary>
|
|
/// Gets the raw query splited into a string array.
|
|
/// </summary>
|
|
public ReadOnlyCollection<string> Terms { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Query can be splited into multiple terms by whitespace
|
|
/// </summary>
|
|
public const string TermSeparator = " ";
|
|
|
|
/// <summary>
|
|
/// User can set multiple action keywords separated by ';'
|
|
/// </summary>
|
|
public const string ActionKeywordSeparator = ";";
|
|
|
|
/// <summary>
|
|
/// '*' is used for System Plugin
|
|
/// </summary>
|
|
public const string GlobalPluginWildcardSign = "*";
|
|
|
|
public string ActionKeyword { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets return first search split by space if it has
|
|
/// </summary>
|
|
public string FirstSearch => SplitSearch(0);
|
|
|
|
/// <summary>
|
|
/// Gets strings from second search (including) to last search
|
|
/// </summary>
|
|
public string SecondToEndSearch
|
|
{
|
|
get
|
|
{
|
|
var index = string.IsNullOrEmpty(ActionKeyword) ? 1 : 2;
|
|
return string.Join(TermSeparator, Terms.Skip(index).ToArray());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets return second search split by space if it has
|
|
/// </summary>
|
|
public string SecondSearch => SplitSearch(1);
|
|
|
|
/// <summary>
|
|
/// Gets return third search split by space if it has
|
|
/// </summary>
|
|
public string ThirdSearch => SplitSearch(2);
|
|
|
|
private string SplitSearch(int index)
|
|
{
|
|
try
|
|
{
|
|
return string.IsNullOrEmpty(ActionKeyword) ? Terms[index] : Terms[index + 1];
|
|
}
|
|
catch (IndexOutOfRangeException)
|
|
{
|
|
return string.Empty;
|
|
}
|
|
}
|
|
|
|
public override string ToString() => RawQuery;
|
|
|
|
[Obsolete("Use Search instead, this method will be removed in v1.3.0")]
|
|
public string GetAllRemainingParameter() => Search;
|
|
}
|
|
}
|