From dc51bc39abf06af3d1828d44eb9c1a9b7110f1b7 Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Fri, 3 Jan 2014 23:52:36 +0800 Subject: [PATCH] structure change --- .../Properties/AssemblyInfo.cs | 36 --------- .../WinAlfred.Plugin.System.csproj | 72 ------------------ Plugins/WinAlfred.Plugin.System/plugin.ini | 8 -- WinAlfred.Plugin.System/CMD.cs | 47 +++++++++++- WinAlfred.Plugin.System/ISystemPlugin.cs | 2 + .../Main.cs => WinAlfred.Plugin.System/Sys.cs | 35 ++++++--- .../WinAlfred.Plugin.System.csproj | 7 ++ WinAlfred.Plugin/IPlugin.cs | 2 +- WinAlfred.Plugin/PluginInitContext.cs | 13 ++++ WinAlfred.Plugin/Result.cs | 9 +++ WinAlfred.Plugin/WinAlfred.Plugin.csproj | 1 + WinAlfred.sln | 19 ----- WinAlfred/Commands/Command.cs | 27 +++++++ WinAlfred/Commands/CommandDispatcher.cs | 31 -------- WinAlfred/Commands/PluginCommand.cs | 50 +++++++----- WinAlfred/Commands/SystemCommand.cs | 29 ++++++- .../Images/lock.png | Bin WinAlfred/MainWindow.xaml.cs | 38 ++++++++- WinAlfred/PluginLoader/BasePluginLoader.cs | 31 +++----- WinAlfred/PluginLoader/CSharpPluginLoader.cs | 29 +++---- WinAlfred/PluginLoader/Plugins.cs | 16 +++- WinAlfred/PluginLoader/PythonPluginLoader.cs | 4 - WinAlfred/PluginLoader/PythonPluginWrapper.cs | 2 +- WinAlfred/ResultItem.xaml | 2 +- WinAlfred/ResultItem.xaml.cs | 3 +- WinAlfred/ResultPanel.xaml.cs | 25 +++++- WinAlfred/WinAlfred.csproj | 8 +- 27 files changed, 289 insertions(+), 257 deletions(-) delete mode 100644 Plugins/WinAlfred.Plugin.System/Properties/AssemblyInfo.cs delete mode 100644 Plugins/WinAlfred.Plugin.System/WinAlfred.Plugin.System.csproj delete mode 100644 Plugins/WinAlfred.Plugin.System/plugin.ini rename Plugins/WinAlfred.Plugin.System/Main.cs => WinAlfred.Plugin.System/Sys.cs (70%) create mode 100644 WinAlfred.Plugin/PluginInitContext.cs create mode 100644 WinAlfred/Commands/Command.cs delete mode 100644 WinAlfred/Commands/CommandDispatcher.cs rename {Plugins/WinAlfred.Plugin.System => WinAlfred}/Images/lock.png (100%) diff --git a/Plugins/WinAlfred.Plugin.System/Properties/AssemblyInfo.cs b/Plugins/WinAlfred.Plugin.System/Properties/AssemblyInfo.cs deleted file mode 100644 index 9f1336c2fa..0000000000 --- a/Plugins/WinAlfred.Plugin.System/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// 有关程序集的常规信息通过以下 -// 特性集控制。更改这些特性值可修改 -// 与程序集关联的信息。 -[assembly: AssemblyTitle("WinAlfred.Plugin.System")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("WinAlfred.Plugin.System")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2013")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// 将 ComVisible 设置为 false 使此程序集中的类型 -// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, -// 则将该类型上的 ComVisible 特性设置为 true。 -[assembly: ComVisible(false)] - -// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID -[assembly: Guid("5cdfe514-80c9-4d82-94e7-c6f79a26ccda")] - -// 程序集的版本信息由下面四个值组成: -// -// 主版本 -// 次版本 -// 生成号 -// 修订号 -// -// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, -// 方法是按如下所示使用“*”: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Plugins/WinAlfred.Plugin.System/WinAlfred.Plugin.System.csproj b/Plugins/WinAlfred.Plugin.System/WinAlfred.Plugin.System.csproj deleted file mode 100644 index a8dacb8d11..0000000000 --- a/Plugins/WinAlfred.Plugin.System/WinAlfred.Plugin.System.csproj +++ /dev/null @@ -1,72 +0,0 @@ - - - - - Debug - AnyCPU - {E515011D-A769-418B-8761-ABE6F29827A0} - Library - Properties - WinAlfred.Plugin.System - WinAlfred.Plugin.System - v3.5 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - - {8451ecdd-2ea4-4966-bb0a-7bbc40138e80} - WinAlfred.Plugin - - - - - Always - - - - - - - - xcopy /Y $(TargetDir)$(TargetFileName) $(SolutionDir)WinAlfred\bin\Debug\Plugins\System\ -xcopy /Y $(TargetDir)plugin.ini $(SolutionDir)WinAlfred\bin\Debug\Plugins\System\ -xcopy /Y $(ProjectDir)Images\*.* $(SolutionDir)WinAlfred\bin\Debug\Plugins\System\Images\ - - - \ No newline at end of file diff --git a/Plugins/WinAlfred.Plugin.System/plugin.ini b/Plugins/WinAlfred.Plugin.System/plugin.ini deleted file mode 100644 index 5b49554ca6..0000000000 --- a/Plugins/WinAlfred.Plugin.System/plugin.ini +++ /dev/null @@ -1,8 +0,0 @@ -[plugin] -ActionKeyword = sys -Name = System Commands -Author = qianlifeng -Version = 0.1 -Language = csharp -Description = test -ExecuteFile = WinAlfred.Plugin.System.dll diff --git a/WinAlfred.Plugin.System/CMD.cs b/WinAlfred.Plugin.System/CMD.cs index 1175f58d7b..ef7aedd011 100644 --- a/WinAlfred.Plugin.System/CMD.cs +++ b/WinAlfred.Plugin.System/CMD.cs @@ -1,20 +1,59 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; +using System.Windows.Forms; namespace WinAlfred.Plugin.System { - public class CMD:IPlugin + public class CMD : ISystemPlugin { public List Query(Query query) { - throw new NotImplementedException(); + List results = new List(); + if (query.RawQuery.StartsWith(">") && query.RawQuery.Length > 1) + { + string cmd = query.RawQuery.Substring(1); + Result result = new Result + { + Title = cmd, + SubTitle = "execute command through command shell" , + IcoPath = "Images/cmd.png", + Action = () => + { + Process process = new Process(); + ProcessStartInfo startInfo = new ProcessStartInfo(); + startInfo.WindowStyle = ProcessWindowStyle.Hidden; + startInfo.FileName = "cmd.exe"; + startInfo.Arguments = "/C " + cmd; + process.StartInfo = startInfo; + process.Start(); + } + }; + results.Add(result); + } + return results; } - public void Init() + public void Init(PluginInitContext context) { - throw new NotImplementedException(); + } + + public string Name + { + get + { + return "CMD"; + } + } + + public string Description + { + get + { + return "Execute shell commands."; + } } } } diff --git a/WinAlfred.Plugin.System/ISystemPlugin.cs b/WinAlfred.Plugin.System/ISystemPlugin.cs index 3eb6f9dbf6..dcb428d352 100644 --- a/WinAlfred.Plugin.System/ISystemPlugin.cs +++ b/WinAlfred.Plugin.System/ISystemPlugin.cs @@ -7,5 +7,7 @@ namespace WinAlfred.Plugin.System { public interface ISystemPlugin : IPlugin { + string Name { get; } + string Description { get; } } } diff --git a/Plugins/WinAlfred.Plugin.System/Main.cs b/WinAlfred.Plugin.System/Sys.cs similarity index 70% rename from Plugins/WinAlfred.Plugin.System/Main.cs rename to WinAlfred.Plugin.System/Sys.cs index 9cd5d7d9ea..5dceba034b 100644 --- a/Plugins/WinAlfred.Plugin.System/Main.cs +++ b/WinAlfred.Plugin.System/Sys.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text; @@ -8,7 +7,7 @@ using System.Windows.Forms; namespace WinAlfred.Plugin.System { - public class Main : IPlugin + public class Sys : ISystemPlugin { List availableResults = new List(); @@ -20,18 +19,18 @@ namespace WinAlfred.Plugin.System public List Query(Query query) { List results = new List(); - if (query.ActionParameters.Count == 0) + + foreach (Result availableResult in availableResults) { - results = availableResults; - } - else - { - results.AddRange(availableResults.Where(result => result.Title.ToLower().Contains(query.ActionParameters[0].ToLower()))); + if (availableResult.Title.ToLower().StartsWith(query.RawQuery.ToLower())) + { + results.Add(availableResult); + } } return results; } - public void Init() + public void Init(PluginInitContext context) { availableResults.Add(new Result { @@ -54,7 +53,23 @@ namespace WinAlfred.Plugin.System Score = 20, IcoPath = "Images\\lock.png", Action = () => LockWorkStation() - }); + }); + } + + public string Name + { + get + { + return "sys"; + } + } + + public string Description + { + get + { + return "provide system commands"; + } } } } diff --git a/WinAlfred.Plugin.System/WinAlfred.Plugin.System.csproj b/WinAlfred.Plugin.System/WinAlfred.Plugin.System.csproj index ae8c238f6c..b822bafe1d 100644 --- a/WinAlfred.Plugin.System/WinAlfred.Plugin.System.csproj +++ b/WinAlfred.Plugin.System/WinAlfred.Plugin.System.csproj @@ -32,6 +32,7 @@ + @@ -41,6 +42,8 @@ + + @@ -49,6 +52,10 @@ + + + +