mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 04:07:40 +02:00
[PTRun][ValueGenerator]Add result entries showing how to use (#33490)
## Summary of the Pull Request Added usage suggestion in PTRun Value Generator. <!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments Added dropdown and give a basic description about the usage of value generator  Using fuzzy match to filter relevant queries  --------- Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com>
This commit is contained in:
@@ -7,8 +7,10 @@ using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using Community.PowerToys.Run.Plugin.ValueGenerator.Helper;
|
||||
using Community.PowerToys.Run.Plugin.ValueGenerator.Properties;
|
||||
using ManagedCommon;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Plugin;
|
||||
using Wox.Plugin.Logger;
|
||||
|
||||
@@ -59,6 +61,19 @@ namespace Community.PowerToys.Run.Plugin.ValueGenerator
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetIcoPath(bool isWarning = false)
|
||||
{
|
||||
var imageName = isWarning ? "Warning" : "ValueGenerator";
|
||||
if (_isLightTheme)
|
||||
{
|
||||
return $"Images/{imageName}.light.png";
|
||||
}
|
||||
else
|
||||
{
|
||||
return $"Images/{imageName}.dark.png";
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!_disposed)
|
||||
@@ -90,6 +105,11 @@ namespace Community.PowerToys.Run.Plugin.ValueGenerator
|
||||
ArgumentNullException.ThrowIfNull(query);
|
||||
|
||||
var results = new List<Result>();
|
||||
if (string.IsNullOrWhiteSpace(query?.Search) && !string.IsNullOrEmpty(query?.ActionKeyword))
|
||||
{
|
||||
return GetSuggestionResults(query, results);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
IComputeRequest computeRequest = _inputParser.ParseInput(query);
|
||||
@@ -110,7 +130,33 @@ namespace Community.PowerToys.Run.Plugin.ValueGenerator
|
||||
}
|
||||
catch (FormatException e)
|
||||
{
|
||||
Log.Debug(GetTranslatedPluginTitle() + ": " + e.Message, GetType());
|
||||
Log.Debug(GetTranslatedPluginTitle() + ": " + e.Message, GetType());
|
||||
if (!string.IsNullOrEmpty(query.ActionKeyword))
|
||||
{
|
||||
return GetSuggestionFuzzyResults(query, results);
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
private List<Result> GetSuggestionResults(Query query, List<Result> results)
|
||||
{
|
||||
foreach (var generatorData in QueryHelper.GeneratorDataList)
|
||||
{
|
||||
results.Add(new Result
|
||||
{
|
||||
Title = QueryHelper.GetResultTitle(generatorData),
|
||||
SubTitle = QueryHelper.GetResultSubtitle(generatorData),
|
||||
IcoPath = GetIcoPath(),
|
||||
ToolTipData = new ToolTipData(QueryHelper.GetResultTitle(generatorData), QueryHelper.GetResultSubtitle(generatorData)),
|
||||
QueryTextDisplay = generatorData.Keyword + " ",
|
||||
Action = c =>
|
||||
{
|
||||
_context.API.ChangeQuery($"{query.ActionKeyword} {generatorData.Keyword} ", true);
|
||||
return false;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return results;
|
||||
@@ -124,7 +170,7 @@ namespace Community.PowerToys.Run.Plugin.ValueGenerator
|
||||
{
|
||||
ContextData = request.Result,
|
||||
Title = request.ResultToString(),
|
||||
IcoPath = _isLightTheme ? "Images/ValueGenerator.light.png" : "Images/ValueGenerator.dark.png",
|
||||
IcoPath = GetIcoPath(),
|
||||
Score = 300,
|
||||
SubTitle = request.Description,
|
||||
Action = c =>
|
||||
@@ -150,13 +196,42 @@ namespace Community.PowerToys.Run.Plugin.ValueGenerator
|
||||
};
|
||||
}
|
||||
|
||||
private List<Result> GetSuggestionFuzzyResults(Query query, List<Result> results)
|
||||
{
|
||||
foreach (var generatorData in QueryHelper.GeneratorDataList)
|
||||
{
|
||||
var matchScore = StringMatcher.FuzzySearch(query.Search.Trim(), generatorData.Keyword).Score;
|
||||
|
||||
if (matchScore > 0)
|
||||
{
|
||||
results.Add(new Result
|
||||
{
|
||||
Title = QueryHelper.GetResultTitle(generatorData),
|
||||
SubTitle = QueryHelper.GetResultSubtitle(generatorData),
|
||||
IcoPath = GetIcoPath(),
|
||||
Score = matchScore,
|
||||
ToolTipData = new ToolTipData(QueryHelper.GetResultTitle(generatorData), QueryHelper.GetResultSubtitle(generatorData)),
|
||||
QueryTextDisplay = generatorData.Keyword + " ",
|
||||
Action = c =>
|
||||
{
|
||||
_context.API.ChangeQuery($"{query.ActionKeyword} {generatorData.Keyword} ", true);
|
||||
return false;
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
private Result GetErrorResult(string errorMessage)
|
||||
{
|
||||
return new Result
|
||||
{
|
||||
Title = Resources.error_title,
|
||||
SubTitle = errorMessage,
|
||||
IcoPath = _isLightTheme ? "Images/Warning.light.png" : "Images/Warning.dark.png",
|
||||
ToolTipData = new ToolTipData(Resources.error_title, errorMessage),
|
||||
IcoPath = GetIcoPath(isWarning: true),
|
||||
Action = _ => { return true; },
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user