Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e107939
backout 'smart' digit grouping, mages fixes + workaround
dcog989 Sep 12, 2025
103d383
dead code, improve messages, group separator fix?
dcog989 Sep 12, 2025
190e0e1
Fix 'German' number formatting
dcog989 Sep 12, 2025
bd186e7
correct + extend description
dcog989 Sep 12, 2025
110f571
Rework solution for nested Mages
dcog989 Sep 13, 2025
6462023
Merge branch 'dev' into calculator-min-fix
dcog989 Sep 13, 2025
11f5ea5
Improve code quality
Jack251970 Sep 14, 2025
495ace1
Improve plugin description
Jack251970 Sep 14, 2025
daf35a4
Do not check bracket complete
Jack251970 Sep 14, 2025
c79e483
Merge branch 'Flow-Launcher:dev' into calculator-min-fix
dcog989 Sep 14, 2025
336e51d
IcoPath to const string
dcog989 Sep 14, 2025
e990e0f
Handle misplaced separators, Mages edge cases
dcog989 Sep 14, 2025
edc76fa
Review feedback, case insensitive, consistent separators
dcog989 Sep 14, 2025
9be8b71
review feedback, CultureInvariant, mild refactor
dcog989 Sep 14, 2025
b07420a
Use EmptyResults to improve code quality
Jack251970 Sep 15, 2025
cea1402
Improve code quality
Jack251970 Sep 15, 2025
1906d68
Add ShowErrorMessage setting
Jack251970 Sep 15, 2025
f9facda
Improve code quality
Jack251970 Sep 15, 2025
684fafd
Improve code quality
Jack251970 Sep 15, 2025
6841ad5
Add calculator unit testing
Jack251970 Sep 16, 2025
e10b925
Add workaround for log & ln function
Jack251970 Sep 16, 2025
552b654
Fix unit test result issue
Jack251970 Sep 16, 2025
8321e40
Fix test setting & Add instances to private fields
Jack251970 Sep 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Plugins/Flow.Launcher.Plugin.Calculator/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:system="clr-namespace:System;assembly=mscorlib">

<system:String x:Key="flowlauncher_plugin_calculator_plugin_name">Calculator</system:String>
<system:String x:Key="flowlauncher_plugin_calculator_plugin_description">Perform mathematical calculations (including hexadecimal values). Use ',' or '.' as thousand separator or decimal place.</system:String>
<system:String x:Key="flowlauncher_plugin_calculator_plugin_description">Perform mathematical calculations, including hex values and advanced functions such as 'min(1,2,3)', 'sqrt(123)' and 'cos(123)'.</system:String>
<system:String x:Key="flowlauncher_plugin_calculator_not_a_number">Not a number (NaN)</system:String>
<system:String x:Key="flowlauncher_plugin_calculator_expression_not_complete">Expression wrong or incomplete (Did you forget some parentheses?)</system:String>
<system:String x:Key="flowlauncher_plugin_calculator_copy_number_to_clipboard">Copy this number to the clipboard</system:String>
Expand All @@ -15,4 +15,5 @@
<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_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>
323 changes: 193 additions & 130 deletions Plugins/Flow.Launcher.Plugin.Calculator/Main.cs

Large diffs are not rendered by default.

15 changes: 7 additions & 8 deletions Plugins/Flow.Launcher.Plugin.Calculator/MainRegexHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@

internal static partial class MainRegexHelper
{

[GeneratedRegex(@"[\(\)\[\]]", RegexOptions.Compiled)]
public static partial Regex GetRegBrackets();

[GeneratedRegex(@"^(ceil|floor|exp|pi|e|max|min|det|abs|log|ln|sqrt|sin|cos|tan|arcsin|arccos|arctan|eigval|eigvec|eig|sum|polar|plot|round|sort|real|zeta|bin2dec|hex2dec|oct2dec|factorial|sign|isprime|isinfty|==|~=|&&|\|\||(?:\<|\>)=?|[ei]|[0-9]|0x[\da-fA-F]+|[\+\%\-\*\/\^\., ""]|[\(\)\|\!\[\]])+$", RegexOptions.Compiled)]
public static partial Regex GetRegValidExpressChar();

[GeneratedRegex(@"[\d\.,]+", RegexOptions.Compiled)]
[GeneratedRegex(@"-?[\d\.,'\u00A0\u202F]+", RegexOptions.Compiled | RegexOptions.CultureInvariant)]
public static partial Regex GetNumberRegex();

[GeneratedRegex(@"\B(?=(\d{3})+(?!\d))", RegexOptions.Compiled)]
public static partial Regex GetThousandGroupRegex();

[GeneratedRegex(@"\bpow(\((?:[^()\[\]]|\((?<Depth>)|\)(?<-Depth>)|\[(?<Depth>)|\](?<-Depth>))*(?(Depth)(?!))\))", RegexOptions.Compiled | RegexOptions.RightToLeft | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)]

Check warning on line 13 in Plugins/Flow.Launcher.Plugin.Calculator/MainRegexHelper.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`bpow` is not a recognized word. (unrecognized-spelling)
public static partial Regex GetPowRegex();

[GeneratedRegex(@"\b(sqrt|pow|factorial|abs|sign|ceil|floor|round|exp|log|log2|log10|min|max|lt|eq|gt|sin|cos|tan|arcsin|arccos|arctan|isnan|isint|isprime|isinfty|rand|randi|type|is|as|length|throw|catch|eval|map|clamp|lerp|regex|shuffle)\s*\(", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)]

Check warning on line 16 in Plugins/Flow.Launcher.Plugin.Calculator/MainRegexHelper.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`randi` is not a recognized word. (unrecognized-spelling)

Check warning on line 16 in Plugins/Flow.Launcher.Plugin.Calculator/MainRegexHelper.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`isinfty` is not a recognized word. (unrecognized-spelling)

Check warning on line 16 in Plugins/Flow.Launcher.Plugin.Calculator/MainRegexHelper.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`isprime` is not a recognized word. (unrecognized-spelling)

Check warning on line 16 in Plugins/Flow.Launcher.Plugin.Calculator/MainRegexHelper.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`isint` is not a recognized word. (unrecognized-spelling)
public static partial Regex GetFunctionRegex();
}
14 changes: 8 additions & 6 deletions Plugins/Flow.Launcher.Plugin.Calculator/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@

