add decimal separator check to CanCalculate

This commit is contained in:
Jeremy 2022-04-24 19:33:06 +10:00
parent 4b09e07e09
commit b177f6d67f
2 changed files with 11 additions and 10 deletions

View file

@ -6,7 +6,6 @@ using System.Text.RegularExpressions;
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 @@ namespace Flow.Launcher.Plugin.Caculator
@")+$", 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;
@ -60,7 +62,7 @@ namespace Flow.Launcher.Plugin.Caculator
{
case DecimalSeparator.Comma:
case DecimalSeparator.UseSystemLocale when CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator == ",":
expression = query.Search.Replace(".", ",");
expression = query.Search.Replace(",", ".");
break;
default:
expression = query.Search;
@ -132,6 +134,10 @@ namespace Flow.Launcher.Plugin.Caculator
return false;
}
if ((query.Search.Contains(dot) && GetDecimalSeparator() != dot) ||
(query.Search.Contains(comma) && GetDecimalSeparator() != comma))
return false;
return true;
}
@ -155,8 +161,8 @@ namespace Flow.Launcher.Plugin.Caculator
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;
}
}

View file

@ -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