Skip to content

Commit 1906d68

Browse files
committed
Add ShowErrorMessage setting
1 parent cea1402 commit 1906d68

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@
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>
1717
<system:String x:Key="flowlauncher_plugin_calculator_failed_to_copy">Copy failed, please try later</system:String>
18+
<system:String x:Key="flowlauncher_plugin_calculator_show_error_message">Show error message when calculation fails</system:String>
1819
</ResourceDictionary>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public List<Result> Query(Query query)
7979

8080
if (result == null || string.IsNullOrEmpty(result.ToString()))
8181
{
82+
if (!_settings.ShowErrorMessage) return EmptyResults;
8283
return new List<Result>
8384
{
8485
new Result
@@ -90,10 +91,14 @@ public List<Result> Query(Query query)
9091
}
9192

9293
if (result.ToString() == "NaN")
94+
{
9395
result = Localize.flowlauncher_plugin_calculator_not_a_number();
96+
}
9497

9598
if (result is Function)
99+
{
96100
result = Localize.flowlauncher_plugin_calculator_expression_not_complete();
101+
}
97102

98103
if (!string.IsNullOrEmpty(result.ToString()))
99104
{
@@ -129,6 +134,7 @@ public List<Result> Query(Query query)
129134
catch (Exception)
130135
{
131136
// Mages engine can throw various exceptions, for simplicity we catch them all and show a generic message.
137+
if (!_settings.ShowErrorMessage) return EmptyResults;
132138
return new List<Result>
133139
{
134140
new Result

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ namespace Flow.Launcher.Plugin.Calculator
44
public class Settings
55
{
66
public DecimalSeparator DecimalSeparator { get; set; } = DecimalSeparator.UseSystemLocale;
7-
public int MaxDecimalPlaces { get; set; } = 10;
7+
8+
public int MaxDecimalPlaces { get; set; } = 10;
9+
10+
public bool ShowErrorMessage { get; set; } = false;
811
}
912
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<Grid.RowDefinitions>
1616
<RowDefinition Height="auto" />
1717
<RowDefinition Height="auto" />
18+
<RowDefinition Height="auto" />
1819
</Grid.RowDefinitions>
1920
<Grid.ColumnDefinitions>
2021
<ColumnDefinition Width="Auto" />
@@ -58,5 +59,14 @@
5859
ItemsSource="{Binding MaxDecimalPlacesRange}"
5960
SelectedItem="{Binding Settings.MaxDecimalPlaces}" />
6061

62+
<CheckBox
63+
Grid.Row="2"
64+
Grid.Column="0"
65+
Grid.ColumnSpan="2"
66+
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
67+
HorizontalAlignment="Left"
68+
VerticalAlignment="Center"
69+
Content="{DynamicResource flowlauncher_plugin_calculator_show_error_message}"
70+
IsChecked="{Binding Settings.ShowErrorMessage, Mode=TwoWay}" />
6171
</Grid>
6272
</UserControl>

0 commit comments

Comments
 (0)