diff --git a/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs b/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs index 429b04979..17b4a85a4 100644 --- a/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Calculator/Main.cs @@ -80,14 +80,14 @@ namespace Flow.Launcher.Plugin.Calculator if (result == null || string.IsNullOrEmpty(result.ToString())) { if (!_settings.ShowErrorMessage) return EmptyResults; - return new List - { + return + [ new Result { Title = Localize.flowlauncher_plugin_calculator_expression_not_complete(), IcoPath = IcoPath } - }; + ]; } if (result.ToString() == "NaN") @@ -105,8 +105,8 @@ namespace Flow.Launcher.Plugin.Calculator decimal roundedResult = Math.Round(Convert.ToDecimal(result), _settings.MaxDecimalPlaces, MidpointRounding.AwayFromZero); string newResult = FormatResult(roundedResult); - return new List - { + return + [ new Result { Title = newResult, @@ -128,21 +128,21 @@ namespace Flow.Launcher.Plugin.Calculator } } } - }; + ]; } } catch (Exception) { // Mages engine can throw various exceptions, for simplicity we catch them all and show a generic message. if (!_settings.ShowErrorMessage) return EmptyResults; - return new List - { + return + [ new Result { Title = Localize.flowlauncher_plugin_calculator_expression_not_complete(), IcoPath = IcoPath } - }; + ]; } return EmptyResults; @@ -153,7 +153,7 @@ namespace Flow.Launcher.Plugin.Calculator // m.Groups[1].Value will be `(...)` with parens var contentWithParen = m.Groups[1].Value; // remove outer parens. `(min(2,3), 4)` becomes `min(2,3), 4` - var argsContent = contentWithParen.Substring(1, contentWithParen.Length - 2); + var argsContent = contentWithParen[1..^1]; var bracketCount = 0; var splitIndex = -1; diff --git a/Plugins/Flow.Launcher.Plugin.Calculator/Settings.cs b/Plugins/Flow.Launcher.Plugin.Calculator/Settings.cs index 0f32b09a9..cac0f3080 100644 --- a/Plugins/Flow.Launcher.Plugin.Calculator/Settings.cs +++ b/Plugins/Flow.Launcher.Plugin.Calculator/Settings.cs @@ -1,12 +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 DecimalSeparator DecimalSeparator { get; set; } = DecimalSeparator.UseSystemLocale; - public int MaxDecimalPlaces { get; set; } = 10; + public int MaxDecimalPlaces { get; set; } = 10; - public bool ShowErrorMessage { get; set; } = false; - } + public bool ShowErrorMessage { get; set; } = false; } diff --git a/Plugins/Flow.Launcher.Plugin.Calculator/ViewModels/SettingsViewModel.cs b/Plugins/Flow.Launcher.Plugin.Calculator/ViewModels/SettingsViewModel.cs index 87ae72fb6..36c277f15 100644 --- a/Plugins/Flow.Launcher.Plugin.Calculator/ViewModels/SettingsViewModel.cs +++ b/Plugins/Flow.Launcher.Plugin.Calculator/ViewModels/SettingsViewModel.cs @@ -1,31 +1,25 @@ using System.Collections.Generic; using System.Linq; -namespace Flow.Launcher.Plugin.Calculator.ViewModels +namespace Flow.Launcher.Plugin.Calculator.ViewModels; + +public class SettingsViewModel(Settings settings) : BaseModel { - public class SettingsViewModel : BaseModel + public Settings Settings { get; init; } = settings; + + public static IEnumerable MaxDecimalPlacesRange => Enumerable.Range(1, 20); + + public List AllDecimalSeparator { get; } = DecimalSeparatorLocalized.GetValues(); + + public DecimalSeparator SelectedDecimalSeparator { - public SettingsViewModel(Settings settings) + get => Settings.DecimalSeparator; + set { - Settings = settings; - } - - public Settings Settings { get; init; } - - public static IEnumerable MaxDecimalPlacesRange => Enumerable.Range(1, 20); - - public List AllDecimalSeparator { get; } = DecimalSeparatorLocalized.GetValues(); - - public DecimalSeparator SelectedDecimalSeparator - { - get => Settings.DecimalSeparator; - set + if (Settings.DecimalSeparator != value) { - if (Settings.DecimalSeparator != value) - { - Settings.DecimalSeparator = value; - OnPropertyChanged(); - } + Settings.DecimalSeparator = value; + OnPropertyChanged(); } } } diff --git a/Plugins/Flow.Launcher.Plugin.Calculator/Views/CalculatorSettings.xaml.cs b/Plugins/Flow.Launcher.Plugin.Calculator/Views/CalculatorSettings.xaml.cs index 7bc307d11..9e75e7bfb 100644 --- a/Plugins/Flow.Launcher.Plugin.Calculator/Views/CalculatorSettings.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.Calculator/Views/CalculatorSettings.xaml.cs @@ -1,22 +1,16 @@ using System.Windows.Controls; using Flow.Launcher.Plugin.Calculator.ViewModels; -namespace Flow.Launcher.Plugin.Calculator.Views -{ - /// - /// Interaction logic for CalculatorSettings.xaml - /// - public partial class CalculatorSettings : UserControl - { - private readonly SettingsViewModel _viewModel; - private readonly Settings _settings; +namespace Flow.Launcher.Plugin.Calculator.Views; - public CalculatorSettings(Settings settings) - { - _viewModel = new SettingsViewModel(settings); - _settings = _viewModel.Settings; - DataContext = _viewModel; - InitializeComponent(); - } +public partial class CalculatorSettings : UserControl +{ + private readonly SettingsViewModel _viewModel; + + public CalculatorSettings(Settings settings) + { + _viewModel = new SettingsViewModel(settings); + DataContext = _viewModel; + InitializeComponent(); } }