diff --git a/.nuget/NuGet.Config b/.nuget/NuGet.Config new file mode 100644 index 0000000000..67f8ea046e --- /dev/null +++ b/.nuget/NuGet.Config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.nuget/NuGet.exe b/.nuget/NuGet.exe new file mode 100644 index 0000000000..c296edf177 Binary files /dev/null and b/.nuget/NuGet.exe differ diff --git a/.nuget/NuGet.targets b/.nuget/NuGet.targets new file mode 100644 index 0000000000..83fe906016 --- /dev/null +++ b/.nuget/NuGet.targets @@ -0,0 +1,136 @@ + + + + $(MSBuildProjectDirectory)\..\ + + + false + + + false + + + true + + + false + + + + + + + + + + + $([System.IO.Path]::Combine($(SolutionDir), ".nuget")) + $([System.IO.Path]::Combine($(ProjectDir), "packages.config")) + + + + + $(SolutionDir).nuget + packages.config + + + + + $(NuGetToolsPath)\NuGet.exe + @(PackageSource) + + "$(NuGetExePath)" + mono --runtime=v4.0.30319 $(NuGetExePath) + + $(TargetDir.Trim('\\')) + + -RequireConsent + -NonInteractive + + "$(SolutionDir) " + "$(SolutionDir)" + + + $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir) + $(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols + + + + RestorePackages; + $(BuildDependsOn); + + + + + $(BuildDependsOn); + BuildPackage; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Plugins/WinAlfred.Plugin.Everything/Everything.dll b/Plugins/WinAlfred.Plugin.Everything/Everything.dll new file mode 100644 index 0000000000..e5ea4f8b86 Binary files /dev/null and b/Plugins/WinAlfred.Plugin.Everything/Everything.dll differ diff --git a/Plugins/WinAlfred.Plugin.Everything/WinAlfred.Plugin.Everything.csproj b/Plugins/WinAlfred.Plugin.Everything/WinAlfred.Plugin.Everything.csproj index 1051a3c63e..39c75cedee 100644 --- a/Plugins/WinAlfred.Plugin.Everything/WinAlfred.Plugin.Everything.csproj +++ b/Plugins/WinAlfred.Plugin.Everything/WinAlfred.Plugin.Everything.csproj @@ -20,7 +20,7 @@ DEBUG;TRACE prompt 4 - AnyCPU + x64 pdbonly @@ -30,21 +30,21 @@ prompt 4 - + true - bin\x86\Debug\ + bin\Debug\ DEBUG;TRACE full - x86 + AnyCPU prompt MinimumRecommendedRules.ruleset - - bin\x86\Release\ + + bin\x64\Release\ TRACE true pdbonly - x86 + x64 prompt MinimumRecommendedRules.ruleset @@ -67,7 +67,17 @@ WinAlfred.Plugin + + + Always + + + + xcopy /Y $(TargetDir)$(TargetFileName) $(SolutionDir)WinAlfred\bin\Debug\Plugins\Everything\ +xcopy /Y $(TargetDir)plugin.ini $(SolutionDir)WinAlfred\bin\Debug\Plugins\Everything\ +xcopy /Y $(ProjectDir)Everything.dll $(SolutionDir)WinAlfred\bin\Debug\Plugins\Everything\ + + \ No newline at end of file diff --git a/Plugins/WinAlfred.Plugin.System/plugin.ini b/Plugins/WinAlfred.Plugin.System/plugin.ini new file mode 100644 index 0000000000..5b49554ca6 --- /dev/null +++ b/Plugins/WinAlfred.Plugin.System/plugin.ini @@ -0,0 +1,8 @@ +[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/Query.cs b/WinAlfred.Plugin/Query.cs index 24005b0727..2e2c45e4d6 100644 --- a/WinAlfred.Plugin/Query.cs +++ b/WinAlfred.Plugin/Query.cs @@ -20,10 +20,12 @@ namespace WinAlfred.Plugin if (string.IsNullOrEmpty(RawQuery)) return; string[] strings = RawQuery.Split(' '); + if (strings.Length == 1) return; //we consider a valid query must contain a space + ActionName = strings[0]; - if (strings.Length > 1) + for (int i = 1; i < strings.Length; i++) { - for (int i = 1; i < strings.Length; i++) + if (!string.IsNullOrEmpty(strings[i])) { ActionParameters.Add(strings[i]); } diff --git a/WinAlfred.Test/WinAlfred.Test.csproj b/WinAlfred.Test/WinAlfred.Test.csproj index d6fd6e7a9c..ab2e15c965 100644 --- a/WinAlfred.Test/WinAlfred.Test.csproj +++ b/WinAlfred.Test/WinAlfred.Test.csproj @@ -11,6 +11,8 @@ WinAlfred.Test v3.5 512 + ..\ + true true @@ -52,12 +54,9 @@ {8451ECDD-2EA4-4966-BB0A-7BBC40138E80} WinAlfred.Plugin - - {2770F339-701C-4698-8C9F-0FE007DFDFC5} - WinAlfred - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/WinAlfred/FrmMain.Designer.cs b/WinAlfred/FrmMain.Designer.cs index 97ec853937..e04cc25d11 100644 --- a/WinAlfred/FrmMain.Designer.cs +++ b/WinAlfred/FrmMain.Designer.cs @@ -29,7 +29,7 @@ private void InitializeComponent() { this.tbQuery = new System.Windows.Forms.TextBox(); - this.listBox1 = new System.Windows.Forms.ListBox(); + this.pnlResults = new System.Windows.Forms.Panel(); this.SuspendLayout(); // // tbQuery @@ -40,29 +40,33 @@ this.tbQuery.Size = new System.Drawing.Size(471, 21); this.tbQuery.TabIndex = 0; this.tbQuery.TextChanged += new System.EventHandler(this.TbQuery_TextChanged); + this.tbQuery.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tbQuery_KeyDown); // - // listBox1 + // pnlResults // - this.listBox1.FormattingEnabled = true; - this.listBox1.ItemHeight = 12; - this.listBox1.Location = new System.Drawing.Point(12, 39); - this.listBox1.Name = "listBox1"; - this.listBox1.Size = new System.Drawing.Size(471, 352); - this.listBox1.TabIndex = 1; + this.pnlResults.AutoSize = true; + this.pnlResults.Location = new System.Drawing.Point(12, 39); + this.pnlResults.Name = "pnlResults"; + this.pnlResults.Size = new System.Drawing.Size(471, 22); + this.pnlResults.TabIndex = 1; // // FrmMain // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(495, 404); - this.Controls.Add(this.listBox1); + this.AutoSize = true; + this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.ClientSize = new System.Drawing.Size(495, 72); + this.Controls.Add(this.pnlResults); this.Controls.Add(this.tbQuery); + this.DoubleBuffered = true; + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "FrmMain"; this.ShowIcon = false; - this.Text = "Form1"; - this.TopMost = true; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "WinAlfred"; this.Load += new System.EventHandler(this.FrmMain_Load); this.ResumeLayout(false); this.PerformLayout(); @@ -72,7 +76,7 @@ #endregion private System.Windows.Forms.TextBox tbQuery; - private System.Windows.Forms.ListBox listBox1; + private System.Windows.Forms.Panel pnlResults; } diff --git a/WinAlfred/FrmMain.cs b/WinAlfred/FrmMain.cs index c674a48adf..dd54a3cb78 100644 --- a/WinAlfred/FrmMain.cs +++ b/WinAlfred/FrmMain.cs @@ -9,6 +9,8 @@ using System.Windows.Forms; using WinAlfred.Helper; using WinAlfred.Plugin; using WinAlfred.PluginLoader; +using WinAlfreds.CustomControls; +using WinAlfreds.Helper; namespace WinAlfred { @@ -16,10 +18,23 @@ namespace WinAlfred { public List plugins = new List(); private List results = new List(); + KeyboardHook hook = new KeyboardHook(); public FrmMain() { InitializeComponent(); + + hook.KeyPressed += OnHotKey; + hook.RegisterHotKey(XModifierKeys.Alt, Keys.Space); + } + + private void OnHotKey(object sender, KeyPressedEventArgs e) + { + if (!Visible) + { + tbQuery.SelectAll(); + } + Visible = !Visible; } private void FrmMain_Load(object sender, EventArgs e) @@ -48,18 +63,27 @@ namespace WinAlfred throw; } #endif - throw; } } } var s = results.OrderByDescending(o => o.Score); - listBox1.Items.Clear(); + pnlResults.Controls.Clear(); foreach (Result result in results) { - listBox1.Items.Add(result.Title); + ResultItemControl control = new ResultItemControl(result); + pnlResults.Controls.Add(control); } } + private void tbQuery_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Escape) + { + e.Handled = true; + e.SuppressKeyPress = true; + Hide(); + } + } } -} +} \ No newline at end of file diff --git a/WinAlfred/Helper/KeyboardHook.cs b/WinAlfred/Helper/KeyboardHook.cs new file mode 100644 index 0000000000..459027e164 --- /dev/null +++ b/WinAlfred/Helper/KeyboardHook.cs @@ -0,0 +1,154 @@ +using System; +using System.Runtime.InteropServices; +using System.Windows.Forms; +using WinAlfred.Helper; + +namespace WinAlfreds.Helper +{ + public sealed class KeyboardHook : IDisposable + { + // Registers a hot key with Windows. + [DllImport("user32.dll")] + private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk); + // Unregisters the hot key with Windows. + [DllImport("user32.dll")] + private static extern bool UnregisterHotKey(IntPtr hWnd, int id); + /// + /// Represents the window that is used internally to get the messages. + /// + private class Window : NativeWindow, IDisposable + { + private static int wmHotkey = 0x0312; + + public Window() + { + // create the handle for the window. + CreateHandle(new CreateParams()); + } + + /// + /// Overridden to get the notifications. + /// + /// + protected override void WndProc(ref Message m) + { + base.WndProc(ref m); + + // check if we got a hot key pressed. + if (m.Msg == wmHotkey) + { + // get the keys. + Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF); + XModifierKeys xModifier = (XModifierKeys)((int)m.LParam & 0xFFFF); + + // invoke the event to notify the parent. + if (KeyPressed != null) + KeyPressed(this, new KeyPressedEventArgs(xModifier, key)); + } + } + + public event EventHandler KeyPressed; + + #region IDisposable Members + + public void Dispose() + { + DestroyHandle(); + } + + #endregion + } + + private Window window = new Window(); + private int currentId; + + public KeyboardHook() + { + // register the event of the inner native window. + window.KeyPressed += delegate(object sender, KeyPressedEventArgs args) + { + if (KeyPressed != null) + KeyPressed(this, args); + }; + } + + /// + /// Registers a hot key in the system. + /// + /// The modifiers that are associated with the hot key. + /// The key itself that is associated with the hot key. + public void RegisterHotKey(XModifierKeys xModifier, Keys key) + { + // increment the counter. + currentId = currentId + 1; + + // register the hot key. + if (!RegisterHotKey(window.Handle, currentId, (uint)xModifier, (uint)key)) + { + Log.Error("Couldn’t register the hot key."); +#if (DEBUG) + { + throw new InvalidOperationException("Couldn’t register the hot key."); + } +#endif + } + } + + /// + /// A hot key has been pressed. + /// + public event EventHandler KeyPressed; + + #region IDisposable Members + + public void Dispose() + { + // unregister all the registered hot keys. + for (int i = currentId; i > 0; i--) + { + UnregisterHotKey(window.Handle, i); + } + + // dispose the inner native window. + window.Dispose(); + } + + #endregion + } + + /// + /// Event Args for the event that is fired after the hot key has been pressed. + /// + public class KeyPressedEventArgs : EventArgs + { + private XModifierKeys xModifier; + private Keys key; + + internal KeyPressedEventArgs(XModifierKeys xModifier, Keys key) + { + this.xModifier = xModifier; + this.key = key; + } + + public XModifierKeys XModifier + { + get { return xModifier; } + } + + public Keys Key + { + get { return key; } + } + } + + /// + /// The enumeration of possible modifiers. + /// + public enum XModifierKeys : uint + { + Alt = 1, + Control = 2, + Shift = 4, + Win = 8 + } +} diff --git a/WinAlfred/PluginLoader/CSharpPluginLoader.cs b/WinAlfred/PluginLoader/CSharpPluginLoader.cs index f736a6f443..6d8521df5b 100644 --- a/WinAlfred/PluginLoader/CSharpPluginLoader.cs +++ b/WinAlfred/PluginLoader/CSharpPluginLoader.cs @@ -20,15 +20,19 @@ namespace WinAlfred.PluginLoader try { Assembly asm = Assembly.LoadFile(metadata.ExecuteFile); - List types = asm.GetTypes().Where(o => o.GetInterfaces().Contains(typeof(IPlugin))).ToList(); + List types = asm.GetTypes().Where(o => o.GetInterfaces().Contains(typeof (IPlugin))).ToList(); if (types.Count == 0) { - Log.Error(string.Format("Cound't load plugin {0}: didn't find the class who implement IPlugin", metadata.Name)); + Log.Error(string.Format("Cound't load plugin {0}: didn't find the class who implement IPlugin", + metadata.Name)); continue; } if (types.Count > 1) { - Log.Error(string.Format("Cound't load plugin {0}: find more than one class who implement IPlugin, there should only one class implement IPlugin", metadata.Name)); + Log.Error( + string.Format( + "Cound't load plugin {0}: find more than one class who implement IPlugin, there should only one class implement IPlugin", + metadata.Name)); continue; } @@ -43,9 +47,9 @@ namespace WinAlfred.PluginLoader { Log.Error(string.Format("Cound't load plugin {0}: {1}", metadata.Name, e.Message)); #if (DEBUG) -{ - throw; -} + { + throw; + } #endif } diff --git a/WinAlfred/Properties/AssemblyInfo.cs b/WinAlfred/Properties/AssemblyInfo.cs index d6daf1e7d5..21762cc7b1 100644 --- a/WinAlfred/Properties/AssemblyInfo.cs +++ b/WinAlfred/Properties/AssemblyInfo.cs @@ -5,11 +5,11 @@ using System.Runtime.InteropServices; // 有关程序集的常规信息通过以下 // 特性集控制。更改这些特性值可修改 // 与程序集关联的信息。 -[assembly: AssemblyTitle("WinAlfred")] +[assembly: AssemblyTitle("WinAlfreds")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("WinAlfred")] +[assembly: AssemblyProduct("WinAlfreds")] [assembly: AssemblyCopyright("Copyright © Microsoft 2013")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -20,7 +20,7 @@ using System.Runtime.InteropServices; [assembly: ComVisible(false)] // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID -[assembly: Guid("5a68016d-17c8-4efb-9ecc-3ea7611d2b8f")] +[assembly: Guid("58cdcef9-2715-45be-a57d-1c03c6cb4f90")] // 程序集的版本信息由下面四个值组成: // diff --git a/WinAlfred/Properties/Resources.Designer.cs b/WinAlfred/Properties/Resources.Designer.cs index d32addc9f5..ce3391e405 100644 --- a/WinAlfred/Properties/Resources.Designer.cs +++ b/WinAlfred/Properties/Resources.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace WinAlfred.Properties +namespace WinAlfreds.Properties { @@ -44,7 +44,7 @@ namespace WinAlfred.Properties { if ((resourceMan == null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WinAlfred.Properties.Resources", typeof(Resources).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WinAlfreds.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; diff --git a/WinAlfred/Properties/Settings.Designer.cs b/WinAlfred/Properties/Settings.Designer.cs index fbf9e505ae..e9207e2670 100644 --- a/WinAlfred/Properties/Settings.Designer.cs +++ b/WinAlfred/Properties/Settings.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace WinAlfred.Properties +namespace WinAlfreds.Properties { diff --git a/WinAlfred/WinAlfred.csproj b/WinAlfred/WinAlfred.csproj index b8f6e47564..150b5b536c 100644 --- a/WinAlfred/WinAlfred.csproj +++ b/WinAlfred/WinAlfred.csproj @@ -4,13 +4,15 @@ Debug AnyCPU - {2770F339-701C-4698-8C9F-0FE007DFDFC5} + {498C79C7-F29E-414B-A53D-0B09EEB67EF2} WinExe Properties - WinAlfred - WinAlfred + WinAlfreds + WinAlfreds v3.5 512 + ..\ + true AnyCPU @@ -31,21 +33,21 @@ prompt 4 - + true - bin\x86\Debug\ + bin\x64\Debug\ DEBUG;TRACE full - x86 + x64 prompt MinimumRecommendedRules.ruleset - - bin\x86\Release\ + + bin\x64\Release\ TRACE true pdbonly - x86 + x64 prompt MinimumRecommendedRules.ruleset @@ -88,20 +90,30 @@ + + UserControl + + + ResultItemControl.cs + Form FrmMain.cs - - - + + + + + + ResultItemControl.cs + FrmMain.cs @@ -128,11 +140,12 @@ - {8451ecdd-2ea4-4966-bb0a-7bbc40138e80} + {8451ECDD-2EA4-4966-BB0A-7BBC40138E80} WinAlfred.Plugin +