mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Add UseThousandsSeparator setting to Calculator plugin
Co-authored-by: Jack251970 <53996452+Jack251970@users.noreply.github.com>
This commit is contained in:
parent
34257cad60
commit
649b142b46
5 changed files with 49 additions and 2 deletions
|
|
@ -16,7 +16,8 @@ namespace Flow.Launcher.Test.Plugins
|
||||||
{
|
{
|
||||||
DecimalSeparator = DecimalSeparator.UseSystemLocale,
|
DecimalSeparator = DecimalSeparator.UseSystemLocale,
|
||||||
MaxDecimalPlaces = 10,
|
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
|
private readonly Engine _engine = new(new Configuration
|
||||||
{
|
{
|
||||||
|
|
@ -41,6 +42,38 @@ namespace Flow.Launcher.Test.Plugins
|
||||||
engineField.SetValue(null, _engine);
|
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 (comma in this case)
|
||||||
|
ClassicAssert.IsTrue(result.Contains(",") || result == "1234",
|
||||||
|
"Expected result to contain thousands separator or be without one if system doesn't use it");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ThousandsSeparatorTest_Disabled()
|
||||||
|
{
|
||||||
|
_settings.UseThousandsSeparator = false;
|
||||||
|
_settings.DecimalSeparator = DecimalSeparator.Dot;
|
||||||
|
|
||||||
|
var result = GetCalculationResult("1000+234");
|
||||||
|
ClassicAssert.AreEqual("1234", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ThousandsSeparatorTest_LargeNumber()
|
||||||
|
{
|
||||||
|
_settings.UseThousandsSeparator = false;
|
||||||
|
_settings.DecimalSeparator = DecimalSeparator.Dot;
|
||||||
|
|
||||||
|
var result = GetCalculationResult("1000000+234567");
|
||||||
|
ClassicAssert.AreEqual("1234567", result);
|
||||||
|
}
|
||||||
|
|
||||||
// Basic operations
|
// Basic operations
|
||||||
[TestCase(@"1+1", "2")]
|
[TestCase(@"1+1", "2")]
|
||||||
[TestCase(@"2-1", "1")]
|
[TestCase(@"2-1", "1")]
|
||||||
|
|
|
||||||
|
|
@ -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_comma">Comma (,)</system:String>
|
||||||
<system:String x:Key="flowlauncher_plugin_calculator_decimal_separator_dot">Dot (.)</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_max_decimal_places">Max. decimal places</system:String>
|
||||||
|
<system:String x:Key="flowlauncher_plugin_calculator_use_thousands_separator">Use thousands separator</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_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>
|
<system:String x:Key="flowlauncher_plugin_calculator_show_error_message">Show error message when calculation fails</system:String>
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
|
|
@ -363,7 +363,7 @@ namespace Flow.Launcher.Plugin.Calculator
|
||||||
string integerPart = parts[0];
|
string integerPart = parts[0];
|
||||||
string fractionalPart = parts.Length > 1 ? parts[1] : string.Empty;
|
string fractionalPart = parts.Length > 1 ? parts[1] : string.Empty;
|
||||||
|
|
||||||
if (integerPart.Length > 3)
|
if (_settings.UseThousandsSeparator && integerPart.Length > 3)
|
||||||
{
|
{
|
||||||
integerPart = ThousandGroupRegex.Replace(integerPart, groupSeparator);
|
integerPart = ThousandGroupRegex.Replace(integerPart, groupSeparator);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,6 @@ public class Settings
|
||||||
public int MaxDecimalPlaces { get; set; } = 10;
|
public int MaxDecimalPlaces { get; set; } = 10;
|
||||||
|
|
||||||
public bool ShowErrorMessage { get; set; } = false;
|
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" />
|
||||||
<RowDefinition Height="auto" />
|
<RowDefinition Height="auto" />
|
||||||
|
<RowDefinition Height="auto" />
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="Auto" />
|
<ColumnDefinition Width="Auto" />
|
||||||
|
|
@ -66,6 +67,16 @@
|
||||||
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
|
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
|
||||||
HorizontalAlignment="Left"
|
HorizontalAlignment="Left"
|
||||||
VerticalAlignment="Center"
|
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}"
|
Content="{DynamicResource flowlauncher_plugin_calculator_show_error_message}"
|
||||||
IsChecked="{Binding Settings.ShowErrorMessage, Mode=TwoWay}" />
|
IsChecked="{Binding Settings.ShowErrorMessage, Mode=TwoWay}" />
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue