Hotkey for mainwindow

This commit is contained in:
bao-qian
2016-05-23 00:46:59 +01:00
parent e7f5491239
commit 95cdc89795
2 changed files with 26 additions and 159 deletions

View File

@@ -9,7 +9,6 @@
Topmost="True"
Loaded="OnLoaded"
Closing="OnClosing"
PreviewKeyDown="OnPreviewKeyDown"
Drop="OnDrop"
Deactivated="OnDeactivated"
SizeToContent="Height"
@@ -25,6 +24,32 @@
Top="{Binding Top, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
d:DataContext="{d:DesignInstance vm:MainViewModel}">
<Window.InputBindings>
<KeyBinding Key="Escape" Command="{Binding EscCommand}"></KeyBinding>
<KeyBinding Key="F1" Command="{Binding StartHelpCommand}"></KeyBinding>
<KeyBinding Key="Tab" Command="{Binding SelectNextItemCommand}"></KeyBinding>
<KeyBinding Key="Tab" Modifiers="Shift" Command="{Binding SelectPrevItemCommand}"></KeyBinding>
<KeyBinding Key="Down" Command="{Binding SelectNextItemCommand}"></KeyBinding>
<KeyBinding Key="Up" Command="{Binding SelectPrevItemCommand}"></KeyBinding>
<KeyBinding Key="N" Modifiers="Ctrl" Command="{Binding SelectNextItemCommand}"></KeyBinding>
<KeyBinding Key="J" Modifiers="Ctrl" Command="{Binding SelectNextItemCommand}"></KeyBinding>
<KeyBinding Key="D" Modifiers="Ctrl" Command="{Binding SelectNextPageCommand}"></KeyBinding>
<KeyBinding Key="P" Modifiers="Ctrl" Command="{Binding SelectPrevItemCommand}"></KeyBinding>
<KeyBinding Key="K" Modifiers="Ctrl" Command="{Binding SelectPrevItemCommand}"></KeyBinding>
<KeyBinding Key="U" Modifiers="Ctrl" Command="{Binding SelectPrevPageCommand}"></KeyBinding>
<KeyBinding Key="O" Modifiers="Ctrl" Command="{Binding LoadContextMenuCommand}"></KeyBinding>
<KeyBinding Key="Enter" Modifiers="Shift" Command="{Binding LoadContextMenuCommand}"></KeyBinding>
<KeyBinding Key="Enter" Command="{Binding OpenResultCommand}"></KeyBinding>
<KeyBinding Key="D1" Modifiers="Alt" Command="{Binding OpenResultCommand}" CommandParameter="0"></KeyBinding>
<KeyBinding Key="D2" Modifiers="Alt" Command="{Binding OpenResultCommand}" CommandParameter="1"></KeyBinding>
<KeyBinding Key="D3" Modifiers="Alt" Command="{Binding OpenResultCommand}" CommandParameter="2"></KeyBinding>
<KeyBinding Key="D4" Modifiers="Alt" Command="{Binding OpenResultCommand}" CommandParameter="3"></KeyBinding>
<KeyBinding Key="D5" Modifiers="Alt" Command="{Binding OpenResultCommand}" CommandParameter="4"></KeyBinding>
<KeyBinding Key="D6" Modifiers="Alt" Command="{Binding OpenResultCommand}" CommandParameter="5"></KeyBinding>
<KeyBinding Key="D7" Modifiers="Alt" Command="{Binding OpenResultCommand}" CommandParameter="6"></KeyBinding>
<KeyBinding Key="D8" Modifiers="Alt" Command="{Binding OpenResultCommand}" CommandParameter="7"></KeyBinding>
<KeyBinding Key="D9" Modifiers="Alt" Command="{Binding OpenResultCommand}" CommandParameter="8"></KeyBinding>
</Window.InputBindings>
<Border Style="{DynamicResource WindowBorderStyle}" MouseDown="OnMouseDown">
<StackPanel Orientation="Vertical">
<TextBox Style="{DynamicResource QueryBoxStyle}"