namespace Flow.Launcher.Plugin.Calculator
namespace Flow.Launcher.Plugin.Calculator;

public class Settings
{
public class Settings
{
public DecimalSeparator DecimalSeparator { get; set; } = DecimalSeparator.UseSystemLocale;
public int MaxDecimalPlaces { get; set; } = 10;
}
public DecimalSeparator DecimalSeparator { get; set; } = DecimalSeparator.UseSystemLocale;

public int MaxDecimalPlaces { get; set; } = 10;

public bool ShowErrorMessage { get; set; } = false;
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
using System.Collections.Generic;
using System.Linq;

namespace Flow.Launcher.Plugin.Calculator.ViewModels
{
public class SettingsViewModel : BaseModel
{
public SettingsViewModel(Settings settings)
{
Settings = settings;
}
namespace Flow.Launcher.Plugin.Calculator.ViewModels;

public Settings Settings { get; init; }
public class SettingsViewModel(Settings settings) : BaseModel
{
public Settings Settings { get; init; } = settings;

public static IEnumerable<int> MaxDecimalPlacesRange => Enumerable.Range(1, 20);
public static IEnumerable<int> MaxDecimalPlacesRange => Enumerable.Range(1, 20);

public List<DecimalSeparatorLocalized> AllDecimalSeparator { get; } = DecimalSeparatorLocalized.GetValues();
public List<DecimalSeparatorLocalized> AllDecimalSeparator { get; } = DecimalSeparatorLocalized.GetValues();

public DecimalSeparator SelectedDecimalSeparator
public DecimalSeparator SelectedDecimalSeparator
{
get => Settings.DecimalSeparator;
set
{
get => Settings.DecimalSeparator;
set
if (Settings.DecimalSeparator != value)
{
if (Settings.DecimalSeparator != value)
{
Settings.DecimalSeparator = value;
OnPropertyChanged();
}
Settings.DecimalSeparator = value;
OnPropertyChanged();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
Expand Down Expand Up @@ -58,5 +59,14 @@
ItemsSource="{Binding MaxDecimalPlacesRange}"
SelectedItem="{Binding Settings.MaxDecimalPlaces}" />

<CheckBox
Grid.Row="2"
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>
</UserControl>
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
using System.Windows.Controls;
using Flow.Launcher.Plugin.Calculator.ViewModels;

namespace Flow.Launcher.Plugin.Calculator.Views
namespace Flow.Launcher.Plugin.Calculator.Views;

public partial class CalculatorSettings : UserControl
{
/// <summary>
/// Interaction logic for CalculatorSettings.xaml
/// </summary>
public partial class CalculatorSettings : UserControl
{
private readonly SettingsViewModel _viewModel;
private readonly Settings _settings;
private readonly SettingsViewModel _viewModel;

public CalculatorSettings(Settings settings)
{
_viewModel = new SettingsViewModel(settings);
_settings = _viewModel.Settings;
DataContext = _viewModel;
InitializeComponent();
}
public CalculatorSettings(Settings settings)
{
_viewModel = new SettingsViewModel(settings);
DataContext = _viewModel;
InitializeComponent();
}
}
2 changes: 1 addition & 1 deletion Plugins/Flow.Launcher.Plugin.Calculator/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"ID": "CEA0FDFC6D3B4085823D60DC76F28855",
"ActionKeyword": "*",
"Name": "Calculator",
"Description": "Perform mathematical calculations (including hexadecimal values). Use ',' or '.' as thousand separator or decimal place.",
"Description": "Perform mathematical calculations, including hex values and advanced functions such as 'min(1,2,3)', 'sqrt(123)' and 'cos(123)'.",
"Author": "cxfksword, dcog989",

Check warning on line 6 in Plugins/Flow.Launcher.Plugin.Calculator/plugin.json

View workflow job for this annotation

GitHub Actions / Check Spelling

`dcog` is not a recognized word. (unrecognized-spelling)

Check warning on line 6 in Plugins/Flow.Launcher.Plugin.Calculator/plugin.json

View workflow job for this annotation

GitHub Actions / Check Spelling

`cxfksword` is not a recognized word. (unrecognized-spelling)
"Version": "1.0.0",
"Language": "csharp",
"Website": "https://github.com/Flow-Launcher/Flow.Launcher",
Expand Down
Loading