mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 10:46:33 +02:00
* [Analyzers][AdvancedPaste] Apply fix for SA1516 * [Analyzers][EnvironmentVariables] Apply fix for SA1516 * [Analyzers][RegistryPreview] Apply fix for SA1516 * [Analyzers][Peek] Apply fix for SA1516 * [Analyzers][PreviewPane] Apply fix for SA1516 * [Analyzers][FancyZones] Apply fix for SA1516 * [Analyzers][PT Run][Plugins] Apply fix for SA1516 * [Analyzers][PT Run] Apply fix for SA1516 * [Analyzers][PT Run][Wox] Apply fix for SA1516 * [Analyzers][Common] Apply fix for SA1516 * [Analyzers][ImageResizer] Apply fix for SA1516 * [Analyzers][ColorPicker] Apply fix for SA1516 * [Analyzers][MouseUtils] Apply fix for SA1516 * [Analyzers][DSC Schema Generator] Apply fix for SA1516 * [Analyzers][FileLocksmith] Apply fix for SA1516 * [Analyzers][Hosts] Apply fix for SA1516 * [Analyzers][MeasureTool] Apply fix for SA1516 * [Analyzers][MouseWithoutBorders] Apply fix for SA1516 * [Analyzers][TextExtractor] Apply fix for SA1516 * [Analyzers][Workspaces] Apply fix for SA1516 * [Analyzers][Awake] Apply fix for SA1516 * [Analyzers][PowerAccent] Apply fix for SA1516 * [Analyzers][RegistryPreview] Apply fix for SA1516 * [Analyzers][Settings] Apply fix for SA1516 * [Analyzers][MouseWithoutBorders] Apply fix for SA1616
70 lines
2.6 KiB
C#
70 lines
2.6 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 Wox.Plugin;
|
|
|
|
namespace PowerLauncher.Plugin
|
|
{
|
|
public static class QueryBuilder
|
|
{
|
|
public static Dictionary<PluginPair, Query> Build(string text)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(text);
|
|
|
|
text = text.Trim();
|
|
int longestActionKeywordLength = 0;
|
|
|
|
// This Dictionary contains the corresponding query for each plugin
|
|
Dictionary<PluginPair, Query> pluginQueryPair = new Dictionary<PluginPair, Query>();
|
|
foreach (var nonGlobalPlugin in PluginManager.NonGlobalPlugins)
|
|
{
|
|
var pluginActionKeyword = nonGlobalPlugin.Metadata.ActionKeyword;
|
|
if (nonGlobalPlugin.Metadata.Disabled || !text.StartsWith(pluginActionKeyword, StringComparison.Ordinal))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
// Save the length of the longest matching keyword for later use
|
|
if (pluginActionKeyword.Length > longestActionKeywordLength)
|
|
{
|
|
longestActionKeywordLength = pluginActionKeyword.Length;
|
|
}
|
|
|
|
// A new query is constructed for each plugin
|
|
var query = new Query(text, pluginActionKeyword);
|
|
pluginQueryPair.TryAdd(nonGlobalPlugin, query);
|
|
}
|
|
|
|
// If we have plugin action keywords that start with the same char we get false positives (Example: ? and ??)
|
|
// Here we remove each query pair that has a shorter keyword than the longest matching one
|
|
foreach (PluginPair plugin in pluginQueryPair.Keys)
|
|
{
|
|
if (plugin.Metadata.ActionKeyword.Length < longestActionKeywordLength)
|
|
{
|
|
pluginQueryPair.Remove(plugin);
|
|
}
|
|
}
|
|
|
|
// If the user has specified a matching action keyword, then do not
|
|
// add the global plugins to the list.
|
|
if (pluginQueryPair.Count == 0)
|
|
{
|
|
foreach (PluginPair globalPlugin in PluginManager.GlobalPlugins)
|
|
{
|
|
if (!globalPlugin.Metadata.Disabled && !pluginQueryPair.ContainsKey(globalPlugin))
|
|
{
|
|
var query = new Query(text);
|
|
pluginQueryPair.Add(globalPlugin, query);
|
|
}
|
|
}
|
|
}
|
|
|
|
return pluginQueryPair;
|
|
}
|
|
}
|
|
}
|