diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Calc/Helper/QueryHelper.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Calc/Helper/QueryHelper.cs index df6a8a153d..b6c41f3831 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Calc/Helper/QueryHelper.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Calc/Helper/QueryHelper.cs @@ -63,7 +63,7 @@ public static partial class QueryHelper return ResultHelper.CreateResult(result.RoundedResult, inputCulture, outputCulture, query); } - return ResultHelper.CreateResult(result.RoundedResult, inputCulture, outputCulture, query, handleSave); + return ResultHelper.CreateResult(result.RoundedResult, inputCulture, outputCulture, query, settings, handleSave); } catch (OverflowException) { diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Calc/Helper/ResultHelper.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Calc/Helper/ResultHelper.cs index d22ecc1612..c729086543 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Calc/Helper/ResultHelper.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Calc/Helper/ResultHelper.cs @@ -13,7 +13,7 @@ namespace Microsoft.CmdPal.Ext.Calc.Helper; public static class ResultHelper { - public static ListItem CreateResult(decimal? roundedResult, CultureInfo inputCulture, CultureInfo outputCulture, string query, TypedEventHandler handleSave) + public static ListItem CreateResult(decimal? roundedResult, CultureInfo inputCulture, CultureInfo outputCulture, string query, SettingsManager settings, TypedEventHandler handleSave) { // Return null when the expression is not a valid calculator query. if (roundedResult == null) @@ -32,19 +32,14 @@ public static class ResultHelper // No TextToSuggest on the main save command item. We don't want to keep suggesting what the result is, // as the user is typing it. - return new ListItem(saveCommand) + return new ListItem(settings.CloseOnEnter ? copyCommandItem.Command : saveCommand) { // Using CurrentCulture since this is user facing Icon = Icons.ResultIcon, Title = result, Subtitle = query, MoreCommands = [ - new CommandContextItem(copyCommandItem.Command) - { - Icon = copyCommandItem.Icon, - Title = copyCommandItem.Title, - Subtitle = copyCommandItem.Subtitle, - }, + new CommandContextItem(settings.CloseOnEnter ? saveCommand : copyCommandItem.Command), ..copyCommandItem.MoreCommands, ], }; diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Calc/Helper/SettingsManager.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Calc/Helper/SettingsManager.cs index e106123f5e..cb5104011e 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Calc/Helper/SettingsManager.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Calc/Helper/SettingsManager.cs @@ -39,6 +39,12 @@ public class SettingsManager : JsonSettingsManager Properties.Resources.calculator_settings_out_en_format_description, false); + private readonly ToggleSetting _closeOnEnter = new( + Namespaced(nameof(CloseOnEnter)), + Properties.Resources.calculator_settings_close_on_enter, + Properties.Resources.calculator_settings_close_on_enter_description, + true); + public CalculateEngine.TrigMode TrigUnit { get @@ -73,6 +79,8 @@ public class SettingsManager : JsonSettingsManager public bool OutputUseEnglishFormat => _outputUseEnNumberFormat.Value; + public bool CloseOnEnter => _closeOnEnter.Value; + internal static string SettingsJsonPath() { var directory = Utilities.BaseSettingsPath("Microsoft.CmdPal"); @@ -89,6 +97,7 @@ public class SettingsManager : JsonSettingsManager Settings.Add(_trigUnit); Settings.Add(_inputUseEnNumberFormat); Settings.Add(_outputUseEnNumberFormat); + Settings.Add(_closeOnEnter); // Load settings from file upon initialization LoadSettings(); diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Calc/Properties/Resources.Designer.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Calc/Properties/Resources.Designer.cs index 8759c1209f..328b57ea96 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Calc/Properties/Resources.Designer.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Calc/Properties/Resources.Designer.cs @@ -186,6 +186,24 @@ namespace Microsoft.CmdPal.Ext.Calc.Properties { } } + /// + /// Looks up a localized string similar to Close on Enter. + /// + public static string calculator_settings_close_on_enter { + get { + return ResourceManager.GetString("calculator_settings_close_on_enter", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Makes Copy and close the primary command. + /// + public static string calculator_settings_close_on_enter_description { + get { + return ResourceManager.GetString("calculator_settings_close_on_enter_description", resourceCulture); + } + } + /// /// Looks up a localized string similar to Use English (United States) number format for input. /// diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Calc/Properties/Resources.resx b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Calc/Properties/Resources.resx index dba2ba2067..1da0e6f61e 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Calc/Properties/Resources.resx +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Calc/Properties/Resources.resx @@ -184,6 +184,12 @@ Ignores your system setting and expects numbers in the format '{0}'. {0} is a placeholder and will be replaced in code. + + Close on Enter + + + Makes Copy and close the primary command + Replace input if query ends with '='