mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-10 21:41:51 +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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user