6
6
using System . Windows ;
7
7
using System . Windows . Controls ;
8
8
using Mages . Core ;
9
- using Flow . Launcher . Infrastructure . Storage ;
10
9
using Flow . Launcher . Plugin . Caculator . ViewModels ;
11
10
using Flow . Launcher . Plugin . Caculator . Views ;
12
11
@@ -25,6 +24,9 @@ public class Main : IPlugin, IPluginI18n, ISettingProvider
25
24
@")+$" , RegexOptions . Compiled ) ;
26
25
private static readonly Regex RegBrackets = new Regex ( @"[\(\)\[\]]" , RegexOptions . Compiled ) ;
27
26
private static Engine MagesEngine ;
27
+ private const string comma = "," ;
28
+ private const string dot = "." ;
29
+
28
30
private PluginInitContext Context { get ; set ; }
29
31
30
32
private static Settings _settings ;
@@ -35,7 +37,7 @@ public void Init(PluginInitContext context)
35
37
Context = context ;
36
38
_settings = context . API . LoadSettingJsonStorage < Settings > ( ) ;
37
39
_viewModel = new SettingsViewModel ( _settings ) ;
38
-
40
+
39
41
MagesEngine = new Engine ( new Configuration
40
42
{
41
43
Scope = new Dictionary < string , object >
@@ -54,7 +56,19 @@ public List<Result> Query(Query query)
54
56
55
57
try
56
58
{
57
- var expression = query . Search . Replace ( "," , "." ) ;
59
+ string expression ;
60
+
61
+ switch ( _settings . DecimalSeparator )
62
+ {
63
+ case DecimalSeparator . Comma :
64
+ case DecimalSeparator . UseSystemLocale when CultureInfo . CurrentCulture . NumberFormat . NumberDecimalSeparator == "," :
65
+ expression = query . Search . Replace ( "," , "." ) ;
66
+ break ;
67
+ default :
68
+ expression = query . Search ;
69
+ break ;
70
+ }
71
+
58
72
var result = MagesEngine . Interpret ( expression ) ;
59
73
60
74
if ( result ? . ToString ( ) == "NaN" )
@@ -76,6 +90,7 @@ public List<Result> Query(Query query)
76
90
IcoPath = "Images/calculator.png" ,
77
91
Score = 300 ,
78
92
SubTitle = Context . API . GetTranslation ( "flowlauncher_plugin_calculator_copy_number_to_clipboard" ) ,
93
+ CopyText = newResult ,
79
94
Action = c =>
80
95
{
81
96
try
@@ -119,6 +134,10 @@ private bool CanCalculate(Query query)
119
134
return false ;
120
135
}
121
136
137
+ if ( ( query . Search . Contains ( dot ) && GetDecimalSeparator ( ) != dot ) ||
138
+ ( query . Search . Contains ( comma ) && GetDecimalSeparator ( ) != comma ) )
139
+ return false ;
140
+
122
141
return true ;
123
142
}
124
143
@@ -142,8 +161,8 @@ private string GetDecimalSeparator()
142
161
switch ( _settings . DecimalSeparator )
143
162
{
144
163
case DecimalSeparator . UseSystemLocale : return systemDecimalSeperator ;
145
- case DecimalSeparator . Dot : return "." ;
146
- case DecimalSeparator . Comma : return "," ;
164
+ case DecimalSeparator . Dot : return dot ;
165
+ case DecimalSeparator . Comma : return comma ;
147
166
default : return systemDecimalSeperator ;
148
167
}
149
168
}
0 commit comments