mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-14 19:49:15 +08:00
Merge branch 'dev'
This commit is contained in:
commit
e6a09e7cf7
4
Deploy/local_build.ps1
Normal file
4
Deploy/local_build.ps1
Normal file
@ -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
|
@ -4,5 +4,7 @@
|
|||||||
|
|
||||||
<system:String x:Key="wox_plugin_caculator_plugin_name">Rechner</system:String>
|
<system:String x:Key="wox_plugin_caculator_plugin_name">Rechner</system:String>
|
||||||
<system:String x:Key="wox_plugin_caculator_plugin_description">Stellt mathematische Berechnungen bereit.(Versuche 5*3-2 in Wox)</system:String>
|
<system:String x:Key="wox_plugin_caculator_plugin_description">Stellt mathematische Berechnungen bereit.(Versuche 5*3-2 in Wox)</system:String>
|
||||||
|
<system:String x:Key="wox_plugin_calculator_not_a_number">Keine Zahl (NaN)</system:String>
|
||||||
|
<system:String x:Key="wox_plugin_calculator_expression_not_complete">Ausdruck falsch oder nicht vollständig (Klammern vergessen?)</system:String>
|
||||||
|
<system:String x:Key="wox_plugin_calculator_copy_number_to_clipboard">Diese Zahl in die Zwischenablage kopieren</system:String>
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
@ -4,5 +4,7 @@
|
|||||||
|
|
||||||
<system:String x:Key="wox_plugin_caculator_plugin_name">Calculator</system:String>
|
<system:String x:Key="wox_plugin_caculator_plugin_name">Calculator</system:String>
|
||||||
<system:String x:Key="wox_plugin_caculator_plugin_description">Allows to do mathematical calculations.(Try 5*3-2 in Wox)</system:String>
|
<system:String x:Key="wox_plugin_caculator_plugin_description">Allows to do mathematical calculations.(Try 5*3-2 in Wox)</system:String>
|
||||||
|
<system:String x:Key="wox_plugin_calculator_not_a_number">Not a number (NaN)</system:String>
|
||||||
|
<system:String x:Key="wox_plugin_calculator_expression_not_complete">Expression wrong or incomplete (Did you forget some parentheses?)</system:String>
|
||||||
|
<system:String x:Key="wox_plugin_calculator_copy_number_to_clipboard">Copy this number to the clipboard</system:String>
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
@ -2,13 +2,13 @@
|
|||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using YAMP;
|
using Mages.Core;
|
||||||
|
|
||||||
namespace Wox.Plugin.Caculator
|
namespace Wox.Plugin.Caculator
|
||||||
{
|
{
|
||||||
public class Main : IPlugin, IPluginI18n
|
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|" +
|
@"ceil|floor|exp|pi|e|max|min|det|abs|log|ln|sqrt|" +
|
||||||
@"sin|cos|tan|arcsin|arccos|arctan|" +
|
@"sin|cos|tan|arcsin|arccos|arctan|" +
|
||||||
@ -17,60 +17,70 @@ namespace Wox.Plugin.Caculator
|
|||||||
@"==|~=|&&|\|\||" +
|
@"==|~=|&&|\|\||" +
|
||||||
@"[ei]|[0-9]|[\+\-\*\/\^\., ""]|[\(\)\|\!\[\]]" +
|
@"[ei]|[0-9]|[\+\-\*\/\^\., ""]|[\(\)\|\!\[\]]" +
|
||||||
@")+$", RegexOptions.Compiled);
|
@")+$", RegexOptions.Compiled);
|
||||||
private static Regex regBrackets = new Regex(@"[\(\)\[\]]", RegexOptions.Compiled);
|
private static readonly Regex RegBrackets = new Regex(@"[\(\)\[\]]", RegexOptions.Compiled);
|
||||||
private static ParseContext yampContext;
|
private static readonly Engine MagesEngine;
|
||||||
private PluginInitContext context { get; set; }
|
private PluginInitContext Context { get; set; }
|
||||||
|
|
||||||
static Main()
|
static Main()
|
||||||
{
|
{
|
||||||
yampContext = Parser.PrimaryContext;
|
MagesEngine = new Engine();
|
||||||
Parser.InteractiveMode = false;
|
|
||||||
Parser.UseScripting = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Result> Query(Query query)
|
public List<Result> Query(Query query)
|
||||||
{
|
{
|
||||||
if (query.Search.Length <= 2 // don't affect when user only input "e" or "i" keyword
|
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<Result>();
|
|| !IsBracketComplete(query.Search)) return new List<Result>();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result = yampContext.Run(query.Search);
|
var result = MagesEngine.Interpret(query.Search);
|
||||||
if (result.Output != null && !string.IsNullOrEmpty(result.Result))
|
|
||||||
|
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<Result>
|
return new List<Result>
|
||||||
{ new Result
|
|
||||||
{
|
{
|
||||||
Title = result.Result,
|
new Result
|
||||||
IcoPath = "Images/calculator.png",
|
|
||||||
Score = 300,
|
|
||||||
SubTitle = "Copy this number to the clipboard",
|
|
||||||
Action = c =>
|
|
||||||
{
|
{
|
||||||
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);
|
try
|
||||||
return true;
|
{
|
||||||
}
|
Clipboard.SetText(result.ToString());
|
||||||
catch (ExternalException e)
|
return true;
|
||||||
{
|
}
|
||||||
MessageBox.Show("Copy failed, please try later");
|
catch (ExternalException)
|
||||||
return false;
|
{
|
||||||
|
MessageBox.Show("Copy failed, please try later");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} };
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{}
|
{
|
||||||
|
// ignored
|
||||||
|
}
|
||||||
|
|
||||||
return new List<Result>();
|
return new List<Result>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsBracketComplete(string query)
|
private bool IsBracketComplete(string query)
|
||||||
{
|
{
|
||||||
var matchs = regBrackets.Matches(query);
|
var matchs = RegBrackets.Matches(query);
|
||||||
var leftBracketCount = 0;
|
var leftBracketCount = 0;
|
||||||
foreach (Match match in matchs)
|
foreach (Match match in matchs)
|
||||||
{
|
{
|
||||||
@ -89,17 +99,17 @@ namespace Wox.Plugin.Caculator
|
|||||||
|
|
||||||
public void Init(PluginInitContext context)
|
public void Init(PluginInitContext context)
|
||||||
{
|
{
|
||||||
this.context = context;
|
Context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetTranslatedPluginTitle()
|
public string GetTranslatedPluginTitle()
|
||||||
{
|
{
|
||||||
return context.API.GetTranslation("wox_plugin_caculator_plugin_name");
|
return Context.API.GetTranslation("wox_plugin_caculator_plugin_name");
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetTranslatedPluginDescription()
|
public string GetTranslatedPluginDescription()
|
||||||
{
|
{
|
||||||
return context.API.GetTranslation("wox_plugin_caculator_plugin_description");
|
return Context.API.GetTranslation("wox_plugin_caculator_plugin_description");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
95
Plugins/Wox.Plugin.Calculator/NumberTranslator.cs
Normal file
95
Plugins/Wox.Plugin.Calculator/NumberTranslator.cs
Normal file
@ -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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Tries to convert all numbers in a text from one culture format to another.
|
||||||
|
/// </summary>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a new <see cref="NumberTranslator"/> - returns null if no number conversion
|
||||||
|
/// is required between the cultures.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sourceCulture">source culture</param>
|
||||||
|
/// <param name="targetCulture">target culture</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Translate from source to target culture.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public string Translate(string input)
|
||||||
|
{
|
||||||
|
return this.Translate(input, this.sourceCulture, this.targetCulture, this.splitRegexForSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Translate from target to source culture.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -38,19 +38,20 @@
|
|||||||
<HintPath>..\..\packages\JetBrains.Annotations.10.3.0\lib\net\JetBrains.Annotations.dll</HintPath>
|
<HintPath>..\..\packages\JetBrains.Annotations.10.3.0\lib\net\JetBrains.Annotations.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="Mages.Core, Version=1.5.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\..\packages\Mages.1.5.0\lib\net35\Mages.Core.dll</HintPath>
|
||||||
|
<Private>True</Private>
|
||||||
|
</Reference>
|
||||||
<Reference Include="PresentationCore" />
|
<Reference Include="PresentationCore" />
|
||||||
<Reference Include="PresentationFramework" />
|
<Reference Include="PresentationFramework" />
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="YAMP, Version=1.4.0.22422, Culture=neutral, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\packages\YAMP.1.4.0\lib\net35\YAMP.dll</HintPath>
|
|
||||||
<Private>True</Private>
|
|
||||||
</Reference>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="..\..\SolutionAssemblyInfo.cs">
|
<Compile Include="..\..\SolutionAssemblyInfo.cs">
|
||||||
<Link>Properties\SolutionAssemblyInfo.cs</Link>
|
<Link>Properties\SolutionAssemblyInfo.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="NumberTranslator.cs" />
|
||||||
<Compile Include="Main.cs" />
|
<Compile Include="Main.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="JetBrains.Annotations" version="10.3.0" targetFramework="net452" />
|
<package id="JetBrains.Annotations" version="10.3.0" targetFramework="net452" />
|
||||||
|
<package id="Mages" version="1.5.0" targetFramework="net452" />
|
||||||
<package id="System.Runtime" version="4.0.0" targetFramework="net452" />
|
<package id="System.Runtime" version="4.0.0" targetFramework="net452" />
|
||||||
<package id="YAMP" version="1.4.0" targetFramework="net452" />
|
|
||||||
</packages>
|
</packages>
|
@ -108,5 +108,13 @@ namespace Wox.Core
|
|||||||
|
|
||||||
return manager;
|
return manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string NewVersinoTips(string version)
|
||||||
|
{
|
||||||
|
var translater = InternationalizationManager.Instance;
|
||||||
|
var tips = string.Format(translater.GetTranslation("newVersionTips"), version);
|
||||||
|
return tips;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -40,6 +40,7 @@ namespace Wox
|
|||||||
{
|
{
|
||||||
var oldActionKeyword = _plugin.Metadata.ActionKeywords[0];
|
var oldActionKeyword = _plugin.Metadata.ActionKeywords[0];
|
||||||
var newActionKeyword = tbAction.Text.Trim();
|
var newActionKeyword = tbAction.Text.Trim();
|
||||||
|
newActionKeyword = newActionKeyword.Length > 0 ? newActionKeyword : "*";
|
||||||
if (!PluginManager.ActionKeywordRegistered(newActionKeyword))
|
if (!PluginManager.ActionKeywordRegistered(newActionKeyword))
|
||||||
{
|
{
|
||||||
var id = _plugin.Metadata.ID;
|
var id = _plugin.Metadata.ID;
|
||||||
|
@ -96,7 +96,7 @@ namespace Wox
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Conditional("RELEASE")]
|
//[Conditional("RELEASE")]
|
||||||
private void AutoUpdates()
|
private void AutoUpdates()
|
||||||
{
|
{
|
||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
|
Loading…
Reference in New Issue
Block a user