Skip to content

Commit 649b142

Browse files
CopilotJack251970
andcommitted
Add UseThousandsSeparator setting to Calculator plugin
Co-authored-by: Jack251970 <53996452+Jack251970@users.noreply.github.com>
1 parent 34257ca commit 649b142

5 files changed

Lines changed: 49 additions & 2 deletions

File tree

Flow.Launcher.Test/Plugins/CalculatorTest.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public class CalculatorPluginTest
1616
{
1717
DecimalSeparator = DecimalSeparator.UseSystemLocale,
1818
MaxDecimalPlaces = 10,
19-
ShowErrorMessage = false // Make sure we return the empty results when error occurs
19+
ShowErrorMessage = false, // Make sure we return the empty results when error occurs
20+
UseThousandsSeparator = true // Default value
2021
};
2122
private readonly Engine _engine = new(new Configuration
2223
{
@@ -41,6 +42,38 @@ public CalculatorPluginTest()
4142
engineField.SetValue(null, _engine);
4243
}
4344

45+
[Test]
46+
public void ThousandsSeparatorTest_Enabled()
47+
{
48+
_settings.UseThousandsSeparator = true;
49+
_settings.DecimalSeparator = DecimalSeparator.Dot;
50+
51+
var result = GetCalculationResult("1000+234");
52+
// When thousands separator is enabled, the result should contain a separator (comma in this case)
53+
ClassicAssert.IsTrue(result.Contains(",") || result == "1234",
54+
"Expected result to contain thousands separator or be without one if system doesn't use it");
55+
}
56+
57+
[Test]
58+
public void ThousandsSeparatorTest_Disabled()
59+
{
60+
_settings.UseThousandsSeparator = false;
61+
_settings.DecimalSeparator = DecimalSeparator.Dot;
62+
63+
var result = GetCalculationResult("1000+234");
64+
ClassicAssert.AreEqual("1234", result);
65+
}
66+
67+
[Test]
68+
public void ThousandsSeparatorTest_LargeNumber()
69+
{
70+
_settings.UseThousandsSeparator = false;
71+
_settings.DecimalSeparator = DecimalSeparator.Dot;
72+
73+
var result = GetCalculationResult("1000000+234567");
74+
ClassicAssert.AreEqual("1234567", result);
75+
}
76+
4477
// Basic operations
4578
[TestCase(@"1+1", "2")]
4679
[TestCase(@"2-1", "1")]

Plugins/Flow.Launcher.Plugin.Calculator/Languages/en.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<system:String x:Key="flowlauncher_plugin_calculator_decimal_separator_comma">Comma (,)</system:String>
1515
<system:String x:Key="flowlauncher_plugin_calculator_decimal_separator_dot">Dot (.)</system:String>
1616
<system:String x:Key="flowlauncher_plugin_calculator_max_decimal_places">Max. decimal places</system:String>
17+
<system:String x:Key="flowlauncher_plugin_calculator_use_thousands_separator">Use thousands separator</system:String>
1718
<system:String x:Key="flowlauncher_plugin_calculator_failed_to_copy">Copy failed, please try later</system:String>
1819
<system:String x:Key="flowlauncher_plugin_calculator_show_error_message">Show error message when calculation fails</system:String>
1920
</ResourceDictionary>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ private string FormatResult(decimal roundedResult)
363363
string integerPart = parts[0];
364364
string fractionalPart = parts.Length > 1 ? parts[1] : string.Empty;
365365

366-
if (integerPart.Length > 3)
366+
if (_settings.UseThousandsSeparator && integerPart.Length > 3)
367367
{
368368
integerPart = ThousandGroupRegex.Replace(integerPart, groupSeparator);
369369
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ public class Settings
77
public int MaxDecimalPlaces { get; set; } = 10;
88

99
public bool ShowErrorMessage { get; set; } = false;
10+
11+
public bool UseThousandsSeparator { get; set; } = true;
1012
}

Plugins/Flow.Launcher.Plugin.Calculator/Views/CalculatorSettings.xaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<RowDefinition Height="auto" />
1717
<RowDefinition Height="auto" />
1818
<RowDefinition Height="auto" />
19+
<RowDefinition Height="auto" />
1920
</Grid.RowDefinitions>
2021
<Grid.ColumnDefinitions>
2122
<ColumnDefinition Width="Auto" />
@@ -66,6 +67,16 @@
6667
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
6768
HorizontalAlignment="Left"
6869
VerticalAlignment="Center"
70+
Content="{DynamicResource flowlauncher_plugin_calculator_use_thousands_separator}"
71+
IsChecked="{Binding Settings.UseThousandsSeparator, Mode=TwoWay}" />
72+
73+
<CheckBox
74+
Grid.Row="3"
75+
Grid.Column="0"
76+
Grid.ColumnSpan="2"
77+
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
78+
HorizontalAlignment="Left"
79+
VerticalAlignment="Center"
6980
Content="{DynamicResource flowlauncher_plugin_calculator_show_error_message}"
7081
IsChecked="{Binding Settings.ShowErrorMessage, Mode=TwoWay}" />
7182
</Grid>

0 commit comments

Comments
 (0)