mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-22 22:50:03 +01:00
* Add hashing plugin for Run * Cleanup logic for hasher plugin - The IComputeRequest interface should make it easier to implement new generators in the future - The GUID generator can now generate all versions of GUID (a.k.a. UUID) - The input for the hash functions is not quite right. The Wox.Plugin.Query class doesn't actually have a way to ge the raw query as given by the user. The issue is with multiple spaces. An input like "a a a a a" would only be accessible as "a a a a a" using the Query class. So for now, hashing only works correctly if the input doesn't contain multiple consecutive spaces. - Need a way to make clear the usage for generating GUIDv3 and v5, since they take 2 parameters. There are defaults, but they aren't very clear. * Change plugin name to ValueGenerator * Clean up error handling for the input parser * Add result type and description to subtitle * Change the icons * Add Base64 encoding and unit tests This commit adds Base64 encoding as a utility of the value generator plugin. The command is `# base64 ***input***`. Also added unit tests for the UUID/GUID generator and for the input parser. I don't think tests are necessary for the hashing functions or for the base64 encoder, since those were part of the the system libraries. I'll open a PR for the documentation tomorrow and mark this draft for review. * Excluded UUIDv2 * Change icons * Add RawUserQuery to Wox.Plugin.Query Getting the RawUserQuery is necessary to be able to handle queries like `# md5 a a`, where the intent is to get the hash for `a a`. The existing `RawQuery` removes consecutive whitespaces and there was no other way of getting the request as entered by the user. * Add ValueGenerator plugin to installer Also add the unit tests for the plugin to the pipeline. * Small cleanup * Fix spelling * Fix spelling again * Spell check for guiddata * More fixes This commit adds the dev docs explaining the classes in the new plugin. It also fixes the following issues: 1. ValueGenerator was not a dependency for the PowerLauncher project 2. The error message for an invalid SHA variant now displays the supported SHA variants 3. Hash requests now wait for a string to hash (i.e. no longer hash an empty string) 4. GUID v3 and v5 namespace aliases allow lowercase notation 5. Unnecessary debug logs 6. An empty query will now just log "Empty request" 7. An invalid query will also log user query * Spell check fix again * Change error message for unsupported GUID versions * Remove Any CPU from the solution * Add to installer * Remove duplicated ValueGeneratorPluginFolder entry
171 lines
4.9 KiB
C#
171 lines
4.9 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.Collections.ObjectModel;
|
|
using System.Linq;
|
|
|
|
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 query, string actionKeyword = "")
|
|
{
|
|
_query = query;
|
|
ActionKeyword = actionKeyword;
|
|
}
|
|
|
|
private string _rawQuery;
|
|
|
|
/// <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
|
|
{
|
|
if (_rawQuery == null)
|
|
{
|
|
_rawQuery = string.Join(Query.TermSeparator, _query.Split(new[] { TermSeparator }, StringSplitOptions.RemoveEmptyEntries));
|
|
}
|
|
|
|
return _rawQuery;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the query as entered by the user.
|
|
/// You should only use this property if you need to process the raw text directly.
|
|
/// </summary>
|
|
public string RawUserQuery
|
|
{
|
|
get
|
|
{
|
|
return _query;
|
|
}
|
|
}
|
|
|
|
private string _search;
|
|
|
|
/// <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
|
|
{
|
|
if (_search == null)
|
|
{
|
|
_search = RawQuery.Substring(ActionKeyword?.Length ?? 0).Trim();
|
|
}
|
|
|
|
return _search;
|
|
}
|
|
}
|
|
|
|
private ReadOnlyCollection<string> _terms;
|
|
|
|
/// <summary>
|
|
/// Gets the raw query split into a string array.
|
|
/// </summary>
|
|
public ReadOnlyCollection<string> Terms
|
|
{
|
|
get
|
|
{
|
|
if (_terms == null)
|
|
{
|
|
var terms = _query
|
|
.Trim()
|
|
.Substring(ActionKeyword.Length)
|
|
.Split(new[] { TermSeparator }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
_terms = new ReadOnlyCollection<string>(terms);
|
|
}
|
|
|
|
return _terms;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Query can be split 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 int WeightBoost { get; set; }
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
private string _query;
|
|
|
|
public override string ToString() => RawQuery;
|
|
|
|
public Dictionary<string, UserSelectedRecord.UserSelectedRecordItem> SelectedItems { get; set; }
|
|
|
|
[Obsolete("Use Search instead, this method will be removed in v1.3.0")]
|
|
public string GetAllRemainingParameter() => Search;
|
|
}
|
|
}
|