Skip to content

Commit b177f6d

Browse files
committed
add decimal separator check to CanCalculate
1 parent 4b09e07 commit b177f6d

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

Plugins/Flow.Launcher.Plugin.Calculator/Main.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Windows;
77
using System.Windows.Controls;
88
using Mages.Core;
9-
using Flow.Launcher.Infrastructure.Storage;
109
using Flow.Launcher.Plugin.Caculator.ViewModels;
1110
using Flow.Launcher.Plugin.Caculator.Views;
1211

@@ -25,6 +24,9 @@ public class Main : IPlugin, IPluginI18n, ISettingProvider
2524
@")+$", RegexOptions.Compiled);
2625
private static readonly Regex RegBrackets = new Regex(@"[\(\)\[\]]", RegexOptions.Compiled);
2726
private static Engine MagesEngine;
27+
private const string comma = ",";
28+
private const string dot = ".";
29+
2830
private PluginInitContext Context { get; set; }
2931

3032
private static Settings _settings;
@@ -60,7 +62,7 @@ public List<Result> Query(Query query)
6062
{
6163
case DecimalSeparator.Comma:
6264
case DecimalSeparator.UseSystemLocale when CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator == ",":
63-
expression = query.Search.Replace(".", ",");
65+
expression = query.Search.Replace(",", ".");
6466
break;
6567
default:
6668
expression = query.Search;
@@ -132,6 +134,10 @@ private bool CanCalculate(Query query)
132134
return false;
133135
}
134136

137+
if ((query.Search.Contains(dot) && GetDecimalSeparator() != dot) ||
138+
(query.Search.Contains(comma) && GetDecimalSeparator() != comma))
139+
return false;
140+
135141
return true;
136142
}
137143

@@ -155,8 +161,8 @@ private string GetDecimalSeparator()
155161
switch (_settings.DecimalSeparator)
156162
{
157163
case DecimalSeparator.UseSystemLocale: return systemDecimalSeperator;
158-
case DecimalSeparator.Dot: return ".";
159-
case DecimalSeparator.Comma: return ",";
164+
case DecimalSeparator.Dot: return dot;
165+
case DecimalSeparator.Comma: return comma;
160166
default: return systemDecimalSeperator;
161167
}
162168
}

Plugins/Flow.Launcher.Plugin.Calculator/Settings.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
1+

72
namespace Flow.Launcher.Plugin.Caculator
83
{
94
public class Settings

0 commit comments

Comments
 (0)