Skip to content

Commit 1acb8fd

Browse files
committed
Merge branch 'dev'
2 parents 28acd46 + d183f62 commit 1acb8fd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+515
-88
lines changed

Plugins/HelloWorldCSharp/App.config

Lines changed: 0 additions & 6 deletions
This file was deleted.

Plugins/HelloWorldCSharp/HelloWorldCSharp.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>HelloWorldCSharp</RootNamespace>
1111
<AssemblyName>HelloWorldCSharp</AssemblyName>
12-
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
14-
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
<TargetFrameworkProfile />
1515
</PropertyGroup>
1616
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1717
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -52,7 +52,6 @@
5252
<Compile Include="Properties\AssemblyInfo.cs" />
5353
</ItemGroup>
5454
<ItemGroup>
55-
<None Include="App.config" />
5655
<None Include="plugin.json">
5756
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
5857
</None>

Plugins/Wox.Plugin.BrowserBookmark/Wox.Plugin.BrowserBookmark.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>Wox.Plugin.BrowserBookmark</RootNamespace>
1111
<AssemblyName>Wox.Plugin.BrowserBookmark</AssemblyName>
12-
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
1515
<RestorePackages>true</RestorePackages>
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<configSections>
44

5-
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
5+
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
66
</configSections>
77
<startup>
8-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
8+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
99
</startup>
1010
<entityFramework>
1111
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
1212
<parameters>
13-
<parameter value="mssqllocaldb" />
13+
<parameter value="mssqllocaldb"/>
1414
</parameters>
1515
</defaultConnectionFactory>
1616
<providers>
17-
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
18-
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
17+
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
18+
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6"/>
1919
</providers>
2020
</entityFramework>
2121

22-
</configuration>
22+
</configuration>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Globalization;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using Wox.Core;
9+
10+
namespace Wox.Plugin.Caculator
11+
{
12+
[TypeConverter(typeof(LocalizationConverter))]
13+
public enum DecimalSeparator
14+
{
15+
[LocalizedDescription("wox_plugin_calculator_decimal_seperator_use_system_locale")]
16+
UseSystemLocale,
17+
18+
[LocalizedDescription("wox_plugin_calculator_decimal_seperator_dot")]
19+
Dot,
20+
21+
[LocalizedDescription("wox_plugin_calculator_decimal_seperator_comma")]
22+
Comma
23+
}
24+
}

Plugins/Wox.Plugin.Calculator/Languages/de.xaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,10 @@
77
<system:String x:Key="wox_plugin_calculator_not_a_number">Keine Zahl (NaN)</system:String>
88
<system:String x:Key="wox_plugin_calculator_expression_not_complete">Ausdruck falsch oder nicht vollständig (Klammern vergessen?)</system:String>
99
<system:String x:Key="wox_plugin_calculator_copy_number_to_clipboard">Diese Zahl in die Zwischenablage kopieren</system:String>
10+
<system:String x:Key="wox_plugin_calculator_output_decimal_seperator">Dezimaltrennzeichen</system:String>
11+
<system:String x:Key="wox_plugin_calculator_output_decimal_seperator_help">Das Dezimaltrennzeichen, welches bei der Ausgabe verwendet werden soll.</system:String>
12+
<system:String x:Key="wox_plugin_calculator_decimal_seperator_use_system_locale">Systemeinstellung nutzen</system:String>
13+
<system:String x:Key="wox_plugin_calculator_decimal_seperator_comma">Komma (,)</system:String>
14+
<system:String x:Key="wox_plugin_calculator_decimal_seperator_dot">Punkt (.)</system:String>
15+
<system:String x:Key="wox_plugin_calculator_max_decimal_places">Max. Nachkommastellen</system:String>
1016
</ResourceDictionary>

Plugins/Wox.Plugin.Calculator/Languages/en.xaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,10 @@
77
<system:String x:Key="wox_plugin_calculator_not_a_number">Not a number (NaN)</system:String>
88
<system:String x:Key="wox_plugin_calculator_expression_not_complete">Expression wrong or incomplete (Did you forget some parentheses?)</system:String>
99
<system:String x:Key="wox_plugin_calculator_copy_number_to_clipboard">Copy this number to the clipboard</system:String>
10+
<system:String x:Key="wox_plugin_calculator_output_decimal_seperator">Decimal separator</system:String>
11+
<system:String x:Key="wox_plugin_calculator_output_decimal_seperator_help">The decimal separator to be used in the output.</system:String>
12+
<system:String x:Key="wox_plugin_calculator_decimal_seperator_use_system_locale">Use system locale</system:String>
13+
<system:String x:Key="wox_plugin_calculator_decimal_seperator_comma">Comma (,)</system:String>
14+
<system:String x:Key="wox_plugin_calculator_decimal_seperator_dot">Dot (.)</system:String>
15+
<system:String x:Key="wox_plugin_calculator_max_decimal_places">Max. decimal places</system:String>
1016
</ResourceDictionary>

Plugins/Wox.Plugin.Calculator/Main.cs

Lines changed: 89 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Globalization;
24
using System.Runtime.InteropServices;
35
using System.Text.RegularExpressions;
46
using System.Windows;
7+
using System.Windows.Controls;
58
using Mages.Core;
9+
using Wox.Infrastructure.Storage;
10+
using Wox.Plugin.Caculator.ViewModels;
11+
using Wox.Plugin.Caculator.Views;
612

