Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PTRun][UnitConverter]Add usage prompt #35168

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class Main : IPlugin, IPluginI18n, IContextMenu, IDisposable
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)
{
Expand All @@ -44,6 +46,14 @@ public List<Result> Query(Query query)
{
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)
Expand All @@ -56,6 +66,24 @@ public List<Result> Query(Query query)
.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
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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>
Loading