2020-09-10 11:01:30 +08:00
|
|
|
|
// Copyright (c) Microsoft Corporation
|
|
|
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using Wox.Plugin;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.Plugin.Calculator
|
|
|
|
|
{
|
|
|
|
|
public static class ResultHelper
|
|
|
|
|
{
|
|
|
|
|
public static Result CreateResult(CalculateResult result, string iconPath)
|
|
|
|
|
{
|
2020-10-08 23:57:17 +08:00
|
|
|
|
return CreateResult(result.RoundedResult, iconPath);
|
2020-09-10 11:01:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-08 23:57:17 +08:00
|
|
|
|
public static Result CreateResult(decimal roundedResult, string iconPath)
|
2020-09-10 11:01:30 +08:00
|
|
|
|
{
|
|
|
|
|
return new Result
|
|
|
|
|
{
|
|
|
|
|
Title = roundedResult.ToString(CultureInfo.CurrentCulture),
|
|
|
|
|
IcoPath = iconPath,
|
|
|
|
|
Score = 300,
|
|
|
|
|
SubTitle = Properties.Resources.wox_plugin_calculator_copy_number_to_clipboard,
|
2020-10-08 23:57:17 +08:00
|
|
|
|
Action = c => Action(roundedResult),
|
2020-09-10 11:01:30 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-08 23:57:17 +08:00
|
|
|
|
public static bool Action(decimal roundedResult)
|
2020-09-10 11:01:30 +08:00
|
|
|
|
{
|
|
|
|
|
var ret = false;
|
2020-10-08 23:57:17 +08:00
|
|
|
|
|
2020-09-10 11:01:30 +08:00
|
|
|
|
var thread = new Thread(() =>
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-10-08 23:57:17 +08:00
|
|
|
|
Clipboard.SetText(roundedResult.ToString(CultureInfo.CurrentUICulture.NumberFormat));
|
2020-09-10 11:01:30 +08:00
|
|
|
|
ret = true;
|
|
|
|
|
}
|
|
|
|
|
catch (ExternalException)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(Properties.Resources.wox_plugin_calculator_copy_failed);
|
|
|
|
|
}
|
|
|
|
|
});
|
2020-10-08 23:57:17 +08:00
|
|
|
|
|
2020-09-10 11:01:30 +08:00
|
|
|
|
thread.SetApartmentState(ApartmentState.STA);
|
|
|
|
|
thread.Start();
|
|
|
|
|
thread.Join();
|
2020-10-08 23:57:17 +08:00
|
|
|
|
|
2020-09-10 11:01:30 +08:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|