diff --git a/Plugins/WinAlfred.Plugin.Fanyi/HttpRequest.cs b/Plugins/WinAlfred.Plugin.Fanyi/HttpRequest.cs
new file mode 100644
index 000000000..385ccec7a
--- /dev/null
+++ b/Plugins/WinAlfred.Plugin.Fanyi/HttpRequest.cs
@@ -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
+{
+ ///
+ /// 有关HTTP请求的辅助类
+ ///
+ 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)";
+ ///
+ /// 创建GET方式的HTTP请求
+ ///
+ /// 请求的URL
+ /// 请求的超时时间
+ /// 请求的客户端浏览器信息,可以为空
+ /// 随同HTTP请求发送的Cookie信息,如果不需要身份验证可以为空
+ ///
+ 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;
+ }
+ ///
+ /// 创建POST方式的HTTP请求
+ ///
+ /// 请求的URL
+ /// 随同请求POST的参数名称及参数值字典
+ /// 请求的超时时间
+ /// 请求的客户端浏览器信息,可以为空
+ /// 发送HTTP请求时所用的编码
+ /// 随同HTTP请求发送的Cookie信息,如果不需要身份验证可以为空
+ ///
+ public static HttpWebResponse CreatePostHttpResponse(string url, IDictionary 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; //总是接受
+ }
+ }
+}
diff --git a/Plugins/WinAlfred.Plugin.Fanyi/Images/translate.png b/Plugins/WinAlfred.Plugin.Fanyi/Images/translate.png
new file mode 100644
index 000000000..11be5bc95
Binary files /dev/null and b/Plugins/WinAlfred.Plugin.Fanyi/Images/translate.png differ
diff --git a/Plugins/WinAlfred.Plugin.Fanyi/Main.cs b/Plugins/WinAlfred.Plugin.Fanyi/Main.cs
new file mode 100644
index 000000000..66559b8be
--- /dev/null
+++ b/Plugins/WinAlfred.Plugin.Fanyi/Main.cs
@@ -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 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 Query(Query query)
+ {
+ List results = new List();
+ 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 data = new Dictionary();
+ 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(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; }
+ }
+}
diff --git a/Plugins/WinAlfred.Plugin.Fanyi/Properties/AssemblyInfo.cs b/Plugins/WinAlfred.Plugin.Fanyi/Properties/AssemblyInfo.cs
new file mode 100644
index 000000000..7e841771e
--- /dev/null
+++ b/Plugins/WinAlfred.Plugin.Fanyi/Properties/AssemblyInfo.cs
@@ -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")]
diff --git a/Plugins/WinAlfred.Plugin.Fanyi/WinAlfred.Plugin.Fanyi.csproj b/Plugins/WinAlfred.Plugin.Fanyi/WinAlfred.Plugin.Fanyi.csproj
new file mode 100644
index 000000000..30bee4c18
--- /dev/null
+++ b/Plugins/WinAlfred.Plugin.Fanyi/WinAlfred.Plugin.Fanyi.csproj
@@ -0,0 +1,83 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {353769D3-D11C-4D86-BD06-AC8C1D68642B}
+ Library
+ Properties
+ WinAlfred.Plugin.Fanyi
+ WinAlfred.Plugin.Fanyi
+ v3.5
+ 512
+ ..\..\
+ true
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+ ..\..\packages\HtmlAgilityPack.1.4.6\lib\Net20\HtmlAgilityPack.dll
+
+
+ ..\..\packages\Newtonsoft.Json.5.0.8\lib\net35\Newtonsoft.Json.dll
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {8451ecdd-2ea4-4966-bb0a-7bbc40138e80}
+ WinAlfred.Plugin
+
+
+
+
+
+ Always
+
+
+
+
+
+
+
+
+ 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\
+
+
+
\ No newline at end of file
diff --git a/Plugins/WinAlfred.Plugin.Fanyi/packages.config b/Plugins/WinAlfred.Plugin.Fanyi/packages.config
new file mode 100644
index 000000000..9fdfb3d13
--- /dev/null
+++ b/Plugins/WinAlfred.Plugin.Fanyi/packages.config
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/Plugins/WinAlfred.Plugin.Fanyi/plugin.ini b/Plugins/WinAlfred.Plugin.Fanyi/plugin.ini
new file mode 100644
index 000000000..6d2c6eaa2
--- /dev/null
+++ b/Plugins/WinAlfred.Plugin.Fanyi/plugin.ini
@@ -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
diff --git a/WinAlfred.Plugin.System/Common/ChineseToPinYin.cs b/WinAlfred.Plugin.System/Common/ChineseToPinYin.cs
new file mode 100644
index 000000000..1f3d7f948
--- /dev/null
+++ b/WinAlfred.Plugin.System/Common/ChineseToPinYin.cs
@@ -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 CodeCollections = new Dictionary {
+ { -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" } };
+ ///
+ /// 汉字转拼音
+ ///
+ /// 需要转换的汉字
+ /// 返回汉字对应的拼音
+ 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();
+ }
+ }
+}
diff --git a/WinAlfred.Plugin.System/Programs.cs b/WinAlfred.Plugin.System/Programs.cs
index 72f9991cc..556932af0 100644
--- a/WinAlfred.Plugin.System/Programs.cs
+++ b/WinAlfred.Plugin.System/Programs.cs
@@ -6,6 +6,7 @@ using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
+using WinAlfred.Plugin.System.Common;
namespace WinAlfred.Plugin.System
{
@@ -14,21 +15,30 @@ namespace WinAlfred.Plugin.System
public string Title { get; set; }
public string IcoPath { get; set; }
public string ExecutePath { get; set; }
+ public int Score { get; set; }
}
public class Programs : ISystemPlugin
{
+ //TODO:add score for MRU program
+
+ private List indexDirectory = new List();
+ private List indexPostfix = new List { "lnk", "exe" };
+
List installedList = new List();
public List Query(Query query)
{
- if (string.IsNullOrEmpty(query.RawQuery) || query.RawQuery.Length <= 1) return new List();
+ if (string.IsNullOrEmpty(query.RawQuery) || query.RawQuery.EndsWith(" ") || query.RawQuery.Length <= 1) return new List();
- return installedList.Where(o => o.Title.ToLower().Contains(query.RawQuery.ToLower())).Select(c => new Result()
+ List returnList = installedList.Where(o => MatchProgram(o, query)).ToList();
+ returnList.ForEach(ScoreFilter);
+
+ return returnList.Select(c => new Result()
{
Title = c.Title,
IcoPath = c.IcoPath,
- Score = 10,
+ Score = c.Score,
Action = () =>
{
if (string.IsNullOrEmpty(c.ExecutePath))
@@ -43,18 +53,27 @@ namespace WinAlfred.Plugin.System
}).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)
{
+ indexDirectory.Add(Environment.GetFolderPath(Environment.SpecialFolder.Programs));
+ indexDirectory.Add(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\Microsoft\Windows\Start Menu\Programs");
+
GetAppFromStartMenu();
}
private void GetAppFromStartMenu()
{
- List path =
- Directory.GetDirectories(Environment.GetFolderPath(Environment.SpecialFolder.Programs)).ToList();
- foreach (string s in path)
+ foreach (string directory in indexDirectory)
{
- GetAppFromDirectory(s);
+ GetAppFromDirectory(directory);
}
}
@@ -62,12 +81,13 @@ namespace WinAlfred.Plugin.System
{
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()
{
Title = getAppNameFromAppPath(file),
IcoPath = file,
+ Score = 10,
ExecutePath = file
};
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)
{
string temp = app.Substring(app.LastIndexOf('\\') + 1);
diff --git a/WinAlfred.Plugin.System/Sys.cs b/WinAlfred.Plugin.System/Sys.cs
index f16709964..9919ca6c3 100644
--- a/WinAlfred.Plugin.System/Sys.cs
+++ b/WinAlfred.Plugin.System/Sys.cs
@@ -62,6 +62,14 @@ namespace WinAlfred.Plugin.System
IcoPath = "Images\\lock.png",
Action = () => LockWorkStation()
});
+ availableResults.Add(new Result
+ {
+ Title = "Exit",
+ SubTitle = "Close this app",
+ Score = 110,
+ IcoPath = "Images\\exit.png",
+ Action = () => context.CloseApp()
+ });
}
public string Name
diff --git a/WinAlfred.Plugin.System/WinAlfred.Plugin.System.csproj b/WinAlfred.Plugin.System/WinAlfred.Plugin.System.csproj
index 7da37c929..f7d8449ea 100644
--- a/WinAlfred.Plugin.System/WinAlfred.Plugin.System.csproj
+++ b/WinAlfred.Plugin.System/WinAlfred.Plugin.System.csproj
@@ -40,6 +40,7 @@
+
diff --git a/WinAlfred.Plugin/PluginInitContext.cs b/WinAlfred.Plugin/PluginInitContext.cs
index c010ae25f..70025c258 100644
--- a/WinAlfred.Plugin/PluginInitContext.cs
+++ b/WinAlfred.Plugin/PluginInitContext.cs
@@ -8,6 +8,11 @@ namespace WinAlfred.Plugin
public class PluginInitContext
{
public List Plugins { get; set; }
+
public Action ChangeQuery { get; set; }
+ public Action CloseApp { get; set; }
+ public Action HideApp { get; set; }
+ public Action ShowApp { get; set; }
+ public Action ShowMsg { get; set; }
}
}
diff --git a/WinAlfred.Plugin/Result.cs b/WinAlfred.Plugin/Result.cs
index 3d328df54..05565fea7 100644
--- a/WinAlfred.Plugin/Result.cs
+++ b/WinAlfred.Plugin/Result.cs
@@ -12,6 +12,8 @@ namespace WinAlfred.Plugin
public Action Action { get; set; }
public int Score { get; set; }
+ public bool DontHideWinAlfredAfterAction { get; set; }
+
//todo: this should be controlled by system, not visible to users
///
/// Only resulsts that originQuery match with curren query will be displayed in the panel
diff --git a/WinAlfred.sln b/WinAlfred.sln
index 22df5a02b..eca79e1fa 100644
--- a/WinAlfred.sln
+++ b/WinAlfred.sln
@@ -9,10 +9,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Plugin", "Plugin", "{3A73F5
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinAlfred", "WinAlfred\WinAlfred.csproj", "{DB90F671-D861-46BB-93A3-F1304F5BA1C5}"
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}"
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
GlobalSection(SolutionConfigurationPlatforms) = preSolution
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}.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|Mixed Platforms.ActiveCfg = Release|x86
- {8451ECDD-2EA4-4966-BB0A-7BBC40138E80}.Release|Mixed Platforms.Build.0 = 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|Any CPU
{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|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|x64.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.Build.0 = 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|x64.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
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
+ GlobalSection(NestedProjects) = preSolution
+ {353769D3-D11C-4D86-BD06-AC8C1D68642B} = {3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87}
+ EndGlobalSection
EndGlobal
diff --git a/WinAlfred/Commands/PluginCommand.cs b/WinAlfred/Commands/PluginCommand.cs
index cb0a764de..f30b667ac 100644
--- a/WinAlfred/Commands/PluginCommand.cs
+++ b/WinAlfred/Commands/PluginCommand.cs
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Threading;
using WinAlfred.Helper;
using WinAlfred.Plugin;
diff --git a/WinAlfred/Helper/KeyboardHook.cs b/WinAlfred/Helper/KeyboardHook.cs
index 97a775534..be717a541 100644
--- a/WinAlfred/Helper/KeyboardHook.cs
+++ b/WinAlfred/Helper/KeyboardHook.cs
@@ -85,6 +85,7 @@ namespace WinAlfred.Helper
if (!RegisterHotKey(window.Handle, currentId, (uint)xModifier, (uint)key))
{
Log.Error("Couldn’t register the hot key.");
+ MessageBox.Show("Couldn’t register the hot key.");
#if (DEBUG)
{
throw new InvalidOperationException("Couldn’t register the hot key.");
diff --git a/WinAlfred/MainWindow.xaml.cs b/WinAlfred/MainWindow.xaml.cs
index fd2099fb0..fa91201f4 100644
--- a/WinAlfred/MainWindow.xaml.cs
+++ b/WinAlfred/MainWindow.xaml.cs
@@ -6,6 +6,7 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Input;
+using Noesis.Javascript;
using WinAlfred.Commands;
using WinAlfred.Helper;
using WinAlfred.Plugin;
@@ -39,11 +40,7 @@ namespace WinAlfred
System.Windows.Forms.MenuItem open = new System.Windows.Forms.MenuItem("Open");
open.Click += (o, e) => ShowWinAlfred();
System.Windows.Forms.MenuItem exit = new System.Windows.Forms.MenuItem("Exit");
- exit.Click += (o, e) =>
- {
- notifyIcon.Visible = false;
- Close();
- };
+ exit.Click += (o, e) => CloseApp();
System.Windows.Forms.MenuItem[] childen = { open, exit };
notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu(childen);
}
@@ -68,6 +65,30 @@ namespace WinAlfred
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");
resultCtrl.Dirty = true;
////auto clear results after 50ms if there are any results returned by plugins
@@ -91,7 +112,7 @@ namespace WinAlfred
Hide();
}
- public void ShowWinAlfred()
+ private void ShowWinAlfred()
{
Show();
//FocusManager.SetFocusedElement(this, tbQuery);
@@ -104,6 +125,9 @@ namespace WinAlfred
Plugins.Init(this);
cmdDispatcher = new Command(this);
InitialTray();
+
+
+
}
private void TbQuery_OnPreviewKeyDown(object sender, KeyEventArgs e)
@@ -126,8 +150,7 @@ namespace WinAlfred
break;
case Key.Enter:
- resultCtrl.AcceptSelect();
- HideWinAlfred();
+ if (resultCtrl.AcceptSelect()) HideWinAlfred();
e.Handled = true;
break;
}
@@ -141,5 +164,39 @@ namespace WinAlfred
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
}
}
\ No newline at end of file
diff --git a/WinAlfred/Msg.xaml b/WinAlfred/Msg.xaml
new file mode 100644
index 000000000..ef17b3453
--- /dev/null
+++ b/WinAlfred/Msg.xaml
@@ -0,0 +1,38 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Title
+ sdfdsf
+
+
+
+
diff --git a/WinAlfred/Msg.xaml.cs b/WinAlfred/Msg.xaml.cs
new file mode 100644
index 000000000..353279de6
--- /dev/null
+++ b/WinAlfred/Msg.xaml.cs
@@ -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));
+ }
+ }
+}
diff --git a/WinAlfred/PluginLoader/Plugins.cs b/WinAlfred/PluginLoader/Plugins.cs
index 1b1b840bf..42f527bf0 100644
--- a/WinAlfred/PluginLoader/Plugins.cs
+++ b/WinAlfred/PluginLoader/Plugins.cs
@@ -22,11 +22,11 @@ namespace WinAlfred.PluginLoader
ThreadPool.QueueUserWorkItem(o => plugin1.Init(new PluginInitContext()
{
Plugins = plugins,
- ChangeQuery = s =>
- {
- window.tbQuery.Text = s;
- window.ShowWinAlfred();
- }
+ ChangeQuery = s => window.ChangeQuery(s),
+ CloseApp = window.CloseApp,
+ HideApp = window.HideApp,
+ ShowApp = window.ShowApp,
+ ShowMsg = (title,subTitle,iconPath) => window.ShowMsg(title,subTitle,iconPath)
}));
}
}
diff --git a/WinAlfred/ResultPanel.xaml.cs b/WinAlfred/ResultPanel.xaml.cs
index 420cb7774..6cf568da4 100644
--- a/WinAlfred/ResultPanel.xaml.cs
+++ b/WinAlfred/ResultPanel.xaml.cs
@@ -192,14 +192,21 @@ namespace WinAlfred
Select(0);
}
- public void AcceptSelect()
+ public bool AcceptSelect()
{
int index = GetCurrentSelectedResultIndex();
var resultItemControl = pnlContainer.Children[index] as ResultItem;
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()
diff --git a/WinAlfred/WinAlfred.csproj b/WinAlfred/WinAlfred.csproj
index 6fe06be12..0d76b8b28 100644
--- a/WinAlfred/WinAlfred.csproj
+++ b/WinAlfred/WinAlfred.csproj
@@ -39,22 +39,50 @@
app.ico
+
+ true
+ bin\x64\Debug\
+ DEBUG;TRACE
+ full
+ x64
+ prompt
+ MinimumRecommendedRules.ruleset
+
+
+ bin\x64\Release\
+ TRACE
+ true
+ pdbonly
+ x64
+ prompt
+ MinimumRecommendedRules.ruleset
+
+
..\packages\log4net.2.0.3\lib\net35-full\log4net.dll
..\packages\Newtonsoft.Json.5.0.8\lib\net35\Newtonsoft.Json.dll
+
+ C:\Users\Scott\Desktop\x64\Noesis.Javascript.dll
+
+
+
+
+
+
+
@@ -71,6 +99,9 @@
+
+ Msg.xaml
+
@@ -95,6 +126,10 @@
MainWindow.xaml
Code
+
+ Designer
+ MSBuild:Compile
+
Designer
MSBuild:Compile