From d00bd281e3d270a2e3302b8259374e6b9ab534d6 Mon Sep 17 00:00:00 2001 From: NaroZeol Date: Tue, 1 Oct 2024 21:23:26 +0800 Subject: [PATCH] [PTRun][UnitConverter]Add usage prompt --- .../Main.cs | 28 +++++++++++++++++++ .../Properties/Resources.Designer.cs | 18 ++++++++++++ .../Properties/Resources.resx | 6 ++++ 3 files changed, 52 insertions(+) diff --git a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/Main.cs b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/Main.cs index 1d471420b4..c488c6905d 100644 --- a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/Main.cs +++ b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/Main.cs @@ -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 GetSuggestionResults(Query query) + { + var title = string.Format(CultureInfo.CurrentCulture, UsagePromptTitle, query.ActionKeyword); + var subTitle = string.Format(CultureInfo.CurrentCulture, UsagePromptSubtitle); + List ret = + [ + new Result + { + Title = title, + SubTitle = subTitle, + IcoPath = _icon_path, + Action = c => true, + } + ]; + + return ret; + } + private Result GetResult(UnitConversionResult result) { return new Result diff --git a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/Properties/Resources.Designer.cs b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/Properties/Resources.Designer.cs index 905e4e6fb9..d8a17b3578 100644 --- a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/Properties/Resources.Designer.cs +++ b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/Properties/Resources.Designer.cs @@ -104,5 +104,23 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter.Properties { return ResourceManager.GetString("plugin_name", resourceCulture); } } + + /// + /// Looks up a localized string similar to e.g. 10 ft to m. + /// + public static string usage_prompt_subtitle { + get { + return ResourceManager.GetString("usage_prompt_subtitle", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Usage: {0} [value] [fromUnit] to [toUnit]. + /// + public static string usage_prompt_title { + get { + return ResourceManager.GetString("usage_prompt_title", resourceCulture); + } + } } } diff --git a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/Properties/Resources.resx b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/Properties/Resources.resx index 0dfaceba8f..8e536c7be9 100644 --- a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/Properties/Resources.resx +++ b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/Properties/Resources.resx @@ -132,4 +132,10 @@ Unit Converter + + e.g. 10 ft to m + + + Usage: {0} [value] [fromUnit] to [toUnit] + \ No newline at end of file