mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 20:27:36 +02:00
since Yamp is not maintained anymore, i switched it for Mages
https://github.com/FlorianRappl/Mages fixes also #1022
This commit is contained in:
@@ -4,5 +4,7 @@
|
||||
|
||||
<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_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>
|
||||
@@ -4,5 +4,7 @@
|
||||
|
||||
<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_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 Brackets?)</system:String>
|
||||
<system:String x:Key="wox_plugin_calculator_copy_number_to_clipboard">Copy this Number to the clipboard</system:String>
|
||||
</ResourceDictionary>
|
||||
@@ -1,9 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows;
|
||||
using YAMP;
|
||||
using Mages;
|
||||
using Mages.Core;
|
||||
|
||||
namespace Wox.Plugin.Caculator
|
||||
{
|
||||
@@ -19,15 +19,12 @@ namespace Wox.Plugin.Caculator
|
||||
@"[ei]|[0-9]|[\+\-\*\/\^\., ""]|[\(\)\|\!\[\]]" +
|
||||
@")+$", RegexOptions.Compiled);
|
||||
private static Regex regBrackets = new Regex(@"[\(\)\[\]]", RegexOptions.Compiled);
|
||||
private static ParseContext yampContext;
|
||||
private static Mages.Core.Engine magesEngine;
|
||||
private PluginInitContext context { get; set; }
|
||||
private NumberTranslator _numberTranslator;
|
||||
|
||||
static Main()
|
||||
{
|
||||
yampContext = Parser.PrimaryContext;
|
||||
Parser.InteractiveMode = false;
|
||||
Parser.UseScripting = false;
|
||||
magesEngine = new Engine();
|
||||
}
|
||||
|
||||
public List<Result> Query(Query query)
|
||||
@@ -38,33 +35,38 @@ namespace Wox.Plugin.Caculator
|
||||
|
||||
try
|
||||
{
|
||||
var result = yampContext.Run(this._numberTranslator?.Translate(query.Search) ?? 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 (result != null && !string.IsNullOrEmpty(result.ToString()))
|
||||
{
|
||||
string resultValue = this._numberTranslator?.TranslateBack(result.Result) ?? result.Result;
|
||||
return new List<Result>
|
||||
{ new Result
|
||||
{
|
||||
new Result
|
||||
Title = result.ToString(),
|
||||
IcoPath = "Images/calculator.png",
|
||||
Score = 300,
|
||||
SubTitle = context.API.GetTranslation("wox_plugin_calculator_copy_number_to_clipboard"),
|
||||
Action = c =>
|
||||
{
|
||||
Title = resultValue,
|
||||
IcoPath = "Images/calculator.png",
|
||||
Score = 300,
|
||||
SubTitle = "Copy this number to the clipboard",
|
||||
Action = c =>
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
Clipboard.SetText(resultValue);
|
||||
return true;
|
||||
}
|
||||
catch (ExternalException e)
|
||||
{
|
||||
MessageBox.Show("Copy failed, please try later");
|
||||
return false;
|
||||
}
|
||||
Clipboard.SetText(result.ToString());
|
||||
return true;
|
||||
}
|
||||
catch (ExternalException e)
|
||||
{
|
||||
MessageBox.Show("Copy failed, please try later");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
} };
|
||||
}
|
||||
}
|
||||
catch
|
||||
@@ -95,7 +97,6 @@ namespace Wox.Plugin.Caculator
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
this.context = context;
|
||||
this._numberTranslator = NumberTranslator.Create(CultureInfo.CurrentCulture, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
public string GetTranslatedPluginTitle()
|
||||
|
||||
@@ -38,14 +38,14 @@
|
||||
<HintPath>..\..\packages\JetBrains.Annotations.10.3.0\lib\net\JetBrains.Annotations.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</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="PresentationFramework" />
|
||||
<Reference Include="System" />
|
||||
<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>
|
||||
<Compile Include="..\..\SolutionAssemblyInfo.cs">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<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="YAMP" version="1.4.0" targetFramework="net452" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user