Add ShowErrorMessage setting

This commit is contained in:
Jack251970 2025-09-15 12:57:25 +08:00
parent cea1402dde
commit 1906d68541
4 changed files with 21 additions and 1 deletions

View file

@ -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>

View file

@ -79,6 +79,7 @@ namespace Flow.Launcher.Plugin.Calculator
if (result == null || string.IsNullOrEmpty(result.ToString()))
{
if (!_settings.ShowErrorMessage) return EmptyResults;
return new List<Result>
{
new Result
@ -90,10 +91,14 @@ namespace Flow.Launcher.Plugin.Calculator
}
if (result.ToString() == "NaN")
{
result = Localize.flowlauncher_plugin_calculator_not_a_number();
}
if (result is Function)
{
result = Localize.flowlauncher_plugin_calculator_expression_not_complete();
}
if (!string.IsNullOrEmpty(result.ToString()))
{
@ -129,6 +134,7 @@ 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<Result>
{
new Result

View file

@ -4,6 +4,9 @@ namespace Flow.Launcher.Plugin.Calculator
public class Settings
{
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;
}
}

View file

@ -15,6 +15,7 @@
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
@ -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>