mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #4206 from Flow-Launcher/copilot/fix-calculator-thousands-separator
Add setting to disable thousands separator in Calculator plugin
This commit is contained in:
commit
ca5f5cf0e3
5 changed files with 61 additions and 5 deletions
|
|
@ -16,14 +16,15 @@ namespace Flow.Launcher.Test.Plugins
|
|||
{
|
||||
DecimalSeparator = DecimalSeparator.UseSystemLocale,
|
||||
MaxDecimalPlaces = 10,
|
||||
ShowErrorMessage = false // Make sure we return the empty results when error occurs
|
||||
ShowErrorMessage = false, // Make sure we return the empty results when error occurs
|
||||
UseThousandsSeparator = true // Default value
|
||||
};
|
||||
private readonly Engine _engine = new(new Configuration
|
||||
{
|
||||
Scope = new Dictionary<string, object>
|
||||
{
|
||||
{ "e", Math.E }, // e is not contained in the default mages engine
|
||||
}
|
||||
{
|
||||
{ "e", Math.E }, // e is not contained in the default mages engine
|
||||
}
|
||||
});
|
||||
|
||||
public CalculatorPluginTest()
|
||||
|
|
@ -41,6 +42,44 @@ namespace Flow.Launcher.Test.Plugins
|
|||
engineField.SetValue(null, _engine);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ThousandsSeparatorTest_Enabled()
|
||||
{
|
||||
_settings.UseThousandsSeparator = true;
|
||||
|
||||
_settings.DecimalSeparator = DecimalSeparator.Dot;
|
||||
var result = GetCalculationResult("1000+234");
|
||||
// When thousands separator is enabled, the result should contain a separator
|
||||
// Since decimal separator is dot, thousands separator should be comma
|
||||
ClassicAssert.AreEqual("1,234", result);
|
||||
|
||||
_settings.DecimalSeparator = DecimalSeparator.Comma;
|
||||
var result2 = GetCalculationResult("1000+234");
|
||||
// When thousands separator is enabled, the result should contain a separator
|
||||
// Since decimal separator is comma, thousands separator should be dot
|
||||
ClassicAssert.AreEqual("1.234", result2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ThousandsSeparatorTest_Disabled()
|
||||
{
|
||||
_settings.UseThousandsSeparator = false;
|
||||
_settings.DecimalSeparator = DecimalSeparator.UseSystemLocale;
|
||||
|
||||
var result = GetCalculationResult("1000+234");
|
||||
ClassicAssert.AreEqual("1234", result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ThousandsSeparatorTest_LargeNumber()
|
||||
{
|
||||
_settings.UseThousandsSeparator = false;
|
||||
_settings.DecimalSeparator = DecimalSeparator.UseSystemLocale;
|
||||
|
||||
var result = GetCalculationResult("1000000+234567");
|
||||
ClassicAssert.AreEqual("1234567", result);
|
||||
}
|
||||
|
||||
// Basic operations
|
||||
[TestCase(@"1+1", "2")]
|
||||
[TestCase(@"2-1", "1")]
|
||||
|
|
@ -77,6 +116,9 @@ namespace Flow.Launcher.Test.Plugins
|
|||
[TestCase(@"invalid_expression", "")]
|
||||
public void CalculatorTest(string expression, string result)
|
||||
{
|
||||
_settings.UseThousandsSeparator = false;
|
||||
_settings.DecimalSeparator = DecimalSeparator.Dot;
|
||||
|
||||
ClassicAssert.AreEqual(GetCalculationResult(expression), result);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
<system:String x:Key="flowlauncher_plugin_calculator_decimal_separator_comma">Comma (,)</system:String>
|
||||
<system:String x:Key="flowlauncher_plugin_calculator_decimal_separator_dot">Dot (.)</system:String>
|
||||
<system:String x:Key="flowlauncher_plugin_calculator_max_decimal_places">Max. decimal places</system:String>
|
||||
<system:String x:Key="flowlauncher_plugin_calculator_use_thousands_separator">Show thousands separator in results</system:String>
|
||||
<system:String x:Key="flowlauncher_plugin_calculator_failed_to_copy">Copy failed, please try later</system:String>
|
||||
<system:String x:Key="flowlauncher_plugin_calculator_show_error_message">Show error message when calculation fails</system:String>
|
||||
</ResourceDictionary>
|
||||
|
|
@ -363,7 +363,7 @@ namespace Flow.Launcher.Plugin.Calculator
|
|||
string integerPart = parts[0];
|
||||
string fractionalPart = parts.Length > 1 ? parts[1] : string.Empty;
|
||||
|
||||
if (integerPart.Length > 3)
|
||||
if (_settings.UseThousandsSeparator && integerPart.Length > 3)
|
||||
{
|
||||
integerPart = ThousandGroupRegex.Replace(integerPart, groupSeparator);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,4 +7,6 @@ public class Settings
|
|||
public int MaxDecimalPlaces { get; set; } = 10;
|
||||
|
||||
public bool ShowErrorMessage { get; set; } = false;
|
||||
|
||||
public bool UseThousandsSeparator { get; set; } = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
<RowDefinition Height="auto" />
|
||||
<RowDefinition Height="auto" />
|
||||
<RowDefinition Height="auto" />
|
||||
<RowDefinition Height="auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
|
|
@ -66,6 +67,16 @@
|
|||
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
Content="{DynamicResource flowlauncher_plugin_calculator_use_thousands_separator}"
|
||||
IsChecked="{Binding Settings.UseThousandsSeparator, Mode=TwoWay}" />
|
||||
|
||||
<CheckBox
|
||||
Grid.Row="3"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="2"
|
||||
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
Content="{DynamicResource flowlauncher_plugin_calculator_show_error_message}"
|
||||
IsChecked="{Binding Settings.ShowErrorMessage, Mode=TwoWay}" />
|
||||
</Grid>
|
||||
|
|
|
|||
Loading…
Reference in a new issue