[PTRun][UnitConverter]Add usage prompt
This commit is contained in:
Родитель
ccdfbb0f68
Коммит
d00bd281e3
|
@ -30,6 +30,8 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
|
|||
private bool _disposed;
|
||||
|
||||
private static readonly CompositeFormat CopyToClipboard = System.Text.CompositeFormat.Parse(Properties.Resources.copy_to_clipboard);
|
||||
private static readonly CompositeFormat UsagePromptTitle = System.Text.CompositeFormat.Parse(Properties.Resources.usage_prompt_title);
|
||||
private static readonly CompositeFormat UsagePromptSubtitle = System.Text.CompositeFormat.Parse(Properties.Resources.usage_prompt_subtitle);
|
||||
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
|
@ -44,6 +46,14 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
|
|||
{
|
||||
ArgumentNullException.ThrowIfNull(query);
|
||||
|
||||
bool isKeywordSearch = !string.IsNullOrEmpty(query.ActionKeyword);
|
||||
bool isEmptySearch = string.IsNullOrEmpty(query.Search);
|
||||
|
||||
if (isEmptySearch && isKeywordSearch)
|
||||
{
|
||||
return GetSuggestionResults(query);
|
||||
}
|
||||
|
||||
// Parse
|
||||
ConvertModel convertModel = InputInterpreter.Parse(query);
|
||||
if (convertModel == null)
|
||||
|
@ -56,6 +66,24 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
|
|||
.ToList();
|
||||
}
|
||||
|
||||
private List<Result> GetSuggestionResults(Query query)
|
||||
{
|
||||
var title = string.Format(CultureInfo.CurrentCulture, UsagePromptTitle, query.ActionKeyword);
|
||||
var subTitle = string.Format(CultureInfo.CurrentCulture, UsagePromptSubtitle);
|
||||
List<Result> ret =
|
||||
[
|
||||
new Result
|
||||
{
|
||||
Title = title,
|
||||
SubTitle = subTitle,
|
||||
IcoPath = _icon_path,
|
||||
Action = c => true,
|
||||
}
|
||||
];
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private Result GetResult(UnitConversionResult result)
|
||||
{
|
||||
return new Result
|
||||
|
|
|
@ -104,5 +104,23 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter.Properties {
|
|||
return ResourceManager.GetString("plugin_name", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to e.g. 10 ft to m.
|
||||
/// </summary>
|
||||
public static string usage_prompt_subtitle {
|
||||
get {
|
||||
return ResourceManager.GetString("usage_prompt_subtitle", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Usage: {0} [value] [fromUnit] to [toUnit].
|
||||
/// </summary>
|
||||
public static string usage_prompt_title {
|
||||
get {
|
||||
return ResourceManager.GetString("usage_prompt_title", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -132,4 +132,10 @@
|
|||
<data name="plugin_name" xml:space="preserve">
|
||||
<value>Unit Converter</value>
|
||||
</data>
|
||||
<data name="usage_prompt_subtitle" xml:space="preserve">
|
||||
<value>e.g. 10 ft to m</value>
|
||||
</data>
|
||||
<data name="usage_prompt_title" xml:space="preserve">
|
||||
<value>Usage: {0} [value] [fromUnit] to [toUnit]</value>
|
||||
</data>
|
||||
</root>
|
Загрузка…
Ссылка в новой задаче