Remove autohotkey and add toggle command args

This commit is contained in:
qianlifeng
2015-01-29 22:35:01 +08:00
parent 2b1e343186
commit a112c6d9ee
9 changed files with 29 additions and 92 deletions

Binary file not shown.

View File

@@ -1,18 +0,0 @@
using AutoHotkey.Interop;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Wox.Infrastructure.Hotkey
{
public class AHKHotkey : IHotkey
{
public bool RegisterHotkey(string hotkey, Action action)
{
AutoHotkeyEngine ahk = AHKHotkeyEngineFactory.CreateOrGet("default");
ahk.ExecRaw(string.Format("{0}::MsgBox, ssss!",hotkey));
return true;
}
}
}

View File

@@ -1,51 +0,0 @@
using AutoHotkey.Interop;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Wox.Infrastructure.Hotkey
{
internal class AHKHotkeyEngineFactory
{
private static List<KeyValuePair<string, AutoHotkeyEngine>> engines = new List<KeyValuePair<string, AutoHotkeyEngine>>();
public static AutoHotkeyEngine CreateOrGet(string name)
{
AutoHotkeyEngine engine = Get(name);
if (engine == null)
{
engine = Create(name);
}
return engine;
}
public static AutoHotkeyEngine Create(string name)
{
var ahk = new AutoHotkey.Interop.AutoHotkeyEngine();
engines.Add(new KeyValuePair<string, AutoHotkeyEngine>(name, ahk));
return ahk;
}
public static AutoHotkeyEngine Get(string name)
{
var engine = engines.FirstOrDefault(o => o.Key == name);
if (engine.Key != null)
{
return engine.Value;
}
return null;
}
public static void Destroy(string name)
{
var engine = engines.FirstOrDefault(o => o.Key == name);
if (engine.Key != null)
{
engine.Value.Terminate();
engines.Remove(engine);
}
}
}
}

View File

@@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Wox.Infrastructure.Hotkey
{
interface IHotkey
{
bool RegisterHotkey(string hotkey, Action action);
}
}

View File

@@ -37,9 +37,6 @@
<Prefer32Bit>false</Prefer32Bit> <Prefer32Bit>false</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="AutoHotkey.Interop">
<HintPath>..\References\AutoHotkey.Interop.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualBasic" /> <Reference Include="Microsoft.VisualBasic" />
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
@@ -61,9 +58,6 @@
<Reference Include="WindowsBase" /> <Reference Include="WindowsBase" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Hotkey\AHKHotkey.cs" />
<Compile Include="Hotkey\AHKHotkeyEngineFactory.cs" />
<Compile Include="Hotkey\IHotkey.cs" />
<Compile Include="Hotkey\InterceptKeys.cs" /> <Compile Include="Hotkey\InterceptKeys.cs" />
<Compile Include="Hotkey\KeyEvent.cs" /> <Compile Include="Hotkey\KeyEvent.cs" />
<Compile Include="Logger\Log.cs" /> <Compile Include="Logger\Log.cs" />

View File

@@ -14,6 +14,7 @@ namespace Wox.CommandArgs
public void Execute(IList<string> args) public void Execute(IList<string> args)
{ {
Console.WriteLine("test");
if (args.Count > 0) if (args.Count > 0)
{ {
string query = args[0]; string query = args[0];

View File

@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Wox.CommandArgs
{
public class ToggleCommandArg:ICommandArg
{
public string Command
{
get { return "toggle"; }
}
public void Execute(IList<string> args)
{
App.Window.ToggleWox();
}
}
}

View File

@@ -243,9 +243,6 @@ namespace Wox
public void SetHotkey(string hotkeyStr, EventHandler<HotkeyEventArgs> action) public void SetHotkey(string hotkeyStr, EventHandler<HotkeyEventArgs> action)
{ {
AHKHotkey ahk = new AHKHotkey();
ahk.RegisterHotkey("#R",null);
return;
var hotkey = new HotkeyModel(hotkeyStr); var hotkey = new HotkeyModel(hotkeyStr);
try try
{ {
@@ -281,17 +278,21 @@ namespace Wox
} }
private void OnHotkey(object sender, HotkeyEventArgs e) private void OnHotkey(object sender, HotkeyEventArgs e)
{
ToggleWox();
e.Handled = true;
}
public void ToggleWox()
{ {
if (!IsVisible) if (!IsVisible)
{ {
ShowWox(); ShowWox();
UserSettingStorage.Instance.IncreaseActivateTimes();
} }
else else
{ {
HideWox(); HideWox();
} }
e.Handled = true;
} }
private void InitProgressbarAnimation() private void InitProgressbarAnimation()
@@ -430,6 +431,7 @@ namespace Wox
private void ShowWox(bool selectAll = true) private void ShowWox(bool selectAll = true)
{ {
UserSettingStorage.Instance.IncreaseActivateTimes();
if (!double.IsNaN(Left) && !double.IsNaN(Top)) if (!double.IsNaN(Left) && !double.IsNaN(Top))
{ {
var origScreen = Screen.FromRectangle(new Rectangle((int)Left, (int)Top, (int)ActualWidth, (int)ActualHeight)); var origScreen = Screen.FromRectangle(new Rectangle((int)Left, (int)Top, (int)ActualWidth, (int)ActualHeight));

View File

@@ -105,6 +105,7 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="CommandArgs\ToggleCommandArg.cs" />
<Compile Include="Converters\ConvertorBase.cs" /> <Compile Include="Converters\ConvertorBase.cs" />
<Compile Include="Converters\ImagePathConverter.cs" /> <Compile Include="Converters\ImagePathConverter.cs" />
<Compile Include="Converters\OpacityModeConverter.cs" /> <Compile Include="Converters\OpacityModeConverter.cs" />