View File

@@ -9,12 +9,10 @@ using Wox.Core.Plugin;
using Wox.Core.Resource;
using Wox.Core.UserSettings;
using Wox.Helper;
using Wox.Infrastructure.Hotkey;
using Wox.ViewModel;
using ContextMenu = System.Windows.Forms.ContextMenu;
using DataFormats = System.Windows.DataFormats;
using DragEventArgs = System.Windows.DragEventArgs;
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
using MenuItem = System.Windows.Forms.MenuItem;
using MessageBox = System.Windows.MessageBox;
@@ -162,162 +160,6 @@ namespace Wox
}
}
private void OnPreviewKeyDown(object sender, KeyEventArgs e)
{
var vm = DataContext as MainViewModel;
if (null == vm) return;
//when alt is pressed, the real key should be e.SystemKey
var key = (e.Key == Key.System ? e.SystemKey : e.Key);
switch (key)
{
case Key.Escape:
vm.EscCommand.Execute(null);
e.Handled = true;
break;
case Key.Tab:
if (GlobalHotkey.Instance.CheckModifiers().ShiftPressed)
{
vm.SelectPrevItemCommand.Execute(null);
}
else
{
vm.SelectNextItemCommand.Execute(null);
}
e.Handled = true;
break;
case Key.N:
case Key.J:
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
{
vm.SelectNextItemCommand.Execute(null);
}
break;
case Key.P:
case Key.K:
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
{
vm.SelectPrevItemCommand.Execute(null);
}
break;
case Key.O:
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
{
vm.LoadContextMenuCommand.Execute(null);
}
break;
case Key.Enter:
if (GlobalHotkey.Instance.CheckModifiers().ShiftPressed)
{
vm.LoadContextMenuCommand.Execute(null);
}
else
{
vm.OpenResultCommand.Execute(null);
}
e.Handled = true;
break;
case Key.Down:
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
{
vm.DisplayNextQueryCommand.Execute(null);
}
else
{
vm.SelectNextItemCommand.Execute(null);
}
e.Handled = true;
break;
case Key.Up:
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
{
vm.DisplayPrevQueryCommand.Execute(null);
}
else
{
vm.SelectPrevItemCommand.Execute(null);
}
e.Handled = true;
break;
case Key.D:
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
{
vm.SelectNextPageCommand.Execute(null);
}
break;
case Key.PageDown:
vm.SelectNextPageCommand.Execute(null);
e.Handled = true;
break;
case Key.U:
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
{
vm.SelectPrevPageCommand.Execute(null);
}
break;
case Key.PageUp:
vm.SelectPrevPageCommand.Execute(null);
e.Handled = true;
break;
case Key.F1:
vm.StartHelpCommand.Execute(null);
break;
case Key.D1:
if (GlobalHotkey.Instance.CheckModifiers().AltPressed)
{
vm.OpenResultCommand.Execute(0);
}
break;
case Key.D2:
if (GlobalHotkey.Instance.CheckModifiers().AltPressed)
{
vm.OpenResultCommand.Execute(1);
}
break;
case Key.D3:
if (GlobalHotkey.Instance.CheckModifiers().AltPressed)
{
vm.OpenResultCommand.Execute(2);
}
break;
case Key.D4:
if (GlobalHotkey.Instance.CheckModifiers().AltPressed)
{
vm.OpenResultCommand.Execute(3);
}
break;
case Key.D5:
if (GlobalHotkey.Instance.CheckModifiers().AltPressed)
{
vm.OpenResultCommand.Execute(4);
}
break;
case Key.D6:
if (GlobalHotkey.Instance.CheckModifiers().AltPressed)
{
vm.OpenResultCommand.Execute(5);
}
break;
}
}
private void OnPreviewMouseButtonDown(object sender, MouseButtonEventArgs e)
{
if (sender != null && e.OriginalSource != null)