Add custom plugin hotkey feature.

This commit is contained in:
qianlifeng
2014-02-22 15:52:20 +08:00
parent 2f5a4f63b6
commit b3e5f09c83
13 changed files with 483 additions and 66 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
@@ -31,16 +32,9 @@ namespace Wox
InitializeComponent();
}
public void SetHotkey(HotkeyModel model)
{
if (model != null)
{
SetHotkey(model.ToString());
}
}
private void TbHotkey_OnPreviewKeyDown(object sender, KeyEventArgs e)
{
e.Handled = true;
tbMsg.Visibility = Visibility.Hidden;
//when alt is pressed, the real key should be e.SystemKey
@@ -77,31 +71,41 @@ namespace Wox
{
text += " + Space";
}
e.Handled = true;
else
{
return;
}
if (text == tbHotkey.Text)
{
return;
}
Dispatcher.DelayInvoke("HotkeyAvailableTest", o => SetHotkey(text), TimeSpan.FromMilliseconds(300));
}
public void SetHotkey(string keyStr)
public void SetHotkey(string keyStr, bool triggerValidate = true)
{
tbMsg.Visibility = Visibility.Visible;
tbHotkey.Text = keyStr;
tbHotkey.Select(tbHotkey.Text.Length, 0);
CurrentHotkey = new HotkeyModel(keyStr);
CurrentHotkeyAvailable = CheckHotAvailabel(CurrentHotkey);
tbMsg.Visibility = Visibility.Visible;
if (!CurrentHotkeyAvailable)
if (triggerValidate)
{
tbMsg.Foreground = new SolidColorBrush(Colors.Red);
tbMsg.Text = "hotkey unavailable";
CurrentHotkeyAvailable = CheckHotAvailabel(CurrentHotkey);
if (!CurrentHotkeyAvailable)
{
tbMsg.Foreground = new SolidColorBrush(Colors.Red);
tbMsg.Text = "hotkey unavailable";
}
else
{
tbMsg.Foreground = new SolidColorBrush(Colors.Green);
tbMsg.Text = "succeed";
}
OnOnHotkeyChanged();
}
else
{
tbMsg.Foreground = new SolidColorBrush(Colors.Green);
tbMsg.Text = "hotkey available";
}
OnOnHotkeyChanged();
}
private bool CheckHotAvailabel(HotkeyModel hotkey)