713
namespace Wox.Plugin.Caculator
814
{
9-
public class Main : IPlugin, IPluginI18n
15+
public class Main : IPlugin, IPluginI18n, ISavable, ISettingProvider
1016
{
1117
private static readonly Regex RegValidExpressChar = new Regex(
1218
@"^(" +
@@ -21,43 +27,58 @@ public class Main : IPlugin, IPluginI18n
2127
private static readonly Engine MagesEngine;
2228
private PluginInitContext Context { get; set; }
2329

30+
private static Settings _settings;
31+
private static SettingsViewModel _viewModel;
32+
2433
static Main()
2534
{
26-
MagesEngine = new Engine();
35+
MagesEngine = new Engine();
36+
}
37+
38+
public void Init(PluginInitContext context)
39+
{
40+
Context = context;
41+
42+
_viewModel = new SettingsViewModel();
43+
_settings = _viewModel.Settings;
2744
}
2845

2946
public List<Result> Query(Query query)
3047
{
31-
if (query.Search.Length <= 2 // don't affect when user only input "e" or "i" keyword
32-
|| !RegValidExpressChar.IsMatch(query.Search)
33-
|| !IsBracketComplete(query.Search)) return new List<Result>();
48+
if (!CanCalculate(query))
49+
{
50+
return new List<Result>();
51+
}
3452

3553
try
3654
{
37-
var result = MagesEngine.Interpret(query.Search);
55+
var expression = query.Search.Replace(",", ".");
56+
var result = MagesEngine.Interpret(expression);
3857

3958
if (result.ToString() == "NaN")
4059
result = Context.API.GetTranslation("wox_plugin_calculator_not_a_number");
4160

4261
if (result is Function)
4362
result = Context.API.GetTranslation("wox_plugin_calculator_expression_not_complete");
4463

45-
4664
if (!string.IsNullOrEmpty(result?.ToString()))
4765
{
66+
decimal roundedResult = Math.Round(Convert.ToDecimal(result), _settings.MaxDecimalPlaces, MidpointRounding.AwayFromZero);
67+
string newResult = ChangeDecimalSeparator(roundedResult, GetDecimalSeparator());
68+
4869
return new List<Result>
4970
{
5071
new Result
5172
{
52-
Title = result.ToString(),
73+
Title = newResult,
5374
IcoPath = "Images/calculator.png",
5475
Score = 300,
5576
SubTitle = Context.API.GetTranslation("wox_plugin_calculator_copy_number_to_clipboard"),
5677
Action = c =>
5778
{
5879
try
5980
{
60-
Clipboard.SetText(result.ToString());
81+
Clipboard.SetText(newResult);
6182
return true;
6283
}
6384
catch (ExternalException)
@@ -78,6 +99,53 @@ public List<Result> Query(Query query)
7899
return new List<Result>();
79100
}
80101

102+
private bool CanCalculate(Query query)
103+
{
104+
// Don't execute when user only input "e" or "i" keyword
105+
if (query.Search.Length < 2)
106+
{
107+
return false;
108+
}
109+
110+
if (!RegValidExpressChar.IsMatch(query.Search))
111+
{
112+
return false;
113+
}
114+
115+
if (!IsBracketComplete(query.Search))
116+
{
117+
return false;
118+
}
119+
120+
return true;
121+
}
122+
123+
private string ChangeDecimalSeparator(decimal value, string newDecimalSeparator)
124+
{
125+
if (String.IsNullOrEmpty(newDecimalSeparator))
126+
{
127+
return value.ToString();
128+
}
129+
130+
var numberFormatInfo = new NumberFormatInfo
131+
{
132+
NumberDecimalSeparator = newDecimalSeparator
133+
};
134+
return value.ToString(numberFormatInfo);
135+
}
136+
137+
private string GetDecimalSeparator()
138+
{
139+
string systemDecimalSeperator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
140+
switch (_settings.DecimalSeparator)
141+
{
142+
case DecimalSeparator.UseSystemLocale: return systemDecimalSeperator;
143+
case DecimalSeparator.Dot: return ".";
144+
case DecimalSeparator.Comma: return ",";
145+
default: return systemDecimalSeperator;
146+
}
147+
}
148+
81149
private bool IsBracketComplete(string query)
82150
{
83151
var matchs = RegBrackets.Matches(query);
@@ -96,12 +164,7 @@ private bool IsBracketComplete(string query)
96164

97165
return leftBracketCount == 0;
98166
}
99-
100-
public void Init(PluginInitContext context)
101-
{
102-
Context = context;
103-
}
104-
167+
105168
public string GetTranslatedPluginTitle()
106169
{
107170
return Context.API.GetTranslation("wox_plugin_caculator_plugin_name");
@@ -111,5 +174,15 @@ public string GetTranslatedPluginDescription()
111174
{
112175
return Context.API.GetTranslation("wox_plugin_caculator_plugin_description");
113176
}
177+
178+
public Control CreateSettingPanel()
179+
{
180+
return new CalculatorSettings(_viewModel);
181+
}
182+
183+
public void Save()
184+
{
185+
_viewModel.Save();
186+
}
114187
}
115188
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Wox.Plugin.Caculator
8+
{
9+
public class Settings
10+
{
11+
public DecimalSeparator DecimalSeparator { get; set; } = DecimalSeparator.UseSystemLocale;
12+
public int MaxDecimalPlaces { get; set; } = 10;
13+
}
14+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Wox.Infrastructure.Storage;
7+
using Wox.Infrastructure.UserSettings;
8+
9+
namespace Wox.Plugin.Caculator.ViewModels
10+
{
11+
public class SettingsViewModel : BaseModel, ISavable
12+
{
13+
private readonly PluginJsonStorage<Settings> _storage;
14+
15+
public SettingsViewModel()
16+
{
17+
_storage = new PluginJsonStorage<Settings>();
18+
Settings = _storage.Load();
19+
}
20+
21+
public Settings Settings { get; set; }
22+
23+
public IEnumerable<int> MaxDecimalPlacesRange => Enumerable.Range(1, 20);
24+
25+
public void Save()
26+
{
27+
_storage.Save();
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)