mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
add translator plugin
This commit is contained in:
135
Plugins/WinAlfred.Plugin.Fanyi/HttpRequest.cs
Normal file
135
Plugins/WinAlfred.Plugin.Fanyi/HttpRequest.cs
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Security;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
//From:http://blog.csdn.net/zhoufoxcn/article/details/6404236
|
||||||
|
namespace WinAlfred.Plugin.Fanyi
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 有关HTTP请求的辅助类
|
||||||
|
/// </summary>
|
||||||
|
public class HttpRequest
|
||||||
|
{
|
||||||
|
private static readonly string DefaultUserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
|
||||||
|
/// <summary>
|
||||||
|
/// 创建GET方式的HTTP请求
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="url">请求的URL</param>
|
||||||
|
/// <param name="timeout">请求的超时时间</param>
|
||||||
|
/// <param name="userAgent">请求的客户端浏览器信息,可以为空</param>
|
||||||
|
/// <param name="cookies">随同HTTP请求发送的Cookie信息,如果不需要身份验证可以为空</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static HttpWebResponse CreateGetHttpResponse(string url, int? timeout, string userAgent, CookieCollection cookies)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(url))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("url");
|
||||||
|
}
|
||||||
|
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
|
||||||
|
request.Method = "GET";
|
||||||
|
request.UserAgent = DefaultUserAgent;
|
||||||
|
if (!string.IsNullOrEmpty(userAgent))
|
||||||
|
{
|
||||||
|
request.UserAgent = userAgent;
|
||||||
|
}
|
||||||
|
if (timeout.HasValue)
|
||||||
|
{
|
||||||
|
request.Timeout = timeout.Value;
|
||||||
|
}
|
||||||
|
if (cookies != null)
|
||||||
|
{
|
||||||
|
request.CookieContainer = new CookieContainer();
|
||||||
|
request.CookieContainer.Add(cookies);
|
||||||
|
}
|
||||||
|
return request.GetResponse() as HttpWebResponse;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 创建POST方式的HTTP请求
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="url">请求的URL</param>
|
||||||
|
/// <param name="parameters">随同请求POST的参数名称及参数值字典</param>
|
||||||
|
/// <param name="timeout">请求的超时时间</param>
|
||||||
|
/// <param name="userAgent">请求的客户端浏览器信息,可以为空</param>
|
||||||
|
/// <param name="requestEncoding">发送HTTP请求时所用的编码</param>
|
||||||
|
/// <param name="cookies">随同HTTP请求发送的Cookie信息,如果不需要身份验证可以为空</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static HttpWebResponse CreatePostHttpResponse(string url, IDictionary<string, string> parameters, int? timeout, string userAgent, Encoding requestEncoding, CookieCollection cookies)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(url))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("url");
|
||||||
|
}
|
||||||
|
if (requestEncoding == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("requestEncoding");
|
||||||
|
}
|
||||||
|
HttpWebRequest request = null;
|
||||||
|
//如果是发送HTTPS请求
|
||||||
|
if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
|
||||||
|
request = WebRequest.Create(url) as HttpWebRequest;
|
||||||
|
request.ProtocolVersion = HttpVersion.Version10;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
request = WebRequest.Create(url) as HttpWebRequest;
|
||||||
|
}
|
||||||
|
request.Method = "POST";
|
||||||
|
request.ContentType = "application/x-www-form-urlencoded";
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(userAgent))
|
||||||
|
{
|
||||||
|
request.UserAgent = userAgent;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
request.UserAgent = DefaultUserAgent;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (timeout.HasValue)
|
||||||
|
{
|
||||||
|
request.Timeout = timeout.Value;
|
||||||
|
}
|
||||||
|
if (cookies != null)
|
||||||
|
{
|
||||||
|
request.CookieContainer = new CookieContainer();
|
||||||
|
request.CookieContainer.Add(cookies);
|
||||||
|
}
|
||||||
|
//如果需要POST数据
|
||||||
|
if (!(parameters == null || parameters.Count == 0))
|
||||||
|
{
|
||||||
|
StringBuilder buffer = new StringBuilder();
|
||||||
|
int i = 0;
|
||||||
|
foreach (string key in parameters.Keys)
|
||||||
|
{
|
||||||
|
if (i > 0)
|
||||||
|
{
|
||||||
|
buffer.AppendFormat("&{0}={1}", key, parameters[key]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buffer.AppendFormat("{0}={1}", key, parameters[key]);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
byte[] data = requestEncoding.GetBytes(buffer.ToString());
|
||||||
|
using (Stream stream = request.GetRequestStream())
|
||||||
|
{
|
||||||
|
stream.Write(data, 0, data.Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return request.GetResponse() as HttpWebResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
|
||||||
|
{
|
||||||
|
return true; //总是接受
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
Plugins/WinAlfred.Plugin.Fanyi/Images/translate.png
Normal file
BIN
Plugins/WinAlfred.Plugin.Fanyi/Images/translate.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
114
Plugins/WinAlfred.Plugin.Fanyi/Main.cs
Normal file
114
Plugins/WinAlfred.Plugin.Fanyi/Main.cs
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace WinAlfred.Plugin.Fanyi
|
||||||
|
{
|
||||||
|
public class TranslateResult
|
||||||
|
{
|
||||||
|
public string from { get; set; }
|
||||||
|
public string to { get; set; }
|
||||||
|
public List<SrcDst> trans_result { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SrcDst
|
||||||
|
{
|
||||||
|
public string src { get; set; }
|
||||||
|
public string dst { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Main : IPlugin
|
||||||
|
{
|
||||||
|
private string translateURL = "http://openapi.baidu.com/public/2.0/bmt/translate";
|
||||||
|
private string baiduKey = "SnPcDY3iH5jDbklRewkG2D2v";
|
||||||
|
|
||||||
|
static public string AssemblyDirectory
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
|
||||||
|
UriBuilder uri = new UriBuilder(codeBase);
|
||||||
|
string path = Uri.UnescapeDataString(uri.Path);
|
||||||
|
return Path.GetDirectoryName(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Result> Query(Query query)
|
||||||
|
{
|
||||||
|
List<Result> results = new List<Result>();
|
||||||
|
if (query.ActionParameters.Count == 0)
|
||||||
|
{
|
||||||
|
results.Add(new Result()
|
||||||
|
{
|
||||||
|
Title = "Start to translate between Chinese and English",
|
||||||
|
SubTitle = "Powered by baidu api",
|
||||||
|
IcoPath = "Images\\translate.png"
|
||||||
|
});
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
Dictionary<string, string> data = new Dictionary<string, string>();
|
||||||
|
data.Add("from", "auto");
|
||||||
|
data.Add("to", "auto");
|
||||||
|
data.Add("q", query.RawQuery.Substring(3));
|
||||||
|
data.Add("client_id", baiduKey);
|
||||||
|
HttpWebResponse response = HttpRequest.CreatePostHttpResponse(translateURL, data, null, null, Encoding.UTF8, null);
|
||||||
|
Stream s = response.GetResponseStream();
|
||||||
|
if (s != null)
|
||||||
|
{
|
||||||
|
StreamReader reader = new StreamReader(s, Encoding.UTF8);
|
||||||
|
string json = reader.ReadToEnd();
|
||||||
|
TranslateResult o = JsonConvert.DeserializeObject<TranslateResult>(json);
|
||||||
|
foreach (SrcDst srcDst in o.trans_result)
|
||||||
|
{
|
||||||
|
string dst = srcDst.dst;
|
||||||
|
results.Add(new Result()
|
||||||
|
{
|
||||||
|
Title = dst,
|
||||||
|
SubTitle = "Copy to clipboard",
|
||||||
|
IcoPath = "Images\\translate.png",
|
||||||
|
Action = () =>
|
||||||
|
{
|
||||||
|
Clipboard.SetText(dst);
|
||||||
|
context.ShowMsg("translation has been copyed to your clipboard.", "",
|
||||||
|
AssemblyDirectory + "\\Images\\translate.png");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GetHtmlStr(string url)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
WebRequest rGet = WebRequest.Create(url);
|
||||||
|
WebResponse rSet = rGet.GetResponse();
|
||||||
|
Stream s = rSet.GetResponseStream();
|
||||||
|
StreamReader reader = new StreamReader(s, Encoding.UTF8);
|
||||||
|
return reader.ReadToEnd();
|
||||||
|
}
|
||||||
|
catch (WebException)
|
||||||
|
{
|
||||||
|
//连接失败
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Init(PluginInitContext context)
|
||||||
|
{
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
private PluginInitContext context { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
36
Plugins/WinAlfred.Plugin.Fanyi/Properties/AssemblyInfo.cs
Normal file
36
Plugins/WinAlfred.Plugin.Fanyi/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
// 有关程序集的常规信息通过以下
|
||||||
|
// 特性集控制。更改这些特性值可修改
|
||||||
|
// 与程序集关联的信息。
|
||||||
|
[assembly: AssemblyTitle("WinAlfred.Plugin.Fanyi")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("Microsoft")]
|
||||||
|
[assembly: AssemblyProduct("WinAlfred.Plugin.Fanyi")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © Microsoft 2014")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// 将 ComVisible 设置为 false 使此程序集中的类型
|
||||||
|
// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
|
||||||
|
// 则将该类型上的 ComVisible 特性设置为 true。
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||||
|
[assembly: Guid("5b55da55-94f5-4248-af75-5eb40409a8ca")]
|
||||||
|
|
||||||
|
// 程序集的版本信息由下面四个值组成:
|
||||||
|
//
|
||||||
|
// 主版本
|
||||||
|
// 次版本
|
||||||
|
// 生成号
|
||||||
|
// 修订号
|
||||||
|
//
|
||||||
|
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
||||||
|
// 方法是按如下所示使用“*”:
|
||||||
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
|
[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||||
83
Plugins/WinAlfred.Plugin.Fanyi/WinAlfred.Plugin.Fanyi.csproj
Normal file
83
Plugins/WinAlfred.Plugin.Fanyi/WinAlfred.Plugin.Fanyi.csproj
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProjectGuid>{353769D3-D11C-4D86-BD06-AC8C1D68642B}</ProjectGuid>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>WinAlfred.Plugin.Fanyi</RootNamespace>
|
||||||
|
<AssemblyName>WinAlfred.Plugin.Fanyi</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
|
||||||
|
<RestorePackages>true</RestorePackages>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="HtmlAgilityPack">
|
||||||
|
<HintPath>..\..\packages\HtmlAgilityPack.1.4.6\lib\Net20\HtmlAgilityPack.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Newtonsoft.Json">
|
||||||
|
<HintPath>..\..\packages\Newtonsoft.Json.5.0.8\lib\net35\Newtonsoft.Json.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Windows.Forms" />
|
||||||
|
<Reference Include="System.Xml.Linq" />
|
||||||
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="HttpRequest.cs" />
|
||||||
|
<Compile Include="Main.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\WinAlfred.Plugin\WinAlfred.Plugin.csproj">
|
||||||
|
<Project>{8451ecdd-2ea4-4966-bb0a-7bbc40138e80}</Project>
|
||||||
|
<Name>WinAlfred.Plugin</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="packages.config" />
|
||||||
|
<None Include="plugin.ini">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="Images\translate.png" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<PostBuildEvent>xcopy /Y $(TargetDir)$(TargetFileName) $(SolutionDir)WinAlfred\bin\Debug\Plugins\Fanyi\
|
||||||
|
xcopy /Y $(TargetDir)plugin.ini $(SolutionDir)WinAlfred\bin\Debug\Plugins\Fanyi\
|
||||||
|
xcopy /Y $(ProjectDir)Images\*.* $(SolutionDir)WinAlfred\bin\Debug\Plugins\Fanyi\Images\</PostBuildEvent>
|
||||||
|
</PropertyGroup>
|
||||||
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
<Target Name="BeforeBuild">
|
||||||
|
</Target>
|
||||||
|
<Target Name="AfterBuild">
|
||||||
|
</Target>
|
||||||
|
-->
|
||||||
|
</Project>
|
||||||
5
Plugins/WinAlfred.Plugin.Fanyi/packages.config
Normal file
5
Plugins/WinAlfred.Plugin.Fanyi/packages.config
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<packages>
|
||||||
|
<package id="HtmlAgilityPack" version="1.4.6" targetFramework="net35" />
|
||||||
|
<package id="Newtonsoft.Json" version="5.0.8" targetFramework="net35" />
|
||||||
|
</packages>
|
||||||
8
Plugins/WinAlfred.Plugin.Fanyi/plugin.ini
Normal file
8
Plugins/WinAlfred.Plugin.Fanyi/plugin.ini
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[plugin]
|
||||||
|
ActionKeyword = fy
|
||||||
|
Name = Translator
|
||||||
|
Author = qianlifeng
|
||||||
|
Version = 0.1
|
||||||
|
Language = csharp
|
||||||
|
Description = Chinese and English Translator
|
||||||
|
ExecuteFile = WinAlfred.Plugin.Fanyi.dll
|
||||||
127
WinAlfred.Plugin.System/Common/ChineseToPinYin.cs
Normal file
127
WinAlfred.Plugin.System/Common/ChineseToPinYin.cs
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
//From:http://blog.csdn.net/chamychen/article/details/7976125
|
||||||
|
namespace WinAlfred.Plugin.System.Common
|
||||||
|
{
|
||||||
|
public static class ChineseToPinYin
|
||||||
|
{
|
||||||
|
private static readonly Dictionary<int, string> CodeCollections = new Dictionary<int, string> {
|
||||||
|
{ -20319, "a" }, { -20317, "ai" }, { -20304, "an" }, { -20295, "ang" }, { -20292, "ao" }, { -20283, "ba" }, { -20265, "bai" },
|
||||||
|
{ -20257, "ban" }, { -20242, "bang" }, { -20230, "bao" }, { -20051, "bei" }, { -20036, "ben" }, { -20032, "beng" }, { -20026, "bi" }
|
||||||
|
, { -20002, "bian" }, { -19990, "biao" }, { -19986, "bie" }, { -19982, "bin" }, { -19976, "bing" }, { -19805, "bo" },
|
||||||
|
{ -19784, "bu" }, { -19775, "ca" }, { -19774, "cai" }, { -19763, "can" }, { -19756, "cang" }, { -19751, "cao" }, { -19746, "ce" },
|
||||||
|
{ -19741, "ceng" }, { -19739, "cha" }, { -19728, "chai" }, { -19725, "chan" }, { -19715, "chang" }, { -19540, "chao" },
|
||||||
|
{ -19531, "che" }, { -19525, "chen" }, { -19515, "cheng" }, { -19500, "chi" }, { -19484, "chong" }, { -19479, "chou" },
|
||||||
|
{ -19467, "chu" }, { -19289, "chuai" }, { -19288, "chuan" }, { -19281, "chuang" }, { -19275, "chui" }, { -19270, "chun" },
|
||||||
|
{ -19263, "chuo" }, { -19261, "ci" }, { -19249, "cong" }, { -19243, "cou" }, { -19242, "cu" }, { -19238, "cuan" },
|
||||||
|
{ -19235, "cui" }, { -19227, "cun" }, { -19224, "cuo" }, { -19218, "da" }, { -19212, "dai" }, { -19038, "dan" }, { -19023, "dang" },
|
||||||
|
{ -19018, "dao" }, { -19006, "de" }, { -19003, "deng" }, { -18996, "di" }, { -18977, "dian" }, { -18961, "diao" }, { -18952, "die" }
|
||||||
|
, { -18783, "ding" }, { -18774, "diu" }, { -18773, "dong" }, { -18763, "dou" }, { -18756, "du" }, { -18741, "duan" },
|
||||||
|
{ -18735, "dui" }, { -18731, "dun" }, { -18722, "duo" }, { -18710, "e" }, { -18697, "en" }, { -18696, "er" }, { -18526, "fa" },
|
||||||
|
{ -18518, "fan" }, { -18501, "fang" }, { -18490, "fei" }, { -18478, "fen" }, { -18463, "feng" }, { -18448, "fo" }, { -18447, "fou" }
|
||||||
|
, { -18446, "fu" }, { -18239, "ga" }, { -18237, "gai" }, { -18231, "gan" }, { -18220, "gang" }, { -18211, "gao" }, { -18201, "ge" },
|
||||||
|
{ -18184, "gei" }, { -18183, "gen" }, { -18181, "geng" }, { -18012, "gong" }, { -17997, "gou" }, { -17988, "gu" }, { -17970, "gua" }
|
||||||
|
, { -17964, "guai" }, { -17961, "guan" }, { -17950, "guang" }, { -17947, "gui" }, { -17931, "gun" }, { -17928, "guo" },
|
||||||
|
{ -17922, "ha" }, { -17759, "hai" }, { -17752, "han" }, { -17733, "hang" }, { -17730, "hao" }, { -17721, "he" }, { -17703, "hei" },
|
||||||
|
{ -17701, "hen" }, { -17697, "heng" }, { -17692, "hong" }, { -17683, "hou" }, { -17676, "hu" }, { -17496, "hua" },
|
||||||
|
{ -17487, "huai" }, { -17482, "huan" }, { -17468, "huang" }, { -17454, "hui" }, { -17433, "hun" }, { -17427, "huo" },
|
||||||
|
{ -17417, "ji" }, { -17202, "jia" }, { -17185, "jian" }, { -16983, "jiang" }, { -16970, "jiao" }, { -16942, "jie" },
|
||||||
|
{ -16915, "jin" }, { -16733, "jing" }, { -16708, "jiong" }, { -16706, "jiu" }, { -16689, "ju" }, { -16664, "juan" },
|
||||||
|
{ -16657, "jue" }, { -16647, "jun" }, { -16474, "ka" }, { -16470, "kai" }, { -16465, "kan" }, { -16459, "kang" }, { -16452, "kao" },
|
||||||
|
{ -16448, "ke" }, { -16433, "ken" }, { -16429, "keng" }, { -16427, "kong" }, { -16423, "kou" }, { -16419, "ku" }, { -16412, "kua" }
|
||||||
|
, { -16407, "kuai" }, { -16403, "kuan" }, { -16401, "kuang" }, { -16393, "kui" }, { -16220, "kun" }, { -16216, "kuo" },
|
||||||
|
{ -16212, "la" }, { -16205, "lai" }, { -16202, "lan" }, { -16187, "lang" }, { -16180, "lao" }, { -16171, "le" }, { -16169, "lei" },
|
||||||
|
{ -16158, "leng" }, { -16155, "li" }, { -15959, "lia" }, { -15958, "lian" }, { -15944, "liang" }, { -15933, "liao" },
|
||||||
|
{ -15920, "lie" }, { -15915, "lin" }, { -15903, "ling" }, { -15889, "liu" }, { -15878, "long" }, { -15707, "lou" }, { -15701, "lu" },
|
||||||
|
{ -15681, "lv" }, { -15667, "luan" }, { -15661, "lue" }, { -15659, "lun" }, { -15652, "luo" }, { -15640, "ma" }, { -15631, "mai" },
|
||||||
|
{ -15625, "man" }, { -15454, "mang" }, { -15448, "mao" }, { -15436, "me" }, { -15435, "mei" }, { -15419, "men" },
|
||||||
|
{ -15416, "meng" }, { -15408, "mi" }, { -15394, "mian" }, { -15385, "miao" }, { -15377, "mie" }, { -15375, "min" },
|
||||||
|
{ -15369, "ming" }, { -15363, "miu" }, { -15362, "mo" }, { -15183, "mou" }, { -15180, "mu" }, { -15165, "na" }, { -15158, "nai" },
|
||||||
|
{ -15153, "nan" }, { -15150, "nang" }, { -15149, "nao" }, { -15144, "ne" }, { -15143, "nei" }, { -15141, "nen" }, { -15140, "neng" }
|
||||||
|
, { -15139, "ni" }, { -15128, "nian" }, { -15121, "niang" }, { -15119, "niao" }, { -15117, "nie" }, { -15110, "nin" },
|
||||||
|
{ -15109, "ning" }, { -14941, "niu" }, { -14937, "nong" }, { -14933, "nu" }, { -14930, "nv" }, { -14929, "nuan" }, { -14928, "nue" }
|
||||||
|
, { -14926, "nuo" }, { -14922, "o" }, { -14921, "ou" }, { -14914, "pa" }, { -14908, "pai" }, { -14902, "pan" }, { -14894, "pang" },
|
||||||
|
{ -14889, "pao" }, { -14882, "pei" }, { -14873, "pen" }, { -14871, "peng" }, { -14857, "pi" }, { -14678, "pian" },
|
||||||
|
{ -14674, "piao" }, { -14670, "pie" }, { -14668, "pin" }, { -14663, "ping" }, { -14654, "po" }, { -14645, "pu" }, { -14630, "qi" },
|
||||||
|
{ -14594, "qia" }, { -14429, "qian" }, { -14407, "qiang" }, { -14399, "qiao" }, { -14384, "qie" }, { -14379, "qin" },
|
||||||
|
{ -14368, "qing" }, { -14355, "qiong" }, { -14353, "qiu" }, { -14345, "qu" }, { -14170, "quan" }, { -14159, "que" },
|
||||||
|
{ -14151, "qun" }, { -14149, "ran" }, { -14145, "rang" }, { -14140, "rao" }, { -14137, "re" }, { -14135, "ren" }, { -14125, "reng" }
|
||||||
|
, { -14123, "ri" }, { -14122, "rong" }, { -14112, "rou" }, { -14109, "ru" }, { -14099, "ruan" }, { -14097, "rui" }, { -14094, "run" }
|
||||||
|
, { -14092, "ruo" }, { -14090, "sa" }, { -14087, "sai" }, { -14083, "san" }, { -13917, "sang" }, { -13914, "sao" }, { -13910, "se" }
|
||||||
|
, { -13907, "sen" }, { -13906, "seng" }, { -13905, "sha" }, { -13896, "shai" }, { -13894, "shan" }, { -13878, "shang" },
|
||||||
|
{ -13870, "shao" }, { -13859, "she" }, { -13847, "shen" }, { -13831, "sheng" }, { -13658, "shi" }, { -13611, "shou" },
|
||||||
|
{ -13601, "shu" }, { -13406, "shua" }, { -13404, "shuai" }, { -13400, "shuan" }, { -13398, "shuang" }, { -13395, "shui" },
|
||||||
|
{ -13391, "shun" }, { -13387, "shuo" }, { -13383, "si" }, { -13367, "song" }, { -13359, "sou" }, { -13356, "su" },
|
||||||
|
{ -13343, "suan" }, { -13340, "sui" }, { -13329, "sun" }, { -13326, "suo" }, { -13318, "ta" }, { -13147, "tai" }, { -13138, "tan" },
|
||||||
|
{ -13120, "tang" }, { -13107, "tao" }, { -13096, "te" }, { -13095, "teng" }, { -13091, "ti" }, { -13076, "tian" },
|
||||||
|
{ -13068, "tiao" }, { -13063, "tie" }, { -13060, "ting" }, { -12888, "tong" }, { -12875, "tou" }, { -12871, "tu" },
|
||||||
|
{ -12860, "tuan" }, { -12858, "tui" }, { -12852, "tun" }, { -12849, "tuo" }, { -12838, "wa" }, { -12831, "wai" }, { -12829, "wan" }
|
||||||
|
, { -12812, "wang" }, { -12802, "wei" }, { -12607, "wen" }, { -12597, "weng" }, { -12594, "wo" }, { -12585, "wu" }, { -12556, "xi" }
|
||||||
|
, { -12359, "xia" }, { -12346, "xian" }, { -12320, "xiang" }, { -12300, "xiao" }, { -12120, "xie" }, { -12099, "xin" },
|
||||||
|
{ -12089, "xing" }, { -12074, "xiong" }, { -12067, "xiu" }, { -12058, "xu" }, { -12039, "xuan" }, { -11867, "xue" },
|
||||||
|
{ -11861, "xun" }, { -11847, "ya" }, { -11831, "yan" }, { -11798, "yang" }, { -11781, "yao" }, { -11604, "ye" }, { -11589, "yi" },
|
||||||
|
{ -11536, "yin" }, { -11358, "ying" }, { -11340, "yo" }, { -11339, "yong" }, { -11324, "you" }, { -11303, "yu" },
|
||||||
|
{ -11097, "yuan" }, { -11077, "yue" }, { -11067, "yun" }, { -11055, "za" }, { -11052, "zai" }, { -11045, "zan" },
|
||||||
|
{ -11041, "zang" }, { -11038, "zao" }, { -11024, "ze" }, { -11020, "zei" }, { -11019, "zen" }, { -11018, "zeng" },
|
||||||
|
{ -11014, "zha" }, { -10838, "zhai" }, { -10832, "zhan" }, { -10815, "zhang" }, { -10800, "zhao" }, { -10790, "zhe" },
|
||||||
|
{ -10780, "zhen" }, { -10764, "zheng" }, { -10587, "zhi" }, { -10544, "zhong" }, { -10533, "zhou" }, { -10519, "zhu" },
|
||||||
|
{ -10331, "zhua" }, { -10329, "zhuai" }, { -10328, "zhuan" }, { -10322, "zhuang" }, { -10315, "zhui" }, { -10309, "zhun" },
|
||||||
|
{ -10307, "zhuo" }, { -10296, "zi" }, { -10281, "zong" }, { -10274, "zou" }, { -10270, "zu" }, { -10262, "zuan" }, { -10260, "zui" }
|
||||||
|
, { -10256, "zun" }, { -10254, "zuo" } };
|
||||||
|
/// <summary>
|
||||||
|
/// 汉字转拼音
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="txt"> 需要转换的汉字 </param>
|
||||||
|
/// <returns> 返回汉字对应的拼音 </returns>
|
||||||
|
public static string ToPinYin(string txt)
|
||||||
|
{
|
||||||
|
txt = txt.Trim();
|
||||||
|
byte[] arr = new byte[2]; //每个汉字为2字节
|
||||||
|
StringBuilder result = new StringBuilder();//使用StringBuilder优化字符串连接
|
||||||
|
int charCode = 0;
|
||||||
|
int arr1 = 0;
|
||||||
|
int arr2 = 0;
|
||||||
|
char[] arrChar = txt.ToCharArray();
|
||||||
|
for (int j = 0; j < arrChar.Length; j++) //遍历输入的字符
|
||||||
|
{
|
||||||
|
arr = Encoding.Default.GetBytes(arrChar[j].ToString());//根据系统默认编码得到字节码
|
||||||
|
if (arr.Length == 1)//如果只有1字节说明该字符不是汉字,结束本次循环
|
||||||
|
{
|
||||||
|
result.Append(arrChar[j].ToString());
|
||||||
|
continue;
|
||||||
|
|
||||||
|
}
|
||||||
|
arr1 = (short)(arr[0]); //取字节1
|
||||||
|
arr2 = (short)(arr[1]); //取字节2
|
||||||
|
charCode = arr1 * 256 + arr2 - 65536;//计算汉字的编码
|
||||||
|
|
||||||
|
if (charCode > -10254 || charCode < -20319) //如果不在汉字编码范围内则不改变
|
||||||
|
{
|
||||||
|
result.Append(arrChar[j]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//根据汉字编码范围查找对应的拼音并保存到结果中
|
||||||
|
//由于charCode的键不一定存在,所以要找比他更小的键上一个键
|
||||||
|
if (!CodeCollections.ContainsKey(charCode))
|
||||||
|
{
|
||||||
|
for (int i = charCode; i <= 0; --i)
|
||||||
|
{
|
||||||
|
if (CodeCollections.ContainsKey(i))
|
||||||
|
{
|
||||||
|
result.Append(" " + CodeCollections[i] + " ");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result.Append(" " + CodeCollections[charCode] + " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
|
using WinAlfred.Plugin.System.Common;
|
||||||
|
|
||||||
namespace WinAlfred.Plugin.System
|
namespace WinAlfred.Plugin.System
|
||||||
{
|
{
|
||||||
@@ -14,21 +15,30 @@ namespace WinAlfred.Plugin.System
|
|||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
public string IcoPath { get; set; }
|
public string IcoPath { get; set; }
|
||||||
public string ExecutePath { get; set; }
|
public string ExecutePath { get; set; }
|
||||||
|
public int Score { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Programs : ISystemPlugin
|
public class Programs : ISystemPlugin
|
||||||
{
|
{
|
||||||
|
//TODO:add score for MRU program
|
||||||
|
|
||||||
|
private List<string> indexDirectory = new List<string>();
|
||||||
|
private List<string> indexPostfix = new List<string> { "lnk", "exe" };
|
||||||
|
|
||||||
List<Program> installedList = new List<Program>();
|
List<Program> installedList = new List<Program>();
|
||||||
|
|
||||||
public List<Result> Query(Query query)
|
public List<Result> Query(Query query)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(query.RawQuery) || query.RawQuery.Length <= 1) return new List<Result>();
|
if (string.IsNullOrEmpty(query.RawQuery) || query.RawQuery.EndsWith(" ") || query.RawQuery.Length <= 1) return new List<Result>();
|
||||||
|
|
||||||
return installedList.Where(o => o.Title.ToLower().Contains(query.RawQuery.ToLower())).Select(c => new Result()
|
List<Program> returnList = installedList.Where(o => MatchProgram(o, query)).ToList();
|
||||||
|
returnList.ForEach(ScoreFilter);
|
||||||
|
|
||||||
|
return returnList.Select(c => new Result()
|
||||||
{
|
{
|
||||||
Title = c.Title,
|
Title = c.Title,
|
||||||
IcoPath = c.IcoPath,
|
IcoPath = c.IcoPath,
|
||||||
Score = 10,
|
Score = c.Score,
|
||||||
Action = () =>
|
Action = () =>
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(c.ExecutePath))
|
if (string.IsNullOrEmpty(c.ExecutePath))
|
||||||
@@ -43,18 +53,27 @@ namespace WinAlfred.Plugin.System
|
|||||||
}).ToList();
|
}).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool MatchProgram(Program program, Query query)
|
||||||
|
{
|
||||||
|
if (program.Title.ToLower().Contains(query.RawQuery.ToLower())) return true;
|
||||||
|
if (ChineseToPinYin.ToPinYin(program.Title).Replace(" ", "").ToLower().Contains(query.RawQuery.ToLower())) return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public void Init(PluginInitContext context)
|
public void Init(PluginInitContext context)
|
||||||
{
|
{
|
||||||
|
indexDirectory.Add(Environment.GetFolderPath(Environment.SpecialFolder.Programs));
|
||||||
|
indexDirectory.Add(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\Microsoft\Windows\Start Menu\Programs");
|
||||||
|
|
||||||
GetAppFromStartMenu();
|
GetAppFromStartMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GetAppFromStartMenu()
|
private void GetAppFromStartMenu()
|
||||||
{
|
{
|
||||||
List<string> path =
|
foreach (string directory in indexDirectory)
|
||||||
Directory.GetDirectories(Environment.GetFolderPath(Environment.SpecialFolder.Programs)).ToList();
|
|
||||||
foreach (string s in path)
|
|
||||||
{
|
{
|
||||||
GetAppFromDirectory(s);
|
GetAppFromDirectory(directory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,12 +81,13 @@ namespace WinAlfred.Plugin.System
|
|||||||
{
|
{
|
||||||
foreach (string file in Directory.GetFiles(path))
|
foreach (string file in Directory.GetFiles(path))
|
||||||
{
|
{
|
||||||
if (file.EndsWith(".lnk") || file.EndsWith(".exe"))
|
if (indexPostfix.Any(o => file.EndsWith("." + o)))
|
||||||
{
|
{
|
||||||
Program p = new Program()
|
Program p = new Program()
|
||||||
{
|
{
|
||||||
Title = getAppNameFromAppPath(file),
|
Title = getAppNameFromAppPath(file),
|
||||||
IcoPath = file,
|
IcoPath = file,
|
||||||
|
Score = 10,
|
||||||
ExecutePath = file
|
ExecutePath = file
|
||||||
};
|
};
|
||||||
installedList.Add(p);
|
installedList.Add(p);
|
||||||
@@ -80,6 +100,18 @@ namespace WinAlfred.Plugin.System
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ScoreFilter(Program p)
|
||||||
|
{
|
||||||
|
if (p.Title.Contains("启动") || p.Title.ToLower().Contains("start"))
|
||||||
|
{
|
||||||
|
p.Score += 10;
|
||||||
|
}
|
||||||
|
if (p.Title.Contains("卸载") || p.Title.ToLower().Contains("uninstall"))
|
||||||
|
{
|
||||||
|
p.Score -= 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private string getAppNameFromAppPath(string app)
|
private string getAppNameFromAppPath(string app)
|
||||||
{
|
{
|
||||||
string temp = app.Substring(app.LastIndexOf('\\') + 1);
|
string temp = app.Substring(app.LastIndexOf('\\') + 1);
|
||||||
|
|||||||
@@ -62,6 +62,14 @@ namespace WinAlfred.Plugin.System
|
|||||||
IcoPath = "Images\\lock.png",
|
IcoPath = "Images\\lock.png",
|
||||||
Action = () => LockWorkStation()
|
Action = () => LockWorkStation()
|
||||||
});
|
});
|
||||||
|
availableResults.Add(new Result
|
||||||
|
{
|
||||||
|
Title = "Exit",
|
||||||
|
SubTitle = "Close this app",
|
||||||
|
Score = 110,
|
||||||
|
IcoPath = "Images\\exit.png",
|
||||||
|
Action = () => context.CloseApp()
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name
|
public string Name
|
||||||
|
|||||||
@@ -40,6 +40,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="CMD.cs" />
|
<Compile Include="CMD.cs" />
|
||||||
|
<Compile Include="Common\ChineseToPinYin.cs" />
|
||||||
<Compile Include="ISystemPlugin.cs" />
|
<Compile Include="ISystemPlugin.cs" />
|
||||||
<Compile Include="Programs.cs" />
|
<Compile Include="Programs.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
|||||||
@@ -8,6 +8,11 @@ namespace WinAlfred.Plugin
|
|||||||
public class PluginInitContext
|
public class PluginInitContext
|
||||||
{
|
{
|
||||||
public List<PluginPair> Plugins { get; set; }
|
public List<PluginPair> Plugins { get; set; }
|
||||||
|
|
||||||
public Action<string> ChangeQuery { get; set; }
|
public Action<string> ChangeQuery { get; set; }
|
||||||
|
public Action CloseApp { get; set; }
|
||||||
|
public Action HideApp { get; set; }
|
||||||
|
public Action ShowApp { get; set; }
|
||||||
|
public Action<string,string,string> ShowMsg { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ namespace WinAlfred.Plugin
|
|||||||
public Action Action { get; set; }
|
public Action Action { get; set; }
|
||||||
public int Score { get; set; }
|
public int Score { get; set; }
|
||||||
|
|
||||||
|
public bool DontHideWinAlfredAfterAction { get; set; }
|
||||||
|
|
||||||
//todo: this should be controlled by system, not visible to users
|
//todo: this should be controlled by system, not visible to users
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Only resulsts that originQuery match with curren query will be displayed in the panel
|
/// Only resulsts that originQuery match with curren query will be displayed in the panel
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Plugin", "Plugin", "{3A73F5
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinAlfred", "WinAlfred\WinAlfred.csproj", "{DB90F671-D861-46BB-93A3-F1304F5BA1C5}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinAlfred", "WinAlfred\WinAlfred.csproj", "{DB90F671-D861-46BB-93A3-F1304F5BA1C5}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PyWinAlfred", "PyWinAlfred\PyWinAlfred.vcxproj", "{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}"
|
|
||||||
EndProject
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinAlfred.Plugin.System", "WinAlfred.Plugin.System\WinAlfred.Plugin.System.csproj", "{69CE0206-CB41-453D-88AF-DF86092EF9B8}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinAlfred.Plugin.System", "WinAlfred.Plugin.System\WinAlfred.Plugin.System.csproj", "{69CE0206-CB41-453D-88AF-DF86092EF9B8}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinAlfred.Plugin.Fanyi", "Plugins\WinAlfred.Plugin.Fanyi\WinAlfred.Plugin.Fanyi.csproj", "{353769D3-D11C-4D86-BD06-AC8C1D68642B}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -52,8 +52,8 @@ Global
|
|||||||
{8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Debug|x86.Build.0 = Debug|Any CPU
|
{8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
{8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Release|Any CPU.Build.0 = Release|Any CPU
|
{8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Release|Mixed Platforms.ActiveCfg = Release|x86
|
{8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||||
{8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Release|Mixed Platforms.Build.0 = Release|x86
|
{8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||||
{8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Release|Win32.ActiveCfg = Release|x86
|
{8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Release|Win32.ActiveCfg = Release|x86
|
||||||
{8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Release|Win32.Build.0 = Release|x86
|
{8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Release|Win32.Build.0 = Release|x86
|
||||||
{8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Release|x64.ActiveCfg = Release|Any CPU
|
{8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
@@ -72,24 +72,6 @@ Global
|
|||||||
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Release|Win32.ActiveCfg = Release|Any CPU
|
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Release|Win32.ActiveCfg = Release|Any CPU
|
||||||
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Release|x64.ActiveCfg = Release|Any CPU
|
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Release|x86.ActiveCfg = Release|Any CPU
|
{DB90F671-D861-46BB-93A3-F1304F5BA1C5}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Debug|Any CPU.ActiveCfg = Debug|Win32
|
|
||||||
{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Debug|Mixed Platforms.ActiveCfg = Debug|x64
|
|
||||||
{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Debug|Mixed Platforms.Build.0 = Debug|x64
|
|
||||||
{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Debug|Win32.ActiveCfg = Debug|Win32
|
|
||||||
{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Debug|Win32.Build.0 = Debug|Win32
|
|
||||||
{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Debug|x64.ActiveCfg = Debug|x64
|
|
||||||
{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Debug|x64.Build.0 = Debug|x64
|
|
||||||
{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Debug|x86.ActiveCfg = Debug|Win32
|
|
||||||
{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Debug|x86.Build.0 = Debug|Win32
|
|
||||||
{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Release|Any CPU.ActiveCfg = Release|Win32
|
|
||||||
{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Release|Mixed Platforms.ActiveCfg = Release|Win32
|
|
||||||
{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Release|Mixed Platforms.Build.0 = Release|Win32
|
|
||||||
{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Release|Win32.ActiveCfg = Release|Win32
|
|
||||||
{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Release|Win32.Build.0 = Release|Win32
|
|
||||||
{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Release|x64.ActiveCfg = Release|x64
|
|
||||||
{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Release|x64.Build.0 = Release|x64
|
|
||||||
{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Release|x86.ActiveCfg = Release|Win32
|
|
||||||
{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Release|x86.Build.0 = Release|Win32
|
|
||||||
{69CE0206-CB41-453D-88AF-DF86092EF9B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{69CE0206-CB41-453D-88AF-DF86092EF9B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{69CE0206-CB41-453D-88AF-DF86092EF9B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{69CE0206-CB41-453D-88AF-DF86092EF9B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{69CE0206-CB41-453D-88AF-DF86092EF9B8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
{69CE0206-CB41-453D-88AF-DF86092EF9B8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||||
@@ -104,8 +86,25 @@ Global
|
|||||||
{69CE0206-CB41-453D-88AF-DF86092EF9B8}.Release|Win32.ActiveCfg = Release|Any CPU
|
{69CE0206-CB41-453D-88AF-DF86092EF9B8}.Release|Win32.ActiveCfg = Release|Any CPU
|
||||||
{69CE0206-CB41-453D-88AF-DF86092EF9B8}.Release|x64.ActiveCfg = Release|Any CPU
|
{69CE0206-CB41-453D-88AF-DF86092EF9B8}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
{69CE0206-CB41-453D-88AF-DF86092EF9B8}.Release|x86.ActiveCfg = Release|Any CPU
|
{69CE0206-CB41-453D-88AF-DF86092EF9B8}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{353769D3-D11C-4D86-BD06-AC8C1D68642B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{353769D3-D11C-4D86-BD06-AC8C1D68642B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{353769D3-D11C-4D86-BD06-AC8C1D68642B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||||
|
{353769D3-D11C-4D86-BD06-AC8C1D68642B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||||
|
{353769D3-D11C-4D86-BD06-AC8C1D68642B}.Debug|Win32.ActiveCfg = Debug|Any CPU
|
||||||
|
{353769D3-D11C-4D86-BD06-AC8C1D68642B}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{353769D3-D11C-4D86-BD06-AC8C1D68642B}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{353769D3-D11C-4D86-BD06-AC8C1D68642B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{353769D3-D11C-4D86-BD06-AC8C1D68642B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{353769D3-D11C-4D86-BD06-AC8C1D68642B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||||
|
{353769D3-D11C-4D86-BD06-AC8C1D68642B}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||||
|
{353769D3-D11C-4D86-BD06-AC8C1D68642B}.Release|Win32.ActiveCfg = Release|Any CPU
|
||||||
|
{353769D3-D11C-4D86-BD06-AC8C1D68642B}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{353769D3-D11C-4D86-BD06-AC8C1D68642B}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
|
GlobalSection(NestedProjects) = preSolution
|
||||||
|
{353769D3-D11C-4D86-BD06-AC8C1D68642B} = {3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87}
|
||||||
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using WinAlfred.Helper;
|
using WinAlfred.Helper;
|
||||||
using WinAlfred.Plugin;
|
using WinAlfred.Plugin;
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ namespace WinAlfred.Helper
|
|||||||
if (!RegisterHotKey(window.Handle, currentId, (uint)xModifier, (uint)key))
|
if (!RegisterHotKey(window.Handle, currentId, (uint)xModifier, (uint)key))
|
||||||
{
|
{
|
||||||
Log.Error("Couldn’t register the hot key.");
|
Log.Error("Couldn’t register the hot key.");
|
||||||
|
MessageBox.Show("Couldn’t register the hot key.");
|
||||||
#if (DEBUG)
|
#if (DEBUG)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Couldn’t register the hot key.");
|
throw new InvalidOperationException("Couldn’t register the hot key.");
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using System.Windows;
|
|||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
using Noesis.Javascript;
|
||||||
using WinAlfred.Commands;
|
using WinAlfred.Commands;
|
||||||
using WinAlfred.Helper;
|
using WinAlfred.Helper;
|
||||||
using WinAlfred.Plugin;
|
using WinAlfred.Plugin;
|
||||||
@@ -39,11 +40,7 @@ namespace WinAlfred
|
|||||||
System.Windows.Forms.MenuItem open = new System.Windows.Forms.MenuItem("Open");
|
System.Windows.Forms.MenuItem open = new System.Windows.Forms.MenuItem("Open");
|
||||||
open.Click += (o, e) => ShowWinAlfred();
|
open.Click += (o, e) => ShowWinAlfred();
|
||||||
System.Windows.Forms.MenuItem exit = new System.Windows.Forms.MenuItem("Exit");
|
System.Windows.Forms.MenuItem exit = new System.Windows.Forms.MenuItem("Exit");
|
||||||
exit.Click += (o, e) =>
|
exit.Click += (o, e) => CloseApp();
|
||||||
{
|
|
||||||
notifyIcon.Visible = false;
|
|
||||||
Close();
|
|
||||||
};
|
|
||||||
System.Windows.Forms.MenuItem[] childen = { open, exit };
|
System.Windows.Forms.MenuItem[] childen = { open, exit };
|
||||||
notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu(childen);
|
notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu(childen);
|
||||||
}
|
}
|
||||||
@@ -68,6 +65,30 @@ namespace WinAlfred
|
|||||||
|
|
||||||
private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e)
|
private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Initialize a context
|
||||||
|
using (JavascriptContext context = new JavascriptContext())
|
||||||
|
{
|
||||||
|
|
||||||
|
// Setting external parameters for the context
|
||||||
|
context.SetParameter("message", "Hello World !");
|
||||||
|
context.SetParameter("number", 1);
|
||||||
|
|
||||||
|
// Script
|
||||||
|
string script = @"
|
||||||
|
var i;
|
||||||
|
for (i = 0; i < 5; i++)
|
||||||
|
console.Print(message + ' (' + i + ')');
|
||||||
|
number += i;
|
||||||
|
";
|
||||||
|
|
||||||
|
// Running the script
|
||||||
|
context.Run(script);
|
||||||
|
|
||||||
|
// Getting a parameter
|
||||||
|
MessageBox.Show("number: " + context.GetParameter("number"));
|
||||||
|
}
|
||||||
|
|
||||||
//MessageBox.Show("s");
|
//MessageBox.Show("s");
|
||||||
resultCtrl.Dirty = true;
|
resultCtrl.Dirty = true;
|
||||||
////auto clear results after 50ms if there are any results returned by plugins
|
////auto clear results after 50ms if there are any results returned by plugins
|
||||||
@@ -91,7 +112,7 @@ namespace WinAlfred
|
|||||||
Hide();
|
Hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShowWinAlfred()
|
private void ShowWinAlfred()
|
||||||
{
|
{
|
||||||
Show();
|
Show();
|
||||||
//FocusManager.SetFocusedElement(this, tbQuery);
|
//FocusManager.SetFocusedElement(this, tbQuery);
|
||||||
@@ -104,6 +125,9 @@ namespace WinAlfred
|
|||||||
Plugins.Init(this);
|
Plugins.Init(this);
|
||||||
cmdDispatcher = new Command(this);
|
cmdDispatcher = new Command(this);
|
||||||
InitialTray();
|
InitialTray();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void TbQuery_OnPreviewKeyDown(object sender, KeyEventArgs e)
|
private void TbQuery_OnPreviewKeyDown(object sender, KeyEventArgs e)
|
||||||
@@ -126,8 +150,7 @@ namespace WinAlfred
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Key.Enter:
|
case Key.Enter:
|
||||||
resultCtrl.AcceptSelect();
|
if (resultCtrl.AcceptSelect()) HideWinAlfred();
|
||||||
HideWinAlfred();
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -141,5 +164,39 @@ namespace WinAlfred
|
|||||||
resultCtrl.AddResults(l);
|
resultCtrl.AddResults(l);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Public API
|
||||||
|
|
||||||
|
//Those method can be invoked by plugins
|
||||||
|
|
||||||
|
public void ChangeQuery(string query)
|
||||||
|
{
|
||||||
|
tbQuery.Text = query;
|
||||||
|
tbQuery.CaretIndex = tbQuery.Text.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CloseApp()
|
||||||
|
{
|
||||||
|
notifyIcon.Visible = false;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void HideApp()
|
||||||
|
{
|
||||||
|
HideWinAlfred();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ShowApp()
|
||||||
|
{
|
||||||
|
ShowWinAlfred();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ShowMsg(string title, string subTitle, string iconPath)
|
||||||
|
{
|
||||||
|
Msg m = new Msg { Owner = GetWindow(this) };
|
||||||
|
m.Show(title, subTitle, iconPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
38
WinAlfred/Msg.xaml
Normal file
38
WinAlfred/Msg.xaml
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<Window x:Class="WinAlfred.Msg"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
Background="#ebebeb"
|
||||||
|
Topmost="True"
|
||||||
|
SizeToContent="Height"
|
||||||
|
ResizeMode="NoResize"
|
||||||
|
WindowStyle="None"
|
||||||
|
ShowInTaskbar="False"
|
||||||
|
Title="Msg" Height="60" Width="382.978">
|
||||||
|
<Window.Triggers>
|
||||||
|
<EventTrigger RoutedEvent="Window.Loaded">
|
||||||
|
<BeginStoryboard>
|
||||||
|
<Storyboard >
|
||||||
|
<DoubleAnimation x:Name="showAnimation" Duration="0:0:0.3" Storyboard.TargetProperty="Top" AccelerationRatio="0.2"/>
|
||||||
|
</Storyboard>
|
||||||
|
</BeginStoryboard>
|
||||||
|
</EventTrigger>
|
||||||
|
|
||||||
|
</Window.Triggers>
|
||||||
|
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5">
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="32"></ColumnDefinition>
|
||||||
|
<ColumnDefinition/>
|
||||||
|
<ColumnDefinition Width="32"></ColumnDefinition>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Image x:Name="imgIco" Width="32" Height="32" HorizontalAlignment="Left" ></Image>
|
||||||
|
<Grid HorizontalAlignment="Stretch" Margin="5 0 0 0" Grid.Column="1" VerticalAlignment="Stretch">
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="29"></RowDefinition>
|
||||||
|
<RowDefinition></RowDefinition>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<TextBlock x:Name="tbTitle" FontSize="16" Foreground="#37392c" FontWeight="Medium">Title</TextBlock>
|
||||||
|
<TextBlock Grid.Row="1" Foreground="#8e94a4" x:Name="tbSubTitle">sdfdsf</TextBlock>
|
||||||
|
</Grid>
|
||||||
|
<Image x:Name="imgClose" Grid.Column="2" Cursor="Hand" Width="16" VerticalAlignment="Top" HorizontalAlignment="Right" />
|
||||||
|
</Grid>
|
||||||
|
</Window>
|
||||||
82
WinAlfred/Msg.xaml.cs
Normal file
82
WinAlfred/Msg.xaml.cs
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Data;
|
||||||
|
using System.Windows.Documents;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Animation;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
using Timer = System.Threading.Timer;
|
||||||
|
|
||||||
|
namespace WinAlfred
|
||||||
|
{
|
||||||
|
public partial class Msg : Window
|
||||||
|
{
|
||||||
|
Storyboard fadeOutStoryboard = new Storyboard();
|
||||||
|
private bool closing = false;
|
||||||
|
|
||||||
|
public Msg()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
Left = Screen.PrimaryScreen.WorkingArea.Right - this.Width;
|
||||||
|
Top = Screen.PrimaryScreen.Bounds.Bottom;
|
||||||
|
showAnimation.From = Screen.PrimaryScreen.Bounds.Bottom;
|
||||||
|
showAnimation.To = Screen.PrimaryScreen.WorkingArea.Bottom - Height;
|
||||||
|
|
||||||
|
// Create the fade out storyboard
|
||||||
|
fadeOutStoryboard.Completed += new EventHandler(fadeOutStoryboard_Completed);
|
||||||
|
DoubleAnimation fadeOutAnimation = new DoubleAnimation(Screen.PrimaryScreen.WorkingArea.Bottom - Height, Screen.PrimaryScreen.Bounds.Bottom, new Duration(TimeSpan.FromSeconds(0.3)))
|
||||||
|
{
|
||||||
|
AccelerationRatio = 0.2
|
||||||
|
};
|
||||||
|
Storyboard.SetTarget(fadeOutAnimation, this);
|
||||||
|
Storyboard.SetTargetProperty(fadeOutAnimation, new PropertyPath(TopProperty));
|
||||||
|
fadeOutStoryboard.Children.Add(fadeOutAnimation);
|
||||||
|
|
||||||
|
imgClose.Source = new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + "\\Images\\close.png"));
|
||||||
|
imgClose.MouseUp += imgClose_MouseUp;
|
||||||
|
}
|
||||||
|
|
||||||
|
void imgClose_MouseUp(object sender, MouseButtonEventArgs e)
|
||||||
|
{
|
||||||
|
if (!closing)
|
||||||
|
{
|
||||||
|
closing = true;
|
||||||
|
fadeOutStoryboard.Begin();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fadeOutStoryboard_Completed(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Show(string title, string subTitle, string icopath)
|
||||||
|
{
|
||||||
|
tbTitle.Text = title;
|
||||||
|
tbSubTitle.Text = subTitle;
|
||||||
|
if (!File.Exists(icopath))
|
||||||
|
{
|
||||||
|
icopath = AppDomain.CurrentDomain.BaseDirectory + "Images\\ico.png";
|
||||||
|
}
|
||||||
|
imgIco.Source = new BitmapImage(new Uri(icopath));
|
||||||
|
Show();
|
||||||
|
new Timer(o =>
|
||||||
|
{
|
||||||
|
if (!closing)
|
||||||
|
{
|
||||||
|
closing = true;
|
||||||
|
Dispatcher.Invoke(new Action(fadeOutStoryboard.Begin));
|
||||||
|
}
|
||||||
|
}, null, TimeSpan.FromSeconds(3), TimeSpan.FromMilliseconds(-1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,11 +22,11 @@ namespace WinAlfred.PluginLoader
|
|||||||
ThreadPool.QueueUserWorkItem(o => plugin1.Init(new PluginInitContext()
|
ThreadPool.QueueUserWorkItem(o => plugin1.Init(new PluginInitContext()
|
||||||
{
|
{
|
||||||
Plugins = plugins,
|
Plugins = plugins,
|
||||||
ChangeQuery = s =>
|
ChangeQuery = s => window.ChangeQuery(s),
|
||||||
{
|
CloseApp = window.CloseApp,
|
||||||
window.tbQuery.Text = s;
|
HideApp = window.HideApp,
|
||||||
window.ShowWinAlfred();
|
ShowApp = window.ShowApp,
|
||||||
}
|
ShowMsg = (title,subTitle,iconPath) => window.ShowMsg(title,subTitle,iconPath)
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -192,14 +192,21 @@ namespace WinAlfred
|
|||||||
Select(0);
|
Select(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AcceptSelect()
|
public bool AcceptSelect()
|
||||||
{
|
{
|
||||||
int index = GetCurrentSelectedResultIndex();
|
int index = GetCurrentSelectedResultIndex();
|
||||||
var resultItemControl = pnlContainer.Children[index] as ResultItem;
|
var resultItemControl = pnlContainer.Children[index] as ResultItem;
|
||||||
if (resultItemControl != null)
|
if (resultItemControl != null)
|
||||||
{
|
{
|
||||||
if (resultItemControl.Result.Action != null) resultItemControl.Result.Action();
|
if (resultItemControl.Result.Action != null)
|
||||||
|
{
|
||||||
|
resultItemControl.Result.Action();
|
||||||
|
}
|
||||||
|
|
||||||
|
return !resultItemControl.Result.DontHideWinAlfredAfterAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResultPanel()
|
public ResultPanel()
|
||||||
|
|||||||
@@ -39,22 +39,50 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<ApplicationIcon>app.ico</ApplicationIcon>
|
<ApplicationIcon>app.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||||
|
<OutputPath>bin\x64\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||||
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="Accessibility" />
|
||||||
<Reference Include="log4net">
|
<Reference Include="log4net">
|
||||||
<HintPath>..\packages\log4net.2.0.3\lib\net35-full\log4net.dll</HintPath>
|
<HintPath>..\packages\log4net.2.0.3\lib\net35-full\log4net.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Newtonsoft.Json">
|
<Reference Include="Newtonsoft.Json">
|
||||||
<HintPath>..\packages\Newtonsoft.Json.5.0.8\lib\net35\Newtonsoft.Json.dll</HintPath>
|
<HintPath>..\packages\Newtonsoft.Json.5.0.8\lib\net35\Newtonsoft.Json.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="Noesis.Javascript">
|
||||||
|
<HintPath>C:\Users\Scott\Desktop\x64\Noesis.Javascript.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="PresentationUI, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
|
||||||
|
<Reference Include="ReachFramework" />
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Deployment" />
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
|
<Reference Include="System.Printing" />
|
||||||
<Reference Include="System.Windows.Forms" />
|
<Reference Include="System.Windows.Forms" />
|
||||||
<Reference Include="System.Xaml" />
|
<Reference Include="System.Xaml" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
|
<Reference Include="UIAutomationProvider" />
|
||||||
|
<Reference Include="UIAutomationTypes" />
|
||||||
<Reference Include="WindowsBase" />
|
<Reference Include="WindowsBase" />
|
||||||
<Reference Include="PresentationCore" />
|
<Reference Include="PresentationCore" />
|
||||||
<Reference Include="PresentationFramework" />
|
<Reference Include="PresentationFramework" />
|
||||||
@@ -71,6 +99,9 @@
|
|||||||
<Compile Include="Helper\KeyboardHook.cs" />
|
<Compile Include="Helper\KeyboardHook.cs" />
|
||||||
<Compile Include="Helper\Log.cs" />
|
<Compile Include="Helper\Log.cs" />
|
||||||
<Compile Include="Helper\WinAlfredException.cs" />
|
<Compile Include="Helper\WinAlfredException.cs" />
|
||||||
|
<Compile Include="Msg.xaml.cs">
|
||||||
|
<DependentUpon>Msg.xaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
<Compile Include="PluginLoader\BasePluginLoader.cs" />
|
<Compile Include="PluginLoader\BasePluginLoader.cs" />
|
||||||
<Compile Include="PluginLoader\CSharpPluginLoader.cs" />
|
<Compile Include="PluginLoader\CSharpPluginLoader.cs" />
|
||||||
<Compile Include="Helper\IniParser.cs" />
|
<Compile Include="Helper\IniParser.cs" />
|
||||||
@@ -95,6 +126,10 @@
|
|||||||
<DependentUpon>MainWindow.xaml</DependentUpon>
|
<DependentUpon>MainWindow.xaml</DependentUpon>
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Page Include="Msg.xaml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
</Page>
|
||||||
<Page Include="ResultPanel.xaml">
|
<Page Include="ResultPanel.xaml">
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
|||||||
Reference in New Issue
Block a user