66using System . Windows ;
77using System . Windows . Controls ;
88using Mages . Core ;
9- using Flow . Launcher . Infrastructure . Storage ;
109using Flow . Launcher . Plugin . Caculator . ViewModels ;
1110using 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 ;
@@ -35,7 +37,7 @@ public void Init(PluginInitContext context)
3537 Context = context ;
3638 _settings = context . API . LoadSettingJsonStorage < Settings > ( ) ;
3739 _viewModel = new SettingsViewModel ( _settings ) ;
38-
40+
3941 MagesEngine = new Engine ( new Configuration
4042 {
4143 Scope = new Dictionary < string , object >
@@ -54,7 +56,19 @@ public List<Result> Query(Query query)
5456
5557 try
5658 {
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+
5872 var result = MagesEngine . Interpret ( expression ) ;
5973
6074 if ( result ? . ToString ( ) == "NaN" )
@@ -76,6 +90,7 @@ public List<Result> Query(Query query)
7690 IcoPath = "Images/calculator.png" ,
7791 Score = 300 ,
7892 SubTitle = Context . API . GetTranslation ( "flowlauncher_plugin_calculator_copy_number_to_clipboard" ) ,
93+ CopyText = newResult ,
7994 Action = c =>
8095 {
8196 try
@@ -119,6 +134,10 @@ private bool CanCalculate(Query query)
119134 return false ;
120135 }
121136
137+ if ( ( query . Search . Contains ( dot ) && GetDecimalSeparator ( ) != dot ) ||
138+ ( query . Search . Contains ( comma ) && GetDecimalSeparator ( ) != comma ) )
139+ return false ;
140+
122141 return true ;
123142 }
124143
@@ -142,8 +161,8 @@ private string GetDecimalSeparator()
142161 switch ( _settings . DecimalSeparator )
143162 {
144163 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 ;
147166 default : return systemDecimalSeperator ;
148167 }
149168 }
0 commit comments