mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #1108 from Flow-Launcher/CalculatorDecimalSeparator
Respect Decimal Separator for query not just result
This commit is contained in:
commit
dffbd35dbd
3 changed files with 26 additions and 12 deletions
|
|
@ -6,7 +6,6 @@ using System.Text.RegularExpressions;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using Mages.Core;
|
using Mages.Core;
|
||||||
using Flow.Launcher.Infrastructure.Storage;
|
|
||||||
using Flow.Launcher.Plugin.Caculator.ViewModels;
|
using Flow.Launcher.Plugin.Caculator.ViewModels;
|
||||||
using Flow.Launcher.Plugin.Caculator.Views;
|
using Flow.Launcher.Plugin.Caculator.Views;
|
||||||
|
|
||||||
|
|
@ -25,6 +24,9 @@ namespace Flow.Launcher.Plugin.Caculator
|
||||||
@")+$", RegexOptions.Compiled);
|
@")+$", RegexOptions.Compiled);
|
||||||
private static readonly Regex RegBrackets = new Regex(@"[\(\)\[\]]", RegexOptions.Compiled);
|
private static readonly Regex RegBrackets = new Regex(@"[\(\)\[\]]", RegexOptions.Compiled);
|
||||||
private static Engine MagesEngine;
|
private static Engine MagesEngine;
|
||||||
|
private const string comma = ",";
|
||||||
|
private const string dot = ".";
|
||||||
|
|
||||||
private PluginInitContext Context { get; set; }
|
private PluginInitContext Context { get; set; }
|
||||||
|
|
||||||
private static Settings _settings;
|
private static Settings _settings;
|
||||||
|
|
@ -35,7 +37,7 @@ namespace Flow.Launcher.Plugin.Caculator
|
||||||
Context = context;
|
Context = context;
|
||||||
_settings = context.API.LoadSettingJsonStorage<Settings>();
|
_settings = context.API.LoadSettingJsonStorage<Settings>();
|
||||||
_viewModel = new SettingsViewModel(_settings);
|
_viewModel = new SettingsViewModel(_settings);
|
||||||
|
|
||||||
MagesEngine = new Engine(new Configuration
|
MagesEngine = new Engine(new Configuration
|
||||||
{
|
{
|
||||||
Scope = new Dictionary<string, object>
|
Scope = new Dictionary<string, object>
|
||||||
|
|
@ -54,7 +56,19 @@ namespace Flow.Launcher.Plugin.Caculator
|
||||||
|
|
||||||
try
|
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);
|
var result = MagesEngine.Interpret(expression);
|
||||||
|
|
||||||
if (result?.ToString() == "NaN")
|
if (result?.ToString() == "NaN")
|
||||||
|
|
@ -76,6 +90,7 @@ namespace Flow.Launcher.Plugin.Caculator
|
||||||
IcoPath = "Images/calculator.png",
|
IcoPath = "Images/calculator.png",
|
||||||
Score = 300,
|
Score = 300,
|
||||||
SubTitle = Context.API.GetTranslation("flowlauncher_plugin_calculator_copy_number_to_clipboard"),
|
SubTitle = Context.API.GetTranslation("flowlauncher_plugin_calculator_copy_number_to_clipboard"),
|
||||||
|
CopyText = newResult,
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
@ -119,6 +134,10 @@ namespace Flow.Launcher.Plugin.Caculator
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((query.Search.Contains(dot) && GetDecimalSeparator() != dot) ||
|
||||||
|
(query.Search.Contains(comma) && GetDecimalSeparator() != comma))
|
||||||
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -142,8 +161,8 @@ namespace Flow.Launcher.Plugin.Caculator
|
||||||
switch (_settings.DecimalSeparator)
|
switch (_settings.DecimalSeparator)
|
||||||
{
|
{
|
||||||
case DecimalSeparator.UseSystemLocale: return systemDecimalSeperator;
|
case DecimalSeparator.UseSystemLocale: return systemDecimalSeperator;
|
||||||
case DecimalSeparator.Dot: return ".";
|
case DecimalSeparator.Dot: return dot;
|
||||||
case DecimalSeparator.Comma: return ",";
|
case DecimalSeparator.Comma: return comma;
|
||||||
default: return systemDecimalSeperator;
|
default: return systemDecimalSeperator;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
namespace Flow.Launcher.Plugin.Caculator
|
||||||
{
|
{
|
||||||
public class Settings
|
public class Settings
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
"Name": "Calculator",
|
"Name": "Calculator",
|
||||||
"Description": "Provide mathematical calculations.(Try 5*3-2 in Flow Launcher)",
|
"Description": "Provide mathematical calculations.(Try 5*3-2 in Flow Launcher)",
|
||||||
"Author": "cxfksword",
|
"Author": "cxfksword",
|
||||||
"Version": "1.1.9",
|
"Version": "1.1.10",
|
||||||
"Language": "csharp",
|
"Language": "csharp",
|
||||||
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
|
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
|
||||||
"ExecuteFileName": "Flow.Launcher.Plugin.Caculator.dll",
|
"ExecuteFileName": "Flow.Launcher.Plugin.Caculator.dll",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue