diff --git a/Deploy/local_build.ps1 b/Deploy/local_build.ps1 new file mode 100644 index 0000000000..9dd7582b19 --- /dev/null +++ b/Deploy/local_build.ps1 @@ -0,0 +1,4 @@ +New-Alias nuget.exe ".\packages\NuGet.CommandLine.*\tools\NuGet.exe" +$env:APPVEYOR_BUILD_FOLDER = Convert-Path . +$env:APPVEYOR_BUILD_VERSION = "1.2.0" +& .\Deploy\squirrel_installer.ps1 \ 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 02c51e8c78..286e4bc9b3 100644 --- a/Plugins/Wox.Plugin.Calculator/Languages/de.xaml +++ b/Plugins/Wox.Plugin.Calculator/Languages/de.xaml @@ -4,5 +4,7 @@ Rechner Stellt mathematische Berechnungen bereit.(Versuche 5*3-2 in Wox) - + Keine Zahl (NaN) + Ausdruck falsch oder nicht vollständig (Klammern vergessen?) + Diese Zahl in die Zwischenablage kopieren \ 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 833a0c14bb..3b5fa32b33 100644 --- a/Plugins/Wox.Plugin.Calculator/Languages/en.xaml +++ b/Plugins/Wox.Plugin.Calculator/Languages/en.xaml @@ -4,5 +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 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 9e7036e650..fab0b8e030 100644 --- a/Plugins/Wox.Plugin.Calculator/Main.cs +++ b/Plugins/Wox.Plugin.Calculator/Main.cs @@ -2,13 +2,13 @@ using System.Runtime.InteropServices; using System.Text.RegularExpressions; using System.Windows; -using YAMP; +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|" + @@ -17,60 +17,70 @@ namespace Wox.Plugin.Caculator @"==|~=|&&|\|\||" + @"[ei]|[0-9]|[\+\-\*\/\^\., ""]|[\(\)\|\!\[\]]" + @")+$", RegexOptions.Compiled); - private static Regex regBrackets = new Regex(@"[\(\)\[\]]", RegexOptions.Compiled); - private static ParseContext yampContext; - 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() { - yampContext = Parser.PrimaryContext; - Parser.InteractiveMode = false; - Parser.UseScripting = false; + 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 = yampContext.Run(query.Search); - if (result.Output != null && !string.IsNullOrEmpty(result.Result)) + var result = MagesEngine.Interpret(query.Search); + + if (result.ToString() == "NaN") + result = Context.API.GetTranslation("wox_plugin_calculator_not_a_number"); + + if (result is Function) + result = Context.API.GetTranslation("wox_plugin_calculator_expression_not_complete"); + + + if (!string.IsNullOrEmpty(result?.ToString())) { return new List - { new Result - { - Title = result.Result, - IcoPath = "Images/calculator.png", - Score = 300, - SubTitle = "Copy this number to the 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.Result); - 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) { @@ -89,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/Plugins/Wox.Plugin.Calculator/NumberTranslator.cs b/Plugins/Wox.Plugin.Calculator/NumberTranslator.cs new file mode 100644 index 0000000000..448301d4fb --- /dev/null +++ b/Plugins/Wox.Plugin.Calculator/NumberTranslator.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; + +namespace Wox.Plugin.Caculator +{ + /// + /// Tries to convert all numbers in a text from one culture format to another. + /// + public class NumberTranslator + { + private readonly CultureInfo sourceCulture; + private readonly CultureInfo targetCulture; + private readonly Regex splitRegexForSource; + private readonly Regex splitRegexForTarget; + + private NumberTranslator(CultureInfo sourceCulture, CultureInfo targetCulture) + { + this.sourceCulture = sourceCulture; + this.targetCulture = targetCulture; + + this.splitRegexForSource = GetSplitRegex(this.sourceCulture); + this.splitRegexForTarget = GetSplitRegex(this.targetCulture); + } + + /// + /// Create a new - returns null if no number conversion + /// is required between the cultures. + /// + /// source culture + /// target culture + /// + public static NumberTranslator Create(CultureInfo sourceCulture, CultureInfo targetCulture) + { + bool conversionRequired = sourceCulture.NumberFormat.NumberDecimalSeparator != targetCulture.NumberFormat.NumberDecimalSeparator + || sourceCulture.NumberFormat.PercentGroupSeparator != targetCulture.NumberFormat.PercentGroupSeparator + || sourceCulture.NumberFormat.NumberGroupSizes != targetCulture.NumberFormat.NumberGroupSizes; + return conversionRequired + ? new NumberTranslator(sourceCulture, targetCulture) + : null; + } + + /// + /// Translate from source to target culture. + /// + /// + /// + public string Translate(string input) + { + return this.Translate(input, this.sourceCulture, this.targetCulture, this.splitRegexForSource); + } + + /// + /// Translate from target to source culture. + /// + /// + /// + public string TranslateBack(string input) + { + return this.Translate(input, this.targetCulture, this.sourceCulture, this.splitRegexForTarget); + } + + private string Translate(string input, CultureInfo cultureFrom, CultureInfo cultureTo, Regex splitRegex) + { + var outputBuilder = new StringBuilder(); + + string[] tokens = splitRegex.Split(input); + foreach (string token in tokens) + { + decimal number; + outputBuilder.Append( + decimal.TryParse(token, NumberStyles.Number, cultureFrom, out number) + ? number.ToString(cultureTo) + : token); + } + + return outputBuilder.ToString(); + } + + private Regex GetSplitRegex(CultureInfo culture) + { + var splitPattern = $"((?:\\d|{Regex.Escape(culture.NumberFormat.NumberDecimalSeparator)}"; + if (!string.IsNullOrEmpty(culture.NumberFormat.NumberGroupSeparator)) + { + splitPattern += $"|{Regex.Escape(culture.NumberFormat.NumberGroupSeparator)}"; + } + splitPattern += ")+)"; + return new Regex(splitPattern); + } + } +} diff --git a/Plugins/Wox.Plugin.Calculator/Wox.Plugin.Calculator.csproj b/Plugins/Wox.Plugin.Calculator/Wox.Plugin.Calculator.csproj index 7d9aefe604..8fd3169a84 100644 --- a/Plugins/Wox.Plugin.Calculator/Wox.Plugin.Calculator.csproj +++ b/Plugins/Wox.Plugin.Calculator/Wox.Plugin.Calculator.csproj @@ -38,19 +38,20 @@ ..\..\packages\JetBrains.Annotations.10.3.0\lib\net\JetBrains.Annotations.dll True + + ..\..\packages\Mages.1.5.0\lib\net35\Mages.Core.dll + True + - - ..\..\packages\YAMP.1.4.0\lib\net35\YAMP.dll - True - Properties\SolutionAssemblyInfo.cs + diff --git a/Plugins/Wox.Plugin.Calculator/packages.config b/Plugins/Wox.Plugin.Calculator/packages.config index d1fce409f5..c17f6726fd 100644 --- a/Plugins/Wox.Plugin.Calculator/packages.config +++ b/Plugins/Wox.Plugin.Calculator/packages.config @@ -1,6 +1,6 @@  + - \ No newline at end of file diff --git a/Wox.Core/Updater.cs b/Wox.Core/Updater.cs index c71479bd54..050ccceb81 100644 --- a/Wox.Core/Updater.cs +++ b/Wox.Core/Updater.cs @@ -108,5 +108,13 @@ namespace Wox.Core return manager; } + + public static string NewVersinoTips(string version) + { + var translater = InternationalizationManager.Instance; + var tips = string.Format(translater.GetTranslation("newVersionTips"), version); + return tips; + } + } } \ No newline at end of file diff --git a/Wox/ActionKeywords.xaml.cs b/Wox/ActionKeywords.xaml.cs index 2dc0e02bd1..c86671c6ef 100644 --- a/Wox/ActionKeywords.xaml.cs +++ b/Wox/ActionKeywords.xaml.cs @@ -40,6 +40,7 @@ namespace Wox { var oldActionKeyword = _plugin.Metadata.ActionKeywords[0]; var newActionKeyword = tbAction.Text.Trim(); + newActionKeyword = newActionKeyword.Length > 0 ? newActionKeyword : "*"; if (!PluginManager.ActionKeywordRegistered(newActionKeyword)) { var id = _plugin.Metadata.ID; diff --git a/Wox/App.xaml.cs b/Wox/App.xaml.cs index f5c7627da5..3407cf5762 100644 --- a/Wox/App.xaml.cs +++ b/Wox/App.xaml.cs @@ -96,7 +96,7 @@ namespace Wox } } - [Conditional("RELEASE")] + //[Conditional("RELEASE")] private void AutoUpdates() { Task.Run(async () =>