From 24fa234c9bb61cad0b927eccda608053e546b152 Mon Sep 17 00:00:00 2001 From: SysC0mp Date: Wed, 11 Dec 2019 19:42:10 +0100 Subject: [PATCH 01/21] Allow comma in input expression Calculator now supports a comma as decimal seperator. --- Plugins/Wox.Plugin.Calculator/Main.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Plugins/Wox.Plugin.Calculator/Main.cs b/Plugins/Wox.Plugin.Calculator/Main.cs index fab0b8e03..010ff0b6f 100644 --- a/Plugins/Wox.Plugin.Calculator/Main.cs +++ b/Plugins/Wox.Plugin.Calculator/Main.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text.RegularExpressions; using System.Windows; @@ -34,7 +34,8 @@ namespace Wox.Plugin.Caculator try { - var result = MagesEngine.Interpret(query.Search); + var expression = query.Search.Replace(",", "."); + var result = MagesEngine.Interpret(expression); if (result.ToString() == "NaN") result = Context.API.GetTranslation("wox_plugin_calculator_not_a_number"); From d204df2b18a0448b62d38ced7de44c81a89743e6 Mon Sep 17 00:00:00 2001 From: SysC0mp Date: Wed, 11 Dec 2019 19:42:27 +0100 Subject: [PATCH 02/21] Improve format --- Plugins/Wox.Plugin.Calculator/Main.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Plugins/Wox.Plugin.Calculator/Main.cs b/Plugins/Wox.Plugin.Calculator/Main.cs index 010ff0b6f..c8c7fcb0b 100644 --- a/Plugins/Wox.Plugin.Calculator/Main.cs +++ b/Plugins/Wox.Plugin.Calculator/Main.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text.RegularExpressions; using System.Windows; @@ -28,7 +28,8 @@ namespace Wox.Plugin.Caculator public List Query(Query query) { - if (query.Search.Length <= 2 // don't affect when user only input "e" or "i" keyword + // Don't affect when user only input "e" or "i" keyword + if (query.Search.Length <= 2 || !RegValidExpressChar.IsMatch(query.Search) || !IsBracketComplete(query.Search)) return new List(); @@ -43,7 +44,6 @@ namespace Wox.Plugin.Caculator if (result is Function) result = Context.API.GetTranslation("wox_plugin_calculator_expression_not_complete"); - if (!string.IsNullOrEmpty(result?.ToString())) { return new List From 2e714a8d7b91c9a73786389ac5903b2fa647f196 Mon Sep 17 00:00:00 2001 From: SysC0mp Date: Tue, 25 Feb 2020 17:38:47 +0100 Subject: [PATCH 03/21] Create localization helper classes --- Wox.Core/Resource/LocalizationConverter.cs | 37 +++++++++++++++++++ .../Resource/LocalizedDescriptionAttribute.cs | 27 ++++++++++++++ Wox.Core/Wox.Core.csproj | 2 + 3 files changed, 66 insertions(+) create mode 100644 Wox.Core/Resource/LocalizationConverter.cs create mode 100644 Wox.Core/Resource/LocalizedDescriptionAttribute.cs diff --git a/Wox.Core/Resource/LocalizationConverter.cs b/Wox.Core/Resource/LocalizationConverter.cs new file mode 100644 index 000000000..d86bf5f7e --- /dev/null +++ b/Wox.Core/Resource/LocalizationConverter.cs @@ -0,0 +1,37 @@ +using System; +using System.ComponentModel; +using System.Globalization; +using System.Reflection; +using System.Windows.Data; + +namespace Wox.Core +{ + public class LocalizationConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (targetType == typeof(string) && value != null) + { + FieldInfo fi = value.GetType().GetField(value.ToString()); + if (fi != null) + { + string localizedDescription = string.Empty; + var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false); + if ((attributes.Length > 0) && (!String.IsNullOrEmpty(attributes[0].Description))) + { + localizedDescription = attributes[0].Description; + } + + return (!String.IsNullOrEmpty(localizedDescription)) ? localizedDescription : value.ToString(); + } + } + + return string.Empty; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Wox.Core/Resource/LocalizedDescriptionAttribute.cs b/Wox.Core/Resource/LocalizedDescriptionAttribute.cs new file mode 100644 index 000000000..ef1257220 --- /dev/null +++ b/Wox.Core/Resource/LocalizedDescriptionAttribute.cs @@ -0,0 +1,27 @@ +using System.ComponentModel; +using Wox.Core.Resource; + +namespace Wox.Core +{ + public class LocalizedDescriptionAttribute : DescriptionAttribute + { + private readonly Internationalization _translator; + private readonly string _resourceKey; + + public LocalizedDescriptionAttribute(string resourceKey) + { + _translator = InternationalizationManager.Instance; + _resourceKey = resourceKey; + } + + public override string Description + { + get + { + string description = _translator.GetTranslation(_resourceKey); + return string.IsNullOrWhiteSpace(description) ? + string.Format("[[{0}]]", _resourceKey) : description; + } + } + } +} diff --git a/Wox.Core/Wox.Core.csproj b/Wox.Core/Wox.Core.csproj index 9d8f1e794..bec5a13a6 100644 --- a/Wox.Core/Wox.Core.csproj +++ b/Wox.Core/Wox.Core.csproj @@ -109,6 +109,8 @@ + + From 73a264b00d8cbbd58cc3f689e3ff22016e5f215e Mon Sep 17 00:00:00 2001 From: SysC0mp Date: Tue, 25 Feb 2020 17:43:12 +0100 Subject: [PATCH 04/21] Create DecimalSeperator enum Localization is handled using the LocalizedDescription attribute and the LocalizationConverter. --- .../Wox.Plugin.Calculator/DecimalSeparator.cs | 24 +++++++++++++++++++ .../Wox.Plugin.Calculator/Languages/de.xaml | 5 +++- .../Wox.Plugin.Calculator/Languages/en.xaml | 5 +++- .../Wox.Plugin.Calculator.csproj | 5 +++- 4 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 Plugins/Wox.Plugin.Calculator/DecimalSeparator.cs diff --git a/Plugins/Wox.Plugin.Calculator/DecimalSeparator.cs b/Plugins/Wox.Plugin.Calculator/DecimalSeparator.cs new file mode 100644 index 000000000..5aad9b39a --- /dev/null +++ b/Plugins/Wox.Plugin.Calculator/DecimalSeparator.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Wox.Core; + +namespace Wox.Plugin.Caculator +{ + [TypeConverter(typeof(LocalizationConverter))] + public enum DecimalSeparator + { + [LocalizedDescription("wox_plugin_calculator_decimal_seperator_use_system_locale")] + UseSystemLocale, + + [LocalizedDescription("wox_plugin_calculator_decimal_seperator_dot")] + Dot, + + [LocalizedDescription("wox_plugin_calculator_decimal_seperator_comma")] + Comma + } +} \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Calculator/Languages/de.xaml b/Plugins/Wox.Plugin.Calculator/Languages/de.xaml index 286e4bc9b..1f550de84 100644 --- a/Plugins/Wox.Plugin.Calculator/Languages/de.xaml +++ b/Plugins/Wox.Plugin.Calculator/Languages/de.xaml @@ -1,4 +1,4 @@ - @@ -7,4 +7,7 @@ Keine Zahl (NaN) Ausdruck falsch oder nicht vollständig (Klammern vergessen?) Diese Zahl in die Zwischenablage kopieren + Systemeinstellung nutzen + Komma (,) + Punkt (.) \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Calculator/Languages/en.xaml b/Plugins/Wox.Plugin.Calculator/Languages/en.xaml index 3b5fa32b3..0de9225b3 100644 --- a/Plugins/Wox.Plugin.Calculator/Languages/en.xaml +++ b/Plugins/Wox.Plugin.Calculator/Languages/en.xaml @@ -1,4 +1,4 @@ - @@ -7,4 +7,7 @@ Not a number (NaN) Expression wrong or incomplete (Did you forget some parentheses?) Copy this number to the clipboard + Use system locale + Comma (,) + Dot (.) \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Calculator/Wox.Plugin.Calculator.csproj b/Plugins/Wox.Plugin.Calculator/Wox.Plugin.Calculator.csproj index cf7ce1241..a257caed6 100644 --- a/Plugins/Wox.Plugin.Calculator/Wox.Plugin.Calculator.csproj +++ b/Plugins/Wox.Plugin.Calculator/Wox.Plugin.Calculator.csproj @@ -1,4 +1,4 @@ - + @@ -46,11 +46,14 @@ + + Properties\SolutionAssemblyInfo.cs + From b37669b77e50c937f84e2d211009428c696e0a53 Mon Sep 17 00:00:00 2001 From: SysC0mp Date: Tue, 25 Feb 2020 17:45:43 +0100 Subject: [PATCH 05/21] Create user control for Calculator settings --- .../Wox.Plugin.Calculator/Languages/de.xaml | 4 +- .../Wox.Plugin.Calculator/Languages/en.xaml | 4 +- Plugins/Wox.Plugin.Calculator/Settings.cs | 13 +++++ .../ViewModels/SettingsViewModel.cs | 28 +++++++++ .../Views/CalculatorSettings.xaml | 44 ++++++++++++++ .../Views/CalculatorSettings.xaml.cs | 42 ++++++++++++++ .../Wox.Plugin.Calculator.csproj | 17 +++++- Wox.Infrastructure/UI/EnumBindingSource.cs | 57 +++++++++++++++++++ Wox.Infrastructure/Wox.Infrastructure.csproj | 1 + 9 files changed, 207 insertions(+), 3 deletions(-) create mode 100644 Plugins/Wox.Plugin.Calculator/Settings.cs create mode 100644 Plugins/Wox.Plugin.Calculator/ViewModels/SettingsViewModel.cs create mode 100644 Plugins/Wox.Plugin.Calculator/Views/CalculatorSettings.xaml create mode 100644 Plugins/Wox.Plugin.Calculator/Views/CalculatorSettings.xaml.cs create mode 100644 Wox.Infrastructure/UI/EnumBindingSource.cs diff --git a/Plugins/Wox.Plugin.Calculator/Languages/de.xaml b/Plugins/Wox.Plugin.Calculator/Languages/de.xaml index 1f550de84..f5f1b27b5 100644 --- a/Plugins/Wox.Plugin.Calculator/Languages/de.xaml +++ b/Plugins/Wox.Plugin.Calculator/Languages/de.xaml @@ -1,4 +1,4 @@ - @@ -7,6 +7,8 @@ Keine Zahl (NaN) Ausdruck falsch oder nicht vollständig (Klammern vergessen?) Diese Zahl in die Zwischenablage kopieren + Dezimaltrennzeichen + Das Dezimaltrennzeichen, welches bei der Ausgabe verwendet werden soll. Systemeinstellung nutzen Komma (,) Punkt (.) diff --git a/Plugins/Wox.Plugin.Calculator/Languages/en.xaml b/Plugins/Wox.Plugin.Calculator/Languages/en.xaml index 0de9225b3..e214919d1 100644 --- a/Plugins/Wox.Plugin.Calculator/Languages/en.xaml +++ b/Plugins/Wox.Plugin.Calculator/Languages/en.xaml @@ -1,4 +1,4 @@ - @@ -7,6 +7,8 @@ Not a number (NaN) Expression wrong or incomplete (Did you forget some parentheses?) Copy this number to the clipboard + Decimal separator + The decimal separator to be used in the output. Use system locale Comma (,) Dot (.) diff --git a/Plugins/Wox.Plugin.Calculator/Settings.cs b/Plugins/Wox.Plugin.Calculator/Settings.cs new file mode 100644 index 000000000..a45405b29 --- /dev/null +++ b/Plugins/Wox.Plugin.Calculator/Settings.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Wox.Plugin.Caculator +{ + public class Settings + { + public DecimalSeparator DecimalSeparator { get; set; } = DecimalSeparator.UseSystemLocale; + } +} diff --git a/Plugins/Wox.Plugin.Calculator/ViewModels/SettingsViewModel.cs b/Plugins/Wox.Plugin.Calculator/ViewModels/SettingsViewModel.cs new file mode 100644 index 000000000..e06ad675c --- /dev/null +++ b/Plugins/Wox.Plugin.Calculator/ViewModels/SettingsViewModel.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Wox.Infrastructure.Storage; +using Wox.Infrastructure.UserSettings; + +namespace Wox.Plugin.Caculator.ViewModels +{ + public class SettingsViewModel : BaseModel, ISavable + { + private readonly PluginJsonStorage _storage; + + public SettingsViewModel() + { + _storage = new PluginJsonStorage(); + Settings = _storage.Load(); + } + + public Settings Settings { get; set; } + + public void Save() + { + _storage.Save(); + } + } +} diff --git a/Plugins/Wox.Plugin.Calculator/Views/CalculatorSettings.xaml b/Plugins/Wox.Plugin.Calculator/Views/CalculatorSettings.xaml new file mode 100644 index 000000000..b9404710d --- /dev/null +++ b/Plugins/Wox.Plugin.Calculator/Views/CalculatorSettings.xaml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Plugins/Wox.Plugin.Calculator/Views/CalculatorSettings.xaml.cs b/Plugins/Wox.Plugin.Calculator/Views/CalculatorSettings.xaml.cs new file mode 100644 index 000000000..c002243c5 --- /dev/null +++ b/Plugins/Wox.Plugin.Calculator/Views/CalculatorSettings.xaml.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using Wox.Plugin.Caculator.ViewModels; + +namespace Wox.Plugin.Caculator.Views +{ + /// + /// Interaction logic for CalculatorSettings.xaml + /// + public partial class CalculatorSettings : UserControl + { + private SettingsViewModel _viewModel; + private Settings _settings; + + public CalculatorSettings(SettingsViewModel viewModel) + { + _viewModel = viewModel; + _settings = viewModel.Settings; + DataContext = viewModel; + InitializeComponent(); + } + + private void CalculatorSettings_Loaded(object sender, RoutedEventArgs e) + { + DecimalSeparatorComboBox.SelectedItem = _settings.DecimalSeparator; + } + } + + +} diff --git a/Plugins/Wox.Plugin.Calculator/Wox.Plugin.Calculator.csproj b/Plugins/Wox.Plugin.Calculator/Wox.Plugin.Calculator.csproj index a257caed6..4f7590273 100644 --- a/Plugins/Wox.Plugin.Calculator/Wox.Plugin.Calculator.csproj +++ b/Plugins/Wox.Plugin.Calculator/Wox.Plugin.Calculator.csproj @@ -1,4 +1,4 @@ - + @@ -57,6 +57,11 @@ + + + + CalculatorSettings.xaml + @@ -65,6 +70,10 @@ + + {B749F0DB-8E75-47DB-9E5E-265D16D0C0D2} + Wox.Core + {4FD29318-A8AB-4D8F-AA47-60BC241B8DA3} Wox.Infrastructure @@ -121,6 +130,12 @@ PreserveNewest + + + Designer + MSBuild:Compile + + diff --git a/Wox.Infrastructure/UI/EnumBindingSource.cs b/Wox.Infrastructure/UI/EnumBindingSource.cs new file mode 100644 index 000000000..c23aacd81 --- /dev/null +++ b/Wox.Infrastructure/UI/EnumBindingSource.cs @@ -0,0 +1,57 @@ +using System; +using System.Windows.Markup; + +namespace Wox.Infrastructure.UI +{ + public class EnumBindingSourceExtension : MarkupExtension + { + private Type _enumType; + public Type EnumType + { + get { return _enumType; } + set + { + if (value != _enumType) + { + if (value != null) + { + Type enumType = Nullable.GetUnderlyingType(value) ?? value; + if (!enumType.IsEnum) + { + throw new ArgumentException("Type must represent an enum."); + } + } + + _enumType = value; + } + } + } + + public EnumBindingSourceExtension() { } + + public EnumBindingSourceExtension(Type enumType) + { + EnumType = enumType; + } + + public override object ProvideValue(IServiceProvider serviceProvider) + { + if (_enumType == null) + { + throw new InvalidOperationException("The EnumType must be specified."); + } + + Type actualEnumType = Nullable.GetUnderlyingType(_enumType) ?? _enumType; + Array enumValues = Enum.GetValues(actualEnumType); + + if (actualEnumType == _enumType) + { + return enumValues; + } + + Array tempArray = Array.CreateInstance(actualEnumType, enumValues.Length + 1); + enumValues.CopyTo(tempArray, 1); + return tempArray; + } + } +} diff --git a/Wox.Infrastructure/Wox.Infrastructure.csproj b/Wox.Infrastructure/Wox.Infrastructure.csproj index af76894ed..ab8976fb8 100644 --- a/Wox.Infrastructure/Wox.Infrastructure.csproj +++ b/Wox.Infrastructure/Wox.Infrastructure.csproj @@ -87,6 +87,7 @@ + From 3d3d9435dc35201f4e17c92dc5e2e156cb284375 Mon Sep 17 00:00:00 2001 From: SysC0mp Date: Tue, 25 Feb 2020 17:48:18 +0100 Subject: [PATCH 06/21] Set minimum expression lenght to 2 Calculations like 8! haven't been possible before due to a validation on the minimum query lenght. --- Plugins/Wox.Plugin.Calculator/Main.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Plugins/Wox.Plugin.Calculator/Main.cs b/Plugins/Wox.Plugin.Calculator/Main.cs index c8c7fcb0b..113240c5e 100644 --- a/Plugins/Wox.Plugin.Calculator/Main.cs +++ b/Plugins/Wox.Plugin.Calculator/Main.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text.RegularExpressions; using System.Windows; @@ -29,9 +29,12 @@ namespace Wox.Plugin.Caculator public List Query(Query query) { // Don't affect when user only input "e" or "i" keyword - if (query.Search.Length <= 2 + if (query.Search.Length < 2 || !RegValidExpressChar.IsMatch(query.Search) - || !IsBracketComplete(query.Search)) return new List(); + || !IsBracketComplete(query.Search)) + { + return new List(); + } try { From 570c1d9a5f027d12fde127966b9bda083aa916e8 Mon Sep 17 00:00:00 2001 From: SysC0mp Date: Tue, 25 Feb 2020 17:50:50 +0100 Subject: [PATCH 07/21] Integrate calculator settings Save & load settings when plugin is in use & specify user control. --- Plugins/Wox.Plugin.Calculator/Main.cs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/Plugins/Wox.Plugin.Calculator/Main.cs b/Plugins/Wox.Plugin.Calculator/Main.cs index 113240c5e..9ebdd36c1 100644 --- a/Plugins/Wox.Plugin.Calculator/Main.cs +++ b/Plugins/Wox.Plugin.Calculator/Main.cs @@ -2,11 +2,15 @@ using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text.RegularExpressions; using System.Windows; +using System.Windows.Controls; using Mages.Core; +using Wox.Infrastructure.Storage; +using Wox.Plugin.Caculator.ViewModels; +using Wox.Plugin.Caculator.Views; namespace Wox.Plugin.Caculator { - public class Main : IPlugin, IPluginI18n + public class Main : IPlugin, IPluginI18n, ISavable, ISettingProvider { private static readonly Regex RegValidExpressChar = new Regex( @"^(" + @@ -21,11 +25,22 @@ namespace Wox.Plugin.Caculator private static readonly Engine MagesEngine; private PluginInitContext Context { get; set; } + private static Settings _settings; + private static SettingsViewModel _viewModel; + static Main() { MagesEngine = new Engine(); } + public void Init(PluginInitContext context) + { + Context = context; + + _viewModel = new SettingsViewModel(); + _settings = _viewModel.Settings; + } + public List Query(Query query) { // Don't affect when user only input "e" or "i" keyword @@ -115,5 +130,15 @@ namespace Wox.Plugin.Caculator { return Context.API.GetTranslation("wox_plugin_caculator_plugin_description"); } + + public Control CreateSettingPanel() + { + return new CalculatorSettings(_viewModel); + } + + public void Save() + { + _viewModel.Save(); + } } } From 5ae3262279f13df92c3a0dda6e3602abefd2cad8 Mon Sep 17 00:00:00 2001 From: SysC0mp Date: Tue, 25 Feb 2020 17:53:18 +0100 Subject: [PATCH 08/21] Adjust decimal separator based on setting The output decimal separator selected will be used for the output. The input can also handle comma and dot as separator now. --- Plugins/Wox.Plugin.Calculator/Main.cs | 41 ++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/Plugins/Wox.Plugin.Calculator/Main.cs b/Plugins/Wox.Plugin.Calculator/Main.cs index 9ebdd36c1..78ccfcac6 100644 --- a/Plugins/Wox.Plugin.Calculator/Main.cs +++ b/Plugins/Wox.Plugin.Calculator/Main.cs @@ -64,11 +64,12 @@ namespace Wox.Plugin.Caculator if (!string.IsNullOrEmpty(result?.ToString())) { + string newResult = ChangeDecimalSeparator(result, GetDecimalSeparator()); return new List { new Result { - Title = result.ToString(), + Title = newResult, IcoPath = "Images/calculator.png", Score = 300, SubTitle = Context.API.GetTranslation("wox_plugin_calculator_copy_number_to_clipboard"), @@ -76,7 +77,7 @@ namespace Wox.Plugin.Caculator { try { - Clipboard.SetText(result.ToString()); + Clipboard.SetText(newResult); return true; } catch (ExternalException) @@ -97,6 +98,37 @@ namespace Wox.Plugin.Caculator return new List(); } + private string ChangeDecimalSeparator(object value, string newDecimalSeparator) + { + if (value == null || String.IsNullOrEmpty(value.ToString())) + { + return string.Empty; + } + + if (String.IsNullOrEmpty(newDecimalSeparator)) + { + return value.ToString(); + } + + var numberFormatInfo = new NumberFormatInfo + { + NumberDecimalSeparator = newDecimalSeparator + }; + return Convert.ToDecimal(value).ToString(numberFormatInfo); + } + + private string GetDecimalSeparator() + { + string systemDecimalSeperator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator; + switch (_settings.DecimalSeparator) + { + case DecimalSeparator.UseSystemLocale: return systemDecimalSeperator; + case DecimalSeparator.Dot: return "."; + case DecimalSeparator.Comma: return ","; + default: return systemDecimalSeperator; + } + } + private bool IsBracketComplete(string query) { var matchs = RegBrackets.Matches(query); @@ -116,11 +148,6 @@ namespace Wox.Plugin.Caculator return leftBracketCount == 0; } - public void Init(PluginInitContext context) - { - Context = context; - } - public string GetTranslatedPluginTitle() { return Context.API.GetTranslation("wox_plugin_caculator_plugin_name"); From 4f4e423a4bf3e7880f58361a33c816db2f376a3c Mon Sep 17 00:00:00 2001 From: SysC0mp Date: Tue, 25 Feb 2020 17:55:04 +0100 Subject: [PATCH 09/21] Add missing using directives --- Plugins/Wox.Plugin.Calculator/Main.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Plugins/Wox.Plugin.Calculator/Main.cs b/Plugins/Wox.Plugin.Calculator/Main.cs index 78ccfcac6..db3016fad 100644 --- a/Plugins/Wox.Plugin.Calculator/Main.cs +++ b/Plugins/Wox.Plugin.Calculator/Main.cs @@ -1,4 +1,6 @@ +using System; using System.Collections.Generic; +using System.Globalization; using System.Runtime.InteropServices; using System.Text.RegularExpressions; using System.Windows; @@ -30,9 +32,9 @@ namespace Wox.Plugin.Caculator static Main() { - MagesEngine = new Engine(); + MagesEngine = new Engine(); } - + public void Init(PluginInitContext context) { Context = context; @@ -147,7 +149,7 @@ namespace Wox.Plugin.Caculator return leftBracketCount == 0; } - + public string GetTranslatedPluginTitle() { return Context.API.GetTranslation("wox_plugin_caculator_plugin_name"); From 3d917e02581ffc6df6c5449d7c1344071230f899 Mon Sep 17 00:00:00 2001 From: SysC0mp Date: Wed, 26 Feb 2020 19:40:20 +0100 Subject: [PATCH 10/21] Extract validation to method --- Plugins/Wox.Plugin.Calculator/Main.cs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/Plugins/Wox.Plugin.Calculator/Main.cs b/Plugins/Wox.Plugin.Calculator/Main.cs index db3016fad..5d7b347d1 100644 --- a/Plugins/Wox.Plugin.Calculator/Main.cs +++ b/Plugins/Wox.Plugin.Calculator/Main.cs @@ -45,10 +45,7 @@ namespace Wox.Plugin.Caculator public List Query(Query query) { - // Don't affect when user only input "e" or "i" keyword - if (query.Search.Length < 2 - || !RegValidExpressChar.IsMatch(query.Search) - || !IsBracketComplete(query.Search)) + if (!CanCalculate(query)) { return new List(); } @@ -100,6 +97,27 @@ namespace Wox.Plugin.Caculator return new List(); } + private bool CanCalculate(Query query) + { + // Don't execute when user only input "e" or "i" keyword + if (query.Search.Length < 2) + { + return false; + } + + if (!RegValidExpressChar.IsMatch(query.Search)) + { + return false; + } + + if (!IsBracketComplete(query.Search)) + { + return false; + } + + return true; + } + private string ChangeDecimalSeparator(object value, string newDecimalSeparator) { if (value == null || String.IsNullOrEmpty(value.ToString())) From 54191d6d88bb812aeb6c46228d3f0a61f855b568 Mon Sep 17 00:00:00 2001 From: SysC0mp Date: Wed, 26 Feb 2020 20:00:07 +0100 Subject: [PATCH 11/21] Replace static text with localized label --- .../Views/CalculatorSettings.xaml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Plugins/Wox.Plugin.Calculator/Views/CalculatorSettings.xaml b/Plugins/Wox.Plugin.Calculator/Views/CalculatorSettings.xaml index b9404710d..a02fdffec 100644 --- a/Plugins/Wox.Plugin.Calculator/Views/CalculatorSettings.xaml +++ b/Plugins/Wox.Plugin.Calculator/Views/CalculatorSettings.xaml @@ -26,13 +26,14 @@ - + + Grid.Row="0" + x:Name="DecimalSeparatorComboBox" + Width="200" + HorizontalAlignment="Left" + SelectedItem="{Binding Settings.DecimalSeparator}" + ItemsSource="{Binding Source={ui:EnumBindingSource {x:Type calculator:DecimalSeparator}}}"> From f18256ab398e480e203cd9b8ae9c7e99459af224 Mon Sep 17 00:00:00 2001 From: SysC0mp Date: Wed, 26 Feb 2020 20:46:27 +0100 Subject: [PATCH 12/21] Add "Max. decimal places" setting --- Plugins/Wox.Plugin.Calculator/Settings.cs | 1 + .../ViewModels/SettingsViewModel.cs | 2 ++ .../Views/CalculatorSettings.xaml | 25 +++++++++++++------ .../Views/CalculatorSettings.xaml.cs | 5 ++-- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Plugins/Wox.Plugin.Calculator/Settings.cs b/Plugins/Wox.Plugin.Calculator/Settings.cs index a45405b29..ce01f2da0 100644 --- a/Plugins/Wox.Plugin.Calculator/Settings.cs +++ b/Plugins/Wox.Plugin.Calculator/Settings.cs @@ -9,5 +9,6 @@ namespace Wox.Plugin.Caculator public class Settings { public DecimalSeparator DecimalSeparator { get; set; } = DecimalSeparator.UseSystemLocale; + public int MaxDecimalPlaces { get; set; } = 10; } } diff --git a/Plugins/Wox.Plugin.Calculator/ViewModels/SettingsViewModel.cs b/Plugins/Wox.Plugin.Calculator/ViewModels/SettingsViewModel.cs index e06ad675c..8550f47a5 100644 --- a/Plugins/Wox.Plugin.Calculator/ViewModels/SettingsViewModel.cs +++ b/Plugins/Wox.Plugin.Calculator/ViewModels/SettingsViewModel.cs @@ -20,6 +20,8 @@ namespace Wox.Plugin.Caculator.ViewModels public Settings Settings { get; set; } + public IEnumerable MaxDecimalPlacesRange => Enumerable.Range(1, 20); + public void Save() { _storage.Save(); diff --git a/Plugins/Wox.Plugin.Calculator/Views/CalculatorSettings.xaml b/Plugins/Wox.Plugin.Calculator/Views/CalculatorSettings.xaml index a02fdffec..0cb21c550 100644 --- a/Plugins/Wox.Plugin.Calculator/Views/CalculatorSettings.xaml +++ b/Plugins/Wox.Plugin.Calculator/Views/CalculatorSettings.xaml @@ -3,11 +3,10 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:local="clr-namespace:Wox.Plugin.Caculator.Views" - xmlns:infrastructure="clr-namespace:Wox.Infrastructure;assembly=Wox.Infrastructure" xmlns:ui="clr-namespace:Wox.Infrastructure.UI;assembly=Wox.Infrastructure" xmlns:calculator="clr-namespace:Wox.Plugin.Caculator" xmlns:core="clr-namespace:Wox.Core;assembly=Wox.Core" + xmlns:viewModels="clr-namespace:Wox.Plugin.Caculator.ViewModels" mc:Ignorable="d" Loaded="CalculatorSettings_Loaded" d:DesignHeight="450" d:DesignWidth="800"> @@ -19,18 +18,19 @@ - + + - + - @@ -40,6 +40,17 @@ + + + + + diff --git a/Plugins/Wox.Plugin.Calculator/Views/CalculatorSettings.xaml.cs b/Plugins/Wox.Plugin.Calculator/Views/CalculatorSettings.xaml.cs index c002243c5..c15bdda77 100644 --- a/Plugins/Wox.Plugin.Calculator/Views/CalculatorSettings.xaml.cs +++ b/Plugins/Wox.Plugin.Calculator/Views/CalculatorSettings.xaml.cs @@ -21,8 +21,8 @@ namespace Wox.Plugin.Caculator.Views /// public partial class CalculatorSettings : UserControl { - private SettingsViewModel _viewModel; - private Settings _settings; + private readonly SettingsViewModel _viewModel; + private readonly Settings _settings; public CalculatorSettings(SettingsViewModel viewModel) { @@ -35,6 +35,7 @@ namespace Wox.Plugin.Caculator.Views private void CalculatorSettings_Loaded(object sender, RoutedEventArgs e) { DecimalSeparatorComboBox.SelectedItem = _settings.DecimalSeparator; + MaxDecimalPlaces.SelectedItem = _settings.MaxDecimalPlaces; } } From 0933eab4b0c1243c3d63fc714ff48f2bbb524d44 Mon Sep 17 00:00:00 2001 From: SysC0mp Date: Wed, 26 Feb 2020 20:46:47 +0100 Subject: [PATCH 13/21] Update Mages version --- Plugins/Wox.Plugin.Calculator/Wox.Plugin.Calculator.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Wox.Plugin.Calculator/Wox.Plugin.Calculator.csproj b/Plugins/Wox.Plugin.Calculator/Wox.Plugin.Calculator.csproj index c682cd19a..f24ad118e 100644 --- a/Plugins/Wox.Plugin.Calculator/Wox.Plugin.Calculator.csproj +++ b/Plugins/Wox.Plugin.Calculator/Wox.Plugin.Calculator.csproj @@ -134,7 +134,7 @@ 10.3.0 - 1.5.0 + 1.6.0 4.0.0 From cc743aeeeaadfd8fa11a57b0b8070849d258d3a6 Mon Sep 17 00:00:00 2001 From: SysC0mp Date: Wed, 26 Feb 2020 20:47:14 +0100 Subject: [PATCH 14/21] Round result using new introduced setting --- Plugins/Wox.Plugin.Calculator/Main.cs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Plugins/Wox.Plugin.Calculator/Main.cs b/Plugins/Wox.Plugin.Calculator/Main.cs index 5d7b347d1..f2f7f7e18 100644 --- a/Plugins/Wox.Plugin.Calculator/Main.cs +++ b/Plugins/Wox.Plugin.Calculator/Main.cs @@ -63,7 +63,9 @@ namespace Wox.Plugin.Caculator if (!string.IsNullOrEmpty(result?.ToString())) { - string newResult = ChangeDecimalSeparator(result, GetDecimalSeparator()); + decimal roundedResult = Math.Round(Convert.ToDecimal(result), _settings.MaxDecimalPlaces, MidpointRounding.AwayFromZero); + string newResult = ChangeDecimalSeparator(roundedResult, GetDecimalSeparator()); + return new List { new Result @@ -118,13 +120,8 @@ namespace Wox.Plugin.Caculator return true; } - private string ChangeDecimalSeparator(object value, string newDecimalSeparator) + private string ChangeDecimalSeparator(decimal value, string newDecimalSeparator) { - if (value == null || String.IsNullOrEmpty(value.ToString())) - { - return string.Empty; - } - if (String.IsNullOrEmpty(newDecimalSeparator)) { return value.ToString(); @@ -134,7 +131,7 @@ namespace Wox.Plugin.Caculator { NumberDecimalSeparator = newDecimalSeparator }; - return Convert.ToDecimal(value).ToString(numberFormatInfo); + return value.ToString(numberFormatInfo); } private string GetDecimalSeparator() From 9d447ca63fd0628d8aa95d1e9dcbb717d14c790e Mon Sep 17 00:00:00 2001 From: SysC0mp Date: Wed, 26 Feb 2020 20:49:39 +0100 Subject: [PATCH 15/21] Replace static text with localized label --- Plugins/Wox.Plugin.Calculator/Languages/de.xaml | 1 + Plugins/Wox.Plugin.Calculator/Languages/en.xaml | 1 + Plugins/Wox.Plugin.Calculator/Views/CalculatorSettings.xaml | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Plugins/Wox.Plugin.Calculator/Languages/de.xaml b/Plugins/Wox.Plugin.Calculator/Languages/de.xaml index f5f1b27b5..eb6847af0 100644 --- a/Plugins/Wox.Plugin.Calculator/Languages/de.xaml +++ b/Plugins/Wox.Plugin.Calculator/Languages/de.xaml @@ -12,4 +12,5 @@ Systemeinstellung nutzen Komma (,) Punkt (.) + Max. Nachkommastellen \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Calculator/Languages/en.xaml b/Plugins/Wox.Plugin.Calculator/Languages/en.xaml index e214919d1..0df0d3342 100644 --- a/Plugins/Wox.Plugin.Calculator/Languages/en.xaml +++ b/Plugins/Wox.Plugin.Calculator/Languages/en.xaml @@ -12,4 +12,5 @@ Use system locale Comma (,) Dot (.) + Max. decimal places \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Calculator/Views/CalculatorSettings.xaml b/Plugins/Wox.Plugin.Calculator/Views/CalculatorSettings.xaml index 0cb21c550..183f10e5f 100644 --- a/Plugins/Wox.Plugin.Calculator/Views/CalculatorSettings.xaml +++ b/Plugins/Wox.Plugin.Calculator/Views/CalculatorSettings.xaml @@ -41,7 +41,7 @@ - + Date: Tue, 10 Mar 2020 18:35:31 +1100 Subject: [PATCH 16/21] Remove UwpDesktop library dependency and upgrade to framework 4.6.2 (#159) * Remove UwpDesktop dependency of lower sdk and add Win SDK Contracts * Upgrade from .Net Framework 4.5.2 to 4.6.2 This upgrade is needed to use Microsoft Windows SDK Contracts library from previous commit * Remove Windows SDK references as no longer required --- Plugins/HelloWorldCSharp/App.config | 6 +++--- Plugins/HelloWorldCSharp/HelloWorldCSharp.csproj | 3 ++- .../Wox.Plugin.BrowserBookmark.csproj | 2 +- Plugins/Wox.Plugin.BrowserBookmark/app.config | 14 +++++++------- .../Wox.Plugin.Calculator.csproj | 2 +- Plugins/Wox.Plugin.Color/Wox.Plugin.Color.csproj | 2 +- .../Wox.Plugin.ControlPanel.csproj | 2 +- .../Wox.Plugin.Everything.csproj | 2 +- Plugins/Wox.Plugin.Folder/Wox.Plugin.Folder.csproj | 2 +- .../Wox.Plugin.PluginIndicator.csproj | 2 +- .../Wox.Plugin.PluginManagement.csproj | 2 +- .../Wox.Plugin.Program/Wox.Plugin.Program.csproj | 8 ++++---- Plugins/Wox.Plugin.Shell/Wox.Plugin.Shell.csproj | 2 +- Plugins/Wox.Plugin.Sys/Wox.Plugin.Sys.csproj | 2 +- Plugins/Wox.Plugin.Url/Wox.Plugin.Url.csproj | 2 +- .../Wox.Plugin.WebSearch.csproj | 2 +- README.md | 12 +----------- Wox.Core/Wox.Core.csproj | 2 +- Wox.Infrastructure/Wox.Infrastructure.csproj | 2 +- Wox.Plugin/Wox.Plugin.csproj | 2 +- Wox.Test/Wox.Test.csproj | 2 +- Wox/App.config | 8 ++++---- Wox/Properties/Resources.Designer.cs | 2 +- Wox/Properties/Settings.Designer.cs | 2 +- Wox/Wox.csproj | 2 +- 25 files changed, 40 insertions(+), 49 deletions(-) diff --git a/Plugins/HelloWorldCSharp/App.config b/Plugins/HelloWorldCSharp/App.config index 88fa4027b..8d234373a 100644 --- a/Plugins/HelloWorldCSharp/App.config +++ b/Plugins/HelloWorldCSharp/App.config @@ -1,6 +1,6 @@ - + - + - \ No newline at end of file + diff --git a/Plugins/HelloWorldCSharp/HelloWorldCSharp.csproj b/Plugins/HelloWorldCSharp/HelloWorldCSharp.csproj index 46006f098..143052a03 100644 --- a/Plugins/HelloWorldCSharp/HelloWorldCSharp.csproj +++ b/Plugins/HelloWorldCSharp/HelloWorldCSharp.csproj @@ -9,9 +9,10 @@ Properties HelloWorldCSharp HelloWorldCSharp - v4.5.2 + v4.6.2 512 true + AnyCPU diff --git a/Plugins/Wox.Plugin.BrowserBookmark/Wox.Plugin.BrowserBookmark.csproj b/Plugins/Wox.Plugin.BrowserBookmark/Wox.Plugin.BrowserBookmark.csproj index 413b0aec7..56456892d 100644 --- a/Plugins/Wox.Plugin.BrowserBookmark/Wox.Plugin.BrowserBookmark.csproj +++ b/Plugins/Wox.Plugin.BrowserBookmark/Wox.Plugin.BrowserBookmark.csproj @@ -9,7 +9,7 @@ Properties Wox.Plugin.BrowserBookmark Wox.Plugin.BrowserBookmark - v4.5.2 + v4.6.2 512 ..\..\ true diff --git a/Plugins/Wox.Plugin.BrowserBookmark/app.config b/Plugins/Wox.Plugin.BrowserBookmark/app.config index 376ff2d53..3b7c7ed0a 100644 --- a/Plugins/Wox.Plugin.BrowserBookmark/app.config +++ b/Plugins/Wox.Plugin.BrowserBookmark/app.config @@ -1,22 +1,22 @@ - + -
+
- + - + - - + + - \ No newline at end of file + diff --git a/Plugins/Wox.Plugin.Calculator/Wox.Plugin.Calculator.csproj b/Plugins/Wox.Plugin.Calculator/Wox.Plugin.Calculator.csproj index f24ad118e..06d476ef4 100644 --- a/Plugins/Wox.Plugin.Calculator/Wox.Plugin.Calculator.csproj +++ b/Plugins/Wox.Plugin.Calculator/Wox.Plugin.Calculator.csproj @@ -9,7 +9,7 @@ Properties Wox.Plugin.Caculator Wox.Plugin.Caculator - v4.5.2 + v4.6.2 512 ..\..\ diff --git a/Plugins/Wox.Plugin.Color/Wox.Plugin.Color.csproj b/Plugins/Wox.Plugin.Color/Wox.Plugin.Color.csproj index ca75ed8f3..c7cbc29e5 100644 --- a/Plugins/Wox.Plugin.Color/Wox.Plugin.Color.csproj +++ b/Plugins/Wox.Plugin.Color/Wox.Plugin.Color.csproj @@ -9,7 +9,7 @@ Properties Wox.Plugin.Color Wox.Plugin.Color - v4.5.2 + v4.6.2 512 diff --git a/Plugins/Wox.Plugin.ControlPanel/Wox.Plugin.ControlPanel.csproj b/Plugins/Wox.Plugin.ControlPanel/Wox.Plugin.ControlPanel.csproj index 711cb8e29..97cdc8c02 100644 --- a/Plugins/Wox.Plugin.ControlPanel/Wox.Plugin.ControlPanel.csproj +++ b/Plugins/Wox.Plugin.ControlPanel/Wox.Plugin.ControlPanel.csproj @@ -9,7 +9,7 @@ Properties Wox.Plugin.ControlPanel Wox.Plugin.ControlPanel - v4.5.2 + v4.6.2 512 diff --git a/Plugins/Wox.Plugin.Everything/Wox.Plugin.Everything.csproj b/Plugins/Wox.Plugin.Everything/Wox.Plugin.Everything.csproj index 2ec791bf8..65f4e45e5 100644 --- a/Plugins/Wox.Plugin.Everything/Wox.Plugin.Everything.csproj +++ b/Plugins/Wox.Plugin.Everything/Wox.Plugin.Everything.csproj @@ -9,7 +9,7 @@ Properties Wox.Plugin.Everything Wox.Plugin.Everything - v4.5.2 + v4.6.2 512 ..\Wox\ diff --git a/Plugins/Wox.Plugin.Folder/Wox.Plugin.Folder.csproj b/Plugins/Wox.Plugin.Folder/Wox.Plugin.Folder.csproj index a75fa0ba9..338e550d5 100644 --- a/Plugins/Wox.Plugin.Folder/Wox.Plugin.Folder.csproj +++ b/Plugins/Wox.Plugin.Folder/Wox.Plugin.Folder.csproj @@ -9,7 +9,7 @@ Properties Wox.Plugin.Folder Wox.Plugin.Folder - v4.5.2 + v4.6.2 512 ..\..\ diff --git a/Plugins/Wox.Plugin.PluginIndicator/Wox.Plugin.PluginIndicator.csproj b/Plugins/Wox.Plugin.PluginIndicator/Wox.Plugin.PluginIndicator.csproj index 709016b06..2de1309cd 100644 --- a/Plugins/Wox.Plugin.PluginIndicator/Wox.Plugin.PluginIndicator.csproj +++ b/Plugins/Wox.Plugin.PluginIndicator/Wox.Plugin.PluginIndicator.csproj @@ -9,7 +9,7 @@ Properties Wox.Plugin.PluginIndicator Wox.Plugin.PluginIndicator - v4.5.2 + v4.6.2 512 diff --git a/Plugins/Wox.Plugin.PluginManagement/Wox.Plugin.PluginManagement.csproj b/Plugins/Wox.Plugin.PluginManagement/Wox.Plugin.PluginManagement.csproj index d963ea367..dcf77f487 100644 --- a/Plugins/Wox.Plugin.PluginManagement/Wox.Plugin.PluginManagement.csproj +++ b/Plugins/Wox.Plugin.PluginManagement/Wox.Plugin.PluginManagement.csproj @@ -9,7 +9,7 @@ Properties Wox.Plugin.PluginManagement Wox.Plugin.PluginManagement - v4.5.2 + v4.6.2 512 ..\..\ diff --git a/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj b/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj index 17ccffaba..a5d7700e1 100644 --- a/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj +++ b/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj @@ -9,7 +9,7 @@ Properties Wox.Plugin.Program Wox.Plugin.Program - v4.5.2 + v4.6.2 512 ..\..\ @@ -158,6 +158,9 @@ 10.3.0 + + 10.0.18362.2005 + 9.0.1 @@ -167,9 +170,6 @@ 4.0.0 - - 10.0.14393.3 - - -
+ +
@@ -16,4 +16,4 @@ - \ No newline at end of file + diff --git a/Wox/Properties/Resources.Designer.cs b/Wox/Properties/Resources.Designer.cs index 20e0fb225..26a9ddff9 100644 --- a/Wox/Properties/Resources.Designer.cs +++ b/Wox/Properties/Resources.Designer.cs @@ -19,7 +19,7 @@ namespace Wox.Properties { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { diff --git a/Wox/Properties/Settings.Designer.cs b/Wox/Properties/Settings.Designer.cs index a61339f5e..be9020f6e 100644 --- a/Wox/Properties/Settings.Designer.cs +++ b/Wox/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace Wox.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.3.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.4.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); diff --git a/Wox/Wox.csproj b/Wox/Wox.csproj index 3b942ca65..0aa060ddd 100644 --- a/Wox/Wox.csproj +++ b/Wox/Wox.csproj @@ -9,7 +9,7 @@ Properties Wox Wox - v4.5.2 + v4.6.2 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 From 37149d99563e559ef1bfdbb86658fedd327f1b24 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Thu, 12 Mar 2020 09:57:36 +1100 Subject: [PATCH 17/21] Reduce Wox's drain on CPU when using Pinyin search (#162) * Remove this unneccessary dreadful logging that kills performance * Update to ShouldUsePinyin option 1. Change default start up not to use Pinyin as default language is English 2. Add prompt when switching to Chinese or Chinese_TW prompt user if they want to use Pinyin search --- Wox.Core/Resource/Internationalization.cs | 16 ++++++++++++ Wox.Infrastructure/Alphabet.cs | 2 +- Wox.Infrastructure/UserSettings/Settings.cs | 3 +-- Wox/SettingWindow.xaml | 6 ++--- Wox/SettingWindow.xaml.cs | 6 ----- Wox/ViewModel/SettingWindowViewModel.cs | 29 ++++++++++++++++++++- 6 files changed, 49 insertions(+), 13 deletions(-) diff --git a/Wox.Core/Resource/Internationalization.cs b/Wox.Core/Resource/Internationalization.cs index 9f865cb53..53cce9174 100644 --- a/Wox.Core/Resource/Internationalization.cs +++ b/Wox.Core/Resource/Internationalization.cs @@ -99,6 +99,22 @@ namespace Wox.Core.Resource } + public bool PromptShouldUsePinyin(string languageCodeToSet) + { + var languageToSet = GetLanguageByLanguageCode(languageCodeToSet); + + if (Settings.ShouldUsePinyin) + return false; + + if (languageToSet != AvailableLanguages.Chinese && languageToSet != AvailableLanguages.Chinese_TW) + return false; + + if (MessageBox.Show("Do you want to turn on search with Pinyin?", string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.No) + return false; + + return true; + } + private void RemoveOldLanguageFiles() { var dicts = Application.Current.Resources.MergedDictionaries; diff --git a/Wox.Infrastructure/Alphabet.cs b/Wox.Infrastructure/Alphabet.cs index 487c0a4b0..4754394cb 100644 --- a/Wox.Infrastructure/Alphabet.cs +++ b/Wox.Infrastructure/Alphabet.cs @@ -162,7 +162,7 @@ namespace Wox.Infrastructure if (word.Length > 40) { - Log.Debug($"|Wox.Infrastructure.StringMatcher.ScoreForPinyin|skip too long string: {word}"); + //Skip strings that are too long string for Pinyin conversion. return false; } diff --git a/Wox.Infrastructure/UserSettings/Settings.cs b/Wox.Infrastructure/UserSettings/Settings.cs index 7714768f0..94a1639d6 100644 --- a/Wox.Infrastructure/UserSettings/Settings.cs +++ b/Wox.Infrastructure/UserSettings/Settings.cs @@ -25,8 +25,7 @@ namespace Wox.Infrastructure.UserSettings /// /// when false Alphabet static service will always return empty results /// - public bool ShouldUsePinyin { get; set; } = true; - + public bool ShouldUsePinyin { get; set; } = false; internal StringMatcher.SearchPrecisionScore QuerySearchPrecision { get; private set; } = StringMatcher.SearchPrecisionScore.Regular; diff --git a/Wox/SettingWindow.xaml b/Wox/SettingWindow.xaml index 1eddd8ab6..7fe6d8750 100644 --- a/Wox/SettingWindow.xaml +++ b/Wox/SettingWindow.xaml @@ -55,7 +55,7 @@ - + @@ -72,8 +72,8 @@ - diff --git a/Wox/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs index 52addf362..df3b363d5 100644 --- a/Wox/SettingWindow.xaml.cs +++ b/Wox/SettingWindow.xaml.cs @@ -40,12 +40,6 @@ namespace Wox #region General - void OnLanguageChanged(object sender, SelectionChangedEventArgs e) - { - var language = (Language)e.AddedItems[0]; - InternationalizationManager.Instance.ChangeLanguage(language); - } - private void OnAutoStartupChecked(object sender, RoutedEventArgs e) { SetStartup(); diff --git a/Wox/ViewModel/SettingWindowViewModel.cs b/Wox/ViewModel/SettingWindowViewModel.cs index 504e7bdfa..f9160df9f 100644 --- a/Wox/ViewModel/SettingWindowViewModel.cs +++ b/Wox/ViewModel/SettingWindowViewModel.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -77,6 +77,33 @@ namespace Wox.ViewModel } } + public string Language + { + get + { + return Settings.Language; + } + set + { + InternationalizationManager.Instance.ChangeLanguage(value); + + if (InternationalizationManager.Instance.PromptShouldUsePinyin(value)) + ShouldUsePinyin = true; + } + } + + public bool ShouldUsePinyin + { + get + { + return Settings.ShouldUsePinyin; + } + set + { + Settings.ShouldUsePinyin = value; + } + } + public List QuerySearchPrecisionStrings { get From f68365b0ee595785597e3d6d704c5131d41bd2c5 Mon Sep 17 00:00:00 2001 From: clueless <14300910+theClueless@users.noreply.github.com> Date: Thu, 12 Mar 2020 01:49:24 +0200 Subject: [PATCH 18/21] fix issue #115 --- Plugins/HelloWorldCSharp/App.config | 6 ------ Plugins/HelloWorldCSharp/HelloWorldCSharp.csproj | 1 - Wox.Plugin/IPublicAPI.cs | 11 ++++++++++- Wox.sln | 4 ++-- Wox/PublicAPIInstance.cs | 7 ++++++- 5 files changed, 18 insertions(+), 11 deletions(-) delete mode 100644 Plugins/HelloWorldCSharp/App.config diff --git a/Plugins/HelloWorldCSharp/App.config b/Plugins/HelloWorldCSharp/App.config deleted file mode 100644 index 8d234373a..000000000 --- a/Plugins/HelloWorldCSharp/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/Plugins/HelloWorldCSharp/HelloWorldCSharp.csproj b/Plugins/HelloWorldCSharp/HelloWorldCSharp.csproj index 143052a03..49f3bf88f 100644 --- a/Plugins/HelloWorldCSharp/HelloWorldCSharp.csproj +++ b/Plugins/HelloWorldCSharp/HelloWorldCSharp.csproj @@ -11,7 +11,6 @@ HelloWorldCSharp v4.6.2 512 - true diff --git a/Wox.Plugin/IPublicAPI.cs b/Wox.Plugin/IPublicAPI.cs index 754b76d36..3c5b34277 100644 --- a/Wox.Plugin/IPublicAPI.cs +++ b/Wox.Plugin/IPublicAPI.cs @@ -81,7 +81,16 @@ namespace Wox.Plugin /// Message title /// Message subtitle /// Message icon path (relative path to your plugin folder) - void ShowMsg(string title, string subTitle = "", string iconPath = "", bool useMainWindowAsOwner = true); + void ShowMsg(string title, string subTitle = "", string iconPath = ""); + + /// + /// Show message box + /// + /// Message title + /// Message subtitle + /// Message icon path (relative path to your plugin folder) + /// when true will use main windows as the owner + void ShowMsg(string title, string subTitle, string iconPath, bool useMainWindowAsOwner = true); /// /// Open setting dialog diff --git a/Wox.sln b/Wox.sln index cbceab9b8..a8a42ae8d 100644 --- a/Wox.sln +++ b/Wox.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.28307.271 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29806.167 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Test", "Wox.Test\Wox.Test.csproj", "{FF742965-9A80-41A5-B042-D6C7D3A21708}" ProjectSection(ProjectDependencies) = postProject diff --git a/Wox/PublicAPIInstance.cs b/Wox/PublicAPIInstance.cs index 58915f87b..6c17be5c5 100644 --- a/Wox/PublicAPIInstance.cs +++ b/Wox/PublicAPIInstance.cs @@ -97,7 +97,12 @@ namespace Wox _mainVM.MainWindowVisibility = Visibility.Visible; } - public void ShowMsg(string title, string subTitle = "", string iconPath = "", bool useMainWindowAsOwner = true) + public void ShowMsg(string title, string subTitle = "", string iconPath = "") + { + ShowMsg(title, subTitle, iconPath, true); + } + + public void ShowMsg(string title, string subTitle, string iconPath, bool useMainWindowAsOwner = true) { Application.Current.Dispatcher.Invoke(() => { From 98ed4e7b593b5ee3c3376b29866e5a1834b17a78 Mon Sep 17 00:00:00 2001 From: clueless <14300910+theClueless@users.noreply.github.com> Date: Thu, 12 Mar 2020 01:54:30 +0200 Subject: [PATCH 19/21] app config remove --- Plugins/HelloWorldCSharp/HelloWorldCSharp.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/Plugins/HelloWorldCSharp/HelloWorldCSharp.csproj b/Plugins/HelloWorldCSharp/HelloWorldCSharp.csproj index 49f3bf88f..827c74170 100644 --- a/Plugins/HelloWorldCSharp/HelloWorldCSharp.csproj +++ b/Plugins/HelloWorldCSharp/HelloWorldCSharp.csproj @@ -52,7 +52,6 @@ - PreserveNewest From b50f738f4207ddf9d41be726d4eaa44c4d28fcdd Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Sun, 15 Mar 2020 20:05:34 +1100 Subject: [PATCH 20/21] Feature: Add auto-complete query text suggestion (#153) * Add query suggestion logic * Add UI element * update * Make caret more appealing by following the color of the query font * Add suggestions when using actionkeyword * Add feature to readme * Per suggestion add explaination * Per review comment * Per review comment * change to use converter * Correct typo Co-authored-by: clueless <14300910+theClueless@users.noreply.github.com> --- Plugins/Wox.Plugin.WebSearch/Main.cs | 2 + README.md | 1 + Wox.Core/Plugin/PluginManager.cs | 5 ++ Wox.Core/Resource/Theme.cs | 6 ++ Wox.Plugin/Result.cs | 13 +++- Wox/Converters/QuerySuggestionBoxConverter.cs | 61 +++++++++++++++++++ Wox/MainWindow.xaml | 47 +++++++++----- Wox/Themes/Base.xaml | 1 + Wox/ViewModel/MainViewModel.cs | 6 +- Wox/Wox.csproj | 1 + 10 files changed, 123 insertions(+), 20 deletions(-) create mode 100644 Wox/Converters/QuerySuggestionBoxConverter.cs diff --git a/Plugins/Wox.Plugin.WebSearch/Main.cs b/Plugins/Wox.Plugin.WebSearch/Main.cs index 429e51cc0..d8c6ccafb 100644 --- a/Plugins/Wox.Plugin.WebSearch/Main.cs +++ b/Plugins/Wox.Plugin.WebSearch/Main.cs @@ -72,6 +72,7 @@ namespace Wox.Plugin.WebSearch SubTitle = subtitle, Score = 6, IcoPath = searchSource.IconPath, + ActionKeywordAssigned = searchSource.ActionKeyword == SearchSourceGlobalPluginWildCardSign ? string.Empty : searchSource.ActionKeyword, Action = c => { if (_settings.OpenInNewBrowser) @@ -137,6 +138,7 @@ namespace Wox.Plugin.WebSearch SubTitle = subtitle, Score = 5, IcoPath = searchSource.IconPath, + ActionKeywordAssigned = searchSource.ActionKeyword == SearchSourceGlobalPluginWildCardSign ? string.Empty : searchSource.ActionKeyword, Action = c => { if (_settings.OpenInNewBrowser) diff --git a/README.md b/README.md index 8db5d4d9c..732dd242f 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ Features **New from this fork:** - Portable mode - Drastically improved search experience +- Auto-complete text suggestion - Search all subfolders and files - Option to always run CMD or Powershell as administrator - Run CMD, Powershell and programs as a different user diff --git a/Wox.Core/Plugin/PluginManager.cs b/Wox.Core/Plugin/PluginManager.cs index 0166690b7..3d1450648 100644 --- a/Wox.Core/Plugin/PluginManager.cs +++ b/Wox.Core/Plugin/PluginManager.cs @@ -191,6 +191,11 @@ namespace Wox.Core.Plugin r.PluginDirectory = metadata.PluginDirectory; r.PluginID = metadata.ID; r.OriginQuery = query; + + // ActionKeywordAssigned is used for constructing MainViewModel's query text auto-complete suggestions + // Plugins may have multi-actionkeywords eg. WebSearches. In this scenario it needs to be overriden on the plugin level + if (metadata.ActionKeywords.Count == 1) + r.ActionKeywordAssigned = query.ActionKeyword; } } diff --git a/Wox.Core/Resource/Theme.cs b/Wox.Core/Resource/Theme.cs index 4b8c37ccf..fc5d55046 100644 --- a/Wox.Core/Resource/Theme.cs +++ b/Wox.Core/Resource/Theme.cs @@ -124,6 +124,12 @@ namespace Wox.Core.Resource queryBoxStyle.Setters.Add(new Setter(TextBox.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(Settings.QueryBoxFontStyle))); queryBoxStyle.Setters.Add(new Setter(TextBox.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(Settings.QueryBoxFontWeight))); queryBoxStyle.Setters.Add(new Setter(TextBox.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(Settings.QueryBoxFontStretch))); + + var caretBrushPropertyValue = queryBoxStyle.Setters.OfType().Any(x => x.Property.Name == "CaretBrush"); + var foregroundPropertyValue = queryBoxStyle.Setters.OfType().Where(x => x.Property.Name == "Foreground") + .Select(x => x.Value).FirstOrDefault(); + if (!caretBrushPropertyValue && foregroundPropertyValue != null) //otherwise BaseQueryBoxStyle will handle styling + queryBoxStyle.Setters.Add(new Setter(TextBox.CaretBrushProperty, foregroundPropertyValue)); } Style resultItemStyle = dict["ItemTitleStyle"] as Style; diff --git a/Wox.Plugin/Result.cs b/Wox.Plugin/Result.cs index 6e0559d35..4c8f2b1ed 100644 --- a/Wox.Plugin/Result.cs +++ b/Wox.Plugin/Result.cs @@ -14,6 +14,12 @@ namespace Wox.Plugin public string Title { get; set; } public string SubTitle { get; set; } + /// + /// This holds the action keyword that triggered the result. + /// If result is triggered by global keyword: *, this should be empty. + /// + public string ActionKeywordAssigned { get; set; } + public string IcoPath { get { return _icoPath; } @@ -53,7 +59,7 @@ namespace Wox.Plugin public IList SubTitleHighlightData { get; set; } /// - /// Only resulsts that originQuery match with curren query will be displayed in the panel + /// Only results that originQuery match with current query will be displayed in the panel /// internal Query OriginQuery { get; set; } @@ -98,13 +104,14 @@ namespace Wox.Plugin return Title + SubTitle; } - [Obsolete("Use IContextMenu instead")] + /// /// Context menus associate with this result /// + [Obsolete("Use IContextMenu instead")] public List ContextMenu { get; set; } - [Obsolete("Use Object initializers instead")] + [Obsolete("Use Object initializer instead")] public Result(string Title, string IcoPath, string SubTitle = null) { this.Title = Title; diff --git a/Wox/Converters/QuerySuggestionBoxConverter.cs b/Wox/Converters/QuerySuggestionBoxConverter.cs new file mode 100644 index 000000000..68b891ce6 --- /dev/null +++ b/Wox/Converters/QuerySuggestionBoxConverter.cs @@ -0,0 +1,61 @@ +using System; +using System.Globalization; +using System.Windows.Data; +using Wox.Infrastructure.Logger; +using Wox.ViewModel; + +namespace Wox.Converters +{ + public class QuerySuggestionBoxConverter : IMultiValueConverter + { + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + if (values.Length != 2) + { + return string.Empty; + } + + // first prop is the current query string + var queryText = (string)values[0]; + + if (string.IsNullOrEmpty(queryText)) + return "Type here to search"; + + // second prop is the current selected item result + var val = values[1]; + if (val == null) + { + return string.Empty; + } + if (!(val is ResultViewModel)) + { + return System.Windows.Data.Binding.DoNothing; + } + + try + { + var selectedItem = (ResultViewModel)val; + + var selectedResult = selectedItem.Result; + var selectedResultActionKeyword = string.IsNullOrEmpty(selectedResult.ActionKeywordAssigned) ? "" : selectedResult.ActionKeywordAssigned + " "; + var selectedResultPossibleSuggestion = selectedResultActionKeyword + selectedResult.Title; + + if (!selectedResultPossibleSuggestion.StartsWith(queryText, StringComparison.CurrentCultureIgnoreCase)) + return string.Empty; + + // When user typed lower case and result title is uppercase, we still want to display suggestion + return queryText + selectedResultPossibleSuggestion.Substring(queryText.Length); + } + catch (Exception e) + { + Log.Exception(nameof(QuerySuggestionBoxConverter), "fail to convert text for suggestion box", e); + return string.Empty; + } + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Wox/MainWindow.xaml b/Wox/MainWindow.xaml index d50411b83..7c5afb3ef 100644 --- a/Wox/MainWindow.xaml +++ b/Wox/MainWindow.xaml @@ -4,7 +4,9 @@ xmlns:wox="clr-namespace:Wox" xmlns:vm="clr-namespace:Wox.ViewModel" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:converters="clr-namespace:Wox.Converters" + mc:Ignorable="d" Title="Wox" Topmost="True" SizeToContent="Height" @@ -25,6 +27,9 @@ PreviewKeyDown="OnKeyDown" Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" d:DataContext="{d:DesignInstance vm:MainViewModel}"> + + + @@ -55,29 +60,43 @@ - + + + + + + + + + - - - - - - - - - - + Background="Transparent"> + + + + + + + + + + + - + diff --git a/Wox/Themes/Base.xaml b/Wox/Themes/Base.xaml index ae195feaa..6f6083035 100644 --- a/Wox/Themes/Base.xaml +++ b/Wox/Themes/Base.xaml @@ -8,6 +8,7 @@ + diff --git a/Wox/ViewModel/MainViewModel.cs b/Wox/ViewModel/MainViewModel.cs index acdd7c040..c2a277963 100644 --- a/Wox/ViewModel/MainViewModel.cs +++ b/Wox/ViewModel/MainViewModel.cs @@ -1,5 +1,6 @@ -using System; +using System; using System.Collections.Generic; +using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Threading; @@ -210,7 +211,7 @@ namespace Wox.ViewModel Query(); } } - + /// /// we need move cursor to end when we manually changed query /// but we don't want to move cursor to end when query is updated from TextBox @@ -455,7 +456,6 @@ namespace Wox.ViewModel } } - private Result ContextMenuTopMost(Result result) { Result menu; diff --git a/Wox/Wox.csproj b/Wox/Wox.csproj index 0aa060ddd..56a4ed97b 100644 --- a/Wox/Wox.csproj +++ b/Wox/Wox.csproj @@ -93,6 +93,7 @@ + ResultListBox.xaml From d80934c235ff65f4dffffd300b841d6e8e701204 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Fri, 27 Mar 2020 19:13:22 +1100 Subject: [PATCH 21/21] Update post_build script's packages reference path (#173) * Update post_build script's packages reference path * Change to static version * remove inappropriate word --- Scripts/post_build.ps1 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Scripts/post_build.ps1 b/Scripts/post_build.ps1 index eb302a6c6..45d3f7b69 100644 --- a/Scripts/post_build.ps1 +++ b/Scripts/post_build.ps1 @@ -38,7 +38,8 @@ function Copy-Resources ($path, $config) { Copy-Item -Recurse -Force $project\Images\* $target\Images\ Copy-Item -Recurse -Force $path\Plugins\HelloWorldPython $target\Plugins\HelloWorldPython Copy-Item -Recurse -Force $path\JsonRPC $target\JsonRPC - Copy-Item -Force $path\packages\squirrel*\tools\Squirrel.exe $output\Update.exe + # making version static as multiple versions can exist in the nuget folder and in the case a breaking change is introduced. + Copy-Item -Force $env:USERPROFILE\.nuget\packages\squirrel.windows\1.5.2\tools\Squirrel.exe $output\Update.exe } function Delete-Unused ($path, $config) { @@ -96,9 +97,9 @@ function Pack-Squirrel-Installer ($path, $version, $output) { $icon = "$path\Wox\Resources\app.ico" Write-Host "icon: $icon" # Squirrel.com: https://github.com/Squirrel/Squirrel.Windows/issues/369 - New-Alias Squirrel $path\packages\squirrel*\tools\Squirrel.exe -Force + New-Alias Squirrel $env:USERPROFILE\.nuget\packages\squirrel.windows\1.5.2\tools\Squirrel.exe -Force # why we need Write-Output: https://github.com/Squirrel/Squirrel.Windows/issues/489#issuecomment-156039327 - # directory of releaseDir in fucking squirrel can't be same as directory ($nupkg) in releasify + # directory of releaseDir in squirrel can't be same as directory ($nupkg) in releasify $temp = "$output\Temp" Squirrel --releasify $nupkg --releaseDir $temp --setupIcon $icon --no-msi | Write-Output @@ -123,7 +124,8 @@ function Main { Delete-Unused $p $config $o = "$p\Output\Packages" Validate-Directory $o - New-Alias Nuget $p\packages\NuGet.CommandLine.*\tools\NuGet.exe -Force + # making version static as multiple versions can exist in the nuget folder and in the case a breaking change is introduced. + New-Alias Nuget $env:USERPROFILE\.nuget\packages\NuGet.CommandLine\3.4.3\tools\NuGet.exe -Force Pack-Squirrel-Installer $p $v $o $isInCI = $env:APPVEYOR