[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

![image](https://github.com/microsoft/PowerToys/assets/24465401/2f9e01d1-1f5a-42b5-9234-f768b27124db)

Using fuzzy match to filter relevant queries

![image](https://github.com/microsoft/PowerToys/assets/24465401/dd0594bb-328a-4a8d-9d7c-e3b5732a8573)

---------

Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com>
This commit is contained in:
Ahmada Yusril
2024-07-23 00:31:32 +09:00
committed by GitHub
parent 16a1fb7981
commit 1b27500231
7 changed files with 477 additions and 6 deletions

View File

@@ -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; },
};
}