diff --git a/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs b/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs index 7de4d30fef5..ea278b49bfe 100644 --- a/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs @@ -6,7 +6,6 @@ using System.Windows; using System.Windows.Controls; using Mages.Core; -using Flow.Launcher.Infrastructure.Storage; using Flow.Launcher.Plugin.Caculator.ViewModels; using Flow.Launcher.Plugin.Caculator.Views; @@ -25,6 +24,9 @@ public class Main : IPlugin, IPluginI18n, ISettingProvider @")+$", RegexOptions.Compiled); private static readonly Regex RegBrackets = new Regex(@"[\(\)\[\]]", RegexOptions.Compiled); private static Engine MagesEngine; + private const string comma = ","; + private const string dot = "."; + private PluginInitContext Context { get; set; } private static Settings _settings; @@ -35,7 +37,7 @@ public void Init(PluginInitContext context) Context = context; _settings = context.API.LoadSettingJsonStorage(); _viewModel = new SettingsViewModel(_settings); - + MagesEngine = new Engine(new Configuration { Scope = new Dictionary @@ -54,7 +56,19 @@ public List Query(Query query) try { - var expression = query.Search.Replace(",", "."); + string expression; + + switch (_settings.DecimalSeparator) + { + case DecimalSeparator.Comma: + case DecimalSeparator.UseSystemLocale when CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator == ",": + expression = query.Search.Replace(",", "."); + break; + default: + expression = query.Search; + break; + } + var result = MagesEngine.Interpret(expression); if (result?.ToString() == "NaN") @@ -76,6 +90,7 @@ public List Query(Query query) IcoPath = "Images/calculator.png", Score = 300, SubTitle = Context.API.GetTranslation("flowlauncher_plugin_calculator_copy_number_to_clipboard"), + CopyText = newResult, Action = c => { try @@ -119,6 +134,10 @@ private bool CanCalculate(Query query) return false; } + if ((query.Search.Contains(dot) && GetDecimalSeparator() != dot) || + (query.Search.Contains(comma) && GetDecimalSeparator() != comma)) + return false; + return true; } @@ -142,8 +161,8 @@ private string GetDecimalSeparator() switch (_settings.DecimalSeparator) { case DecimalSeparator.UseSystemLocale: return systemDecimalSeperator; - case DecimalSeparator.Dot: return "."; - case DecimalSeparator.Comma: return ","; + case DecimalSeparator.Dot: return dot; + case DecimalSeparator.Comma: return comma; default: return systemDecimalSeperator; } } diff --git a/Plugins/Flow.Launcher.Plugin.Calculator/Settings.cs b/Plugins/Flow.Launcher.Plugin.Calculator/Settings.cs index 10cee364b08..61551487381 100644 --- a/Plugins/Flow.Launcher.Plugin.Calculator/Settings.cs +++ b/Plugins/Flow.Launcher.Plugin.Calculator/Settings.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - + namespace Flow.Launcher.Plugin.Caculator { public class Settings diff --git a/Plugins/Flow.Launcher.Plugin.Calculator/plugin.json b/Plugins/Flow.Launcher.Plugin.Calculator/plugin.json index 0b09218681f..771babb90fe 100644 --- a/Plugins/Flow.Launcher.Plugin.Calculator/plugin.json +++ b/Plugins/Flow.Launcher.Plugin.Calculator/plugin.json @@ -4,7 +4,7 @@ "Name": "Calculator", "Description": "Provide mathematical calculations.(Try 5*3-2 in Flow Launcher)", "Author": "cxfksword", - "Version": "1.1.9", + "Version": "1.1.10", "Language": "csharp", "Website": "https://github.com/Flow-Launcher/Flow.Launcher", "ExecuteFileName": "Flow.Launcher.Plugin.Caculator.dll",