From 742048f24e3413e31cd8a77bc51f2550229ea9da Mon Sep 17 00:00:00 2001 From: Michael Wirth Date: Mon, 16 Oct 2017 20:17:53 +0200 Subject: [PATCH] Fixed typos and swapped Brackets for parentheses, Corrections due to PR --- .../Wox.Plugin.Calculator/Languages/en.xaml | 6 +- Plugins/Wox.Plugin.Calculator/Main.cs | 67 ++++++++++--------- Wox.Infrastructure/Logger/Log.cs | 2 +- 3 files changed, 39 insertions(+), 36 deletions(-) diff --git a/Plugins/Wox.Plugin.Calculator/Languages/en.xaml b/Plugins/Wox.Plugin.Calculator/Languages/en.xaml index e354839e7c..3b5fa32b33 100644 --- a/Plugins/Wox.Plugin.Calculator/Languages/en.xaml +++ b/Plugins/Wox.Plugin.Calculator/Languages/en.xaml @@ -4,7 +4,7 @@ Calculator Allows to do mathematical calculations.(Try 5*3-2 in Wox) - Not a Number (NaN) - Expression wrong or incomplete (Did you forget some Brackets?) - Copy this Number to the clipboard + Not a number (NaN) + Expression wrong or incomplete (Did you forget some parentheses?) + Copy this number to the clipboard \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Calculator/Main.cs b/Plugins/Wox.Plugin.Calculator/Main.cs index cefb686b97..fab0b8e030 100644 --- a/Plugins/Wox.Plugin.Calculator/Main.cs +++ b/Plugins/Wox.Plugin.Calculator/Main.cs @@ -2,14 +2,13 @@ using System.Runtime.InteropServices; using System.Text.RegularExpressions; using System.Windows; -using Mages; using Mages.Core; namespace Wox.Plugin.Caculator { public class Main : IPlugin, IPluginI18n { - private static Regex regValidExpressChar = new Regex( + private static readonly Regex RegValidExpressChar = new Regex( @"^(" + @"ceil|floor|exp|pi|e|max|min|det|abs|log|ln|sqrt|" + @"sin|cos|tan|arcsin|arccos|arctan|" + @@ -18,66 +17,70 @@ namespace Wox.Plugin.Caculator @"==|~=|&&|\|\||" + @"[ei]|[0-9]|[\+\-\*\/\^\., ""]|[\(\)\|\!\[\]]" + @")+$", RegexOptions.Compiled); - private static Regex regBrackets = new Regex(@"[\(\)\[\]]", RegexOptions.Compiled); - private static Mages.Core.Engine magesEngine; - private PluginInitContext context { get; set; } + private static readonly Regex RegBrackets = new Regex(@"[\(\)\[\]]", RegexOptions.Compiled); + private static readonly Engine MagesEngine; + private PluginInitContext Context { get; set; } static Main() { - magesEngine = new Engine(); + MagesEngine = new Engine(); } public List Query(Query query) { if (query.Search.Length <= 2 // don't affect when user only input "e" or "i" keyword - || !regValidExpressChar.IsMatch(query.Search) + || !RegValidExpressChar.IsMatch(query.Search) || !IsBracketComplete(query.Search)) return new List(); try { - var result = magesEngine.Interpret(query.Search); + var result = MagesEngine.Interpret(query.Search); if (result.ToString() == "NaN") - result = context.API.GetTranslation("wox_plugin_calculator_not_a_number"); + result = Context.API.GetTranslation("wox_plugin_calculator_not_a_number"); if (result is Function) - result = context.API.GetTranslation("wox_plugin_calculator_expression_not_complete"); + result = Context.API.GetTranslation("wox_plugin_calculator_expression_not_complete"); - if (result != null && !string.IsNullOrEmpty(result.ToString())) + if (!string.IsNullOrEmpty(result?.ToString())) { return new List - { new Result { - Title = result.ToString(), - IcoPath = "Images/calculator.png", - Score = 300, - SubTitle = context.API.GetTranslation("wox_plugin_calculator_copy_number_to_clipboard"), - Action = c => + new Result { - try + Title = result.ToString(), + IcoPath = "Images/calculator.png", + Score = 300, + SubTitle = Context.API.GetTranslation("wox_plugin_calculator_copy_number_to_clipboard"), + Action = c => { - Clipboard.SetText(result.ToString()); - return true; + try + { + Clipboard.SetText(result.ToString()); + return true; + } + catch (ExternalException) + { + MessageBox.Show("Copy failed, please try later"); + return false; + } } - catch (ExternalException e) - { - MessageBox.Show("Copy failed, please try later"); - return false; - } - } - } }; + } + }; } } catch - { } + { + // ignored + } return new List(); } private bool IsBracketComplete(string query) { - var matchs = regBrackets.Matches(query); + var matchs = RegBrackets.Matches(query); var leftBracketCount = 0; foreach (Match match in matchs) { @@ -96,17 +99,17 @@ namespace Wox.Plugin.Caculator public void Init(PluginInitContext context) { - this.context = context; + Context = context; } public string GetTranslatedPluginTitle() { - return context.API.GetTranslation("wox_plugin_caculator_plugin_name"); + return Context.API.GetTranslation("wox_plugin_caculator_plugin_name"); } public string GetTranslatedPluginDescription() { - return context.API.GetTranslation("wox_plugin_caculator_plugin_description"); + return Context.API.GetTranslation("wox_plugin_caculator_plugin_description"); } } } diff --git a/Wox.Infrastructure/Logger/Log.cs b/Wox.Infrastructure/Logger/Log.cs index f7ea74b31c..d02654978d 100644 --- a/Wox.Infrastructure/Logger/Log.cs +++ b/Wox.Infrastructure/Logger/Log.cs @@ -72,7 +72,7 @@ namespace Wox.Infrastructure.Logger public static void Exception(string message, System.Exception e) { #if DEBUG - throw e; + //throw e; #else if (FormatValid(message)) {