mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
Add hotkey setting
This commit is contained in:
@@ -62,6 +62,7 @@ namespace Wox.Infrastructure
|
|||||||
Instance.UserSetting.Theme = "Default";
|
Instance.UserSetting.Theme = "Default";
|
||||||
Instance.UserSetting.ReplaceWinR = true;
|
Instance.UserSetting.ReplaceWinR = true;
|
||||||
Instance.UserSetting.WebSearches = Instance.UserSetting.LoadDefaultWebSearches();
|
Instance.UserSetting.WebSearches = Instance.UserSetting.LoadDefaultWebSearches();
|
||||||
|
Instance.UserSetting.Hotkey = "Win + W";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CommonStorage Instance
|
public static CommonStorage Instance
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using System.Runtime.CompilerServices;
|
|||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
|
|
||||||
namespace Wox.Helper
|
namespace Wox.Infrastructure
|
||||||
{
|
{
|
||||||
public enum KeyEvent : int
|
public enum KeyEvent : int
|
||||||
{
|
{
|
||||||
@@ -29,8 +29,6 @@ namespace Wox.Helper
|
|||||||
WM_SYSKEYDOWN = 260
|
WM_SYSKEYDOWN = 260
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Listens keyboard globally.
|
/// Listens keyboard globally.
|
||||||
/// <remarks>Uses WH_KEYBOARD_LL.</remarks>
|
/// <remarks>Uses WH_KEYBOARD_LL.</remarks>
|
||||||
@@ -153,37 +151,6 @@ namespace Wox.Helper
|
|||||||
internal static extern uint SendInput(uint nInputs, [MarshalAs(UnmanagedType.LPArray), In] INPUT[] pInputs, int cbSize);
|
internal static extern uint SendInput(uint nInputs, [MarshalAs(UnmanagedType.LPArray), In] INPUT[] pInputs, int cbSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum InputType
|
|
||||||
{
|
|
||||||
INPUT_MOUSE = 0,
|
|
||||||
INPUT_KEYBOARD = 1,
|
|
||||||
INPUT_HARDWARE = 2,
|
|
||||||
}
|
|
||||||
[Flags()]
|
|
||||||
public enum MOUSEEVENTF
|
|
||||||
{
|
|
||||||
MOVE = 0x0001, //mouse move
|
|
||||||
LEFTDOWN = 0x0002, //left button down
|
|
||||||
LEFTUP = 0x0004, //left button up
|
|
||||||
RIGHTDOWN = 0x0008, //right button down
|
|
||||||
RIGHTUP = 0x0010, //right button up
|
|
||||||
MIDDLEDOWN = 0x0020, //middle button down
|
|
||||||
MIDDLEUP = 0x0040, //middle button up
|
|
||||||
XDOWN = 0x0080, //x button down
|
|
||||||
XUP = 0x0100, //x button down
|
|
||||||
WHEEL = 0x0800, //wheel button rolled
|
|
||||||
VIRTUALDESK = 0x4000, //map to entire virtual desktop
|
|
||||||
ABSOLUTE = 0x8000, //absolute move
|
|
||||||
}
|
|
||||||
|
|
||||||
[Flags()]
|
|
||||||
public enum KEYEVENTF
|
|
||||||
{
|
|
||||||
EXTENDEDKEY = 0x0001,
|
|
||||||
KEYUP = 0x0002,
|
|
||||||
UNICODE = 0x0004,
|
|
||||||
SCANCODE = 0x0008,
|
|
||||||
}
|
|
||||||
[StructLayout(LayoutKind.Explicit)]
|
[StructLayout(LayoutKind.Explicit)]
|
||||||
public struct INPUT
|
public struct INPUT
|
||||||
{
|
{
|
||||||
@@ -5,6 +5,7 @@ namespace Wox.Infrastructure.UserSettings
|
|||||||
{
|
{
|
||||||
public class UserSetting
|
public class UserSetting
|
||||||
{
|
{
|
||||||
|
public string Hotkey { get; set; }
|
||||||
public string Theme { get; set; }
|
public string Theme { get; set; }
|
||||||
public bool ReplaceWinR { get; set; }
|
public bool ReplaceWinR { get; set; }
|
||||||
public List<WebSearch> WebSearches { get; set; }
|
public List<WebSearch> WebSearches { get; set; }
|
||||||
|
|||||||
@@ -50,6 +50,8 @@
|
|||||||
<Compile Include="ChineseToPinYin.cs" />
|
<Compile Include="ChineseToPinYin.cs" />
|
||||||
<Compile Include="CommonStorage.cs" />
|
<Compile Include="CommonStorage.cs" />
|
||||||
<Compile Include="FuzzyMatcher.cs" />
|
<Compile Include="FuzzyMatcher.cs" />
|
||||||
|
<Compile Include="GloablHotkey.cs" />
|
||||||
|
<Compile Include="HotkeyModel.cs" />
|
||||||
<Compile Include="IniParser.cs" />
|
<Compile Include="IniParser.cs" />
|
||||||
<Compile Include="UAC.cs" />
|
<Compile Include="UAC.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
|||||||
@@ -4,10 +4,14 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Height="50"
|
Height="24"
|
||||||
Width="300"
|
|
||||||
d:DesignHeight="300" d:DesignWidth="300">
|
d:DesignHeight="300" d:DesignWidth="300">
|
||||||
<Grid >
|
<Grid >
|
||||||
<TextBox x:Name="tbHotkey" PreviewKeyDown="TbHotkey_OnPreviewKeyDown"></TextBox>
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="150"></ColumnDefinition>
|
||||||
|
<ColumnDefinition Width="120"></ColumnDefinition>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<TextBox x:Name="tbHotkey" VerticalContentAlignment="Center" Grid.Column="0" PreviewKeyDown="TbHotkey_OnPreviewKeyDown"></TextBox>
|
||||||
|
<TextBlock x:Name="tbMsg" Visibility="Hidden" Margin="5 0 0 0" VerticalAlignment="Center" Grid.Column="1" ></TextBlock>
|
||||||
</Grid>
|
</Grid>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -1,17 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Drawing;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Data;
|
|
||||||
using System.Windows.Documents;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using NHotkey;
|
||||||
using System.Windows.Navigation;
|
using NHotkey.Wpf;
|
||||||
using System.Windows.Shapes;
|
|
||||||
using Wox.Helper;
|
using Wox.Helper;
|
||||||
|
using Wox.Infrastructure;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
|
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
|
||||||
using UserControl = System.Windows.Controls.UserControl;
|
using UserControl = System.Windows.Controls.UserControl;
|
||||||
@@ -20,13 +15,34 @@ namespace Wox
|
|||||||
{
|
{
|
||||||
public partial class HotkeyControl : UserControl
|
public partial class HotkeyControl : UserControl
|
||||||
{
|
{
|
||||||
|
public HotkeyModel CurrentHotkey { get; private set; }
|
||||||
|
public bool CurrentHotkeyAvailable { get; private set; }
|
||||||
|
|
||||||
|
public event EventHandler OnHotkeyChanged;
|
||||||
|
|
||||||
|
protected virtual void OnOnHotkeyChanged()
|
||||||
|
{
|
||||||
|
EventHandler handler = OnHotkeyChanged;
|
||||||
|
if (handler != null) handler(this, EventArgs.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
public HotkeyControl()
|
public HotkeyControl()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetHotkey(HotkeyModel model)
|
||||||
|
{
|
||||||
|
if (model != null)
|
||||||
|
{
|
||||||
|
SetHotkey(model.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void TbHotkey_OnPreviewKeyDown(object sender, KeyEventArgs e)
|
private void TbHotkey_OnPreviewKeyDown(object sender, KeyEventArgs e)
|
||||||
{
|
{
|
||||||
|
tbMsg.Visibility = Visibility.Hidden;
|
||||||
|
|
||||||
//when alt is pressed, the real key should be e.SystemKey
|
//when alt is pressed, the real key should be e.SystemKey
|
||||||
Key key = (e.Key == Key.System ? e.SystemKey : e.Key);
|
Key key = (e.Key == Key.System ? e.SystemKey : e.Key);
|
||||||
|
|
||||||
@@ -34,35 +50,87 @@ namespace Wox
|
|||||||
SpecialKeyState specialKeyState = new GloablHotkey().CheckModifiers();
|
SpecialKeyState specialKeyState = new GloablHotkey().CheckModifiers();
|
||||||
if (specialKeyState.AltPressed)
|
if (specialKeyState.AltPressed)
|
||||||
{
|
{
|
||||||
text += "Alt ";
|
text += "Alt";
|
||||||
}
|
}
|
||||||
if (specialKeyState.CtrlPressed)
|
if (specialKeyState.CtrlPressed)
|
||||||
{
|
{
|
||||||
text += "Ctrl ";
|
text += string.IsNullOrEmpty(text) ? "Ctrl" : " + Ctrl";
|
||||||
}
|
}
|
||||||
if (specialKeyState.ShiftPressed)
|
if (specialKeyState.ShiftPressed)
|
||||||
{
|
{
|
||||||
text += "Shift ";
|
text += string.IsNullOrEmpty(text) ? "Shift" : " + Shift";
|
||||||
}
|
}
|
||||||
if (specialKeyState.WinPressed)
|
if (specialKeyState.WinPressed)
|
||||||
{
|
{
|
||||||
text += "Win ";
|
text += string.IsNullOrEmpty(text) ? "Win" : " + Win";
|
||||||
}
|
}
|
||||||
if(IsKeyAChar(key))
|
if (string.IsNullOrEmpty(text))
|
||||||
{
|
{
|
||||||
text += e.Key.ToString();
|
text += "Ctrl + Alt";
|
||||||
}
|
|
||||||
if (key == Key.Space)
|
|
||||||
{
|
|
||||||
text += "Space";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tbHotkey.Text = text;
|
if (IsKeyACharOrNumber(key))
|
||||||
|
{
|
||||||
|
text += " + " + key;
|
||||||
|
}
|
||||||
|
else if (key == Key.Space)
|
||||||
|
{
|
||||||
|
text += " + Space";
|
||||||
|
}
|
||||||
|
|
||||||
|
e.Handled = true;
|
||||||
|
|
||||||
|
Dispatcher.DelayInvoke("HotkeyAvailableTest", o => SetHotkey(text), TimeSpan.FromMilliseconds(300));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool IsKeyAChar(Key key)
|
public void SetHotkey(string keyStr)
|
||||||
{
|
{
|
||||||
return key >= Key.A && key <= Key.Z;
|
tbHotkey.Text = keyStr;
|
||||||
|
tbHotkey.Select(tbHotkey.Text.Length, 0);
|
||||||
|
|
||||||
|
CurrentHotkey = new HotkeyModel(keyStr);
|
||||||
|
CurrentHotkeyAvailable = CheckHotAvailabel(CurrentHotkey);
|
||||||
|
tbMsg.Visibility = Visibility.Visible;
|
||||||
|
if (!CurrentHotkeyAvailable)
|
||||||
|
{
|
||||||
|
tbMsg.Foreground = new SolidColorBrush(Colors.Red);
|
||||||
|
tbMsg.Text = "hotkey unavailable";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tbMsg.Foreground = new SolidColorBrush(Colors.Green);
|
||||||
|
tbMsg.Text = "hotkey available";
|
||||||
|
}
|
||||||
|
OnOnHotkeyChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool CheckHotAvailabel(HotkeyModel hotkey)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HotkeyManager.Current.AddOrReplace("HotkeyAvailableTest", hotkey.CharKey, hotkey.ModifierKeys, OnHotkey);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
HotkeyManager.Current.Remove("HotkeyAvailableTest");
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnHotkey(object sender, HotkeyEventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool IsKeyACharOrNumber(Key key)
|
||||||
|
{
|
||||||
|
return (key >= Key.A && key <= Key.Z) || (key >= Key.D0 && key <= Key.D9);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@@ -8,29 +9,33 @@ using System.Windows.Controls;
|
|||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Media.Animation;
|
using System.Windows.Media.Animation;
|
||||||
|
using WindowsInput;
|
||||||
|
using WindowsInput.Native;
|
||||||
using NHotkey;
|
using NHotkey;
|
||||||
using NHotkey.Wpf;
|
using NHotkey.Wpf;
|
||||||
using Wox.Commands;
|
using Wox.Commands;
|
||||||
using Wox.Helper;
|
|
||||||
using Wox.Infrastructure;
|
using Wox.Infrastructure;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
using Wox.PluginLoader;
|
using Wox.PluginLoader;
|
||||||
using Application = System.Windows.Application;
|
using Application = System.Windows.Application;
|
||||||
|
using ContextMenu = System.Windows.Forms.ContextMenu;
|
||||||
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
|
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
|
||||||
|
using MenuItem = System.Windows.Forms.MenuItem;
|
||||||
|
using MessageBox = System.Windows.MessageBox;
|
||||||
|
using Timer = System.Timers.Timer;
|
||||||
|
|
||||||
namespace Wox
|
namespace Wox
|
||||||
{
|
{
|
||||||
public partial class MainWindow
|
public partial class MainWindow
|
||||||
{
|
{
|
||||||
|
private static readonly object locker = new object();
|
||||||
|
private readonly GloablHotkey globalHotkey = new GloablHotkey();
|
||||||
|
|
||||||
|
private readonly KeyboardSimulator keyboardSimulator = new KeyboardSimulator(new InputSimulator());
|
||||||
|
private readonly Storyboard progressBarStoryboard = new Storyboard();
|
||||||
|
private bool WinRStroked;
|
||||||
private NotifyIcon notifyIcon;
|
private NotifyIcon notifyIcon;
|
||||||
Storyboard progressBarStoryboard = new Storyboard();
|
private bool queryHasReturn;
|
||||||
private bool queryHasReturn = false;
|
|
||||||
|
|
||||||
private GloablHotkey globalHotkey = new GloablHotkey();
|
|
||||||
private bool WinRStroked = false;
|
|
||||||
private static object locker = new object();
|
|
||||||
|
|
||||||
private WindowsInput.KeyboardSimulator keyboardSimulator = new WindowsInput.KeyboardSimulator(new WindowsInput.InputSimulator());
|
|
||||||
|
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
@@ -49,8 +54,22 @@ namespace Wox
|
|||||||
SetTheme(CommonStorage.Instance.UserSetting.Theme = "Default");
|
SetTheme(CommonStorage.Instance.UserSetting.Theme = "Default");
|
||||||
}
|
}
|
||||||
|
|
||||||
HotkeyManager.Current.AddOrReplace("ShowHideWox", Key.W, ModifierKeys.Windows, OnHotkey);
|
|
||||||
this.Closing += MainWindow_Closing;
|
Closing += MainWindow_Closing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetHotkey(string hotkeyStr)
|
||||||
|
{
|
||||||
|
HotkeyModel hotkey = new HotkeyModel(hotkeyStr);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HotkeyManager.Current.AddOrReplace("ShowHideWox", hotkey.CharKey, hotkey.ModifierKeys, OnHotkey);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Registe hotkey: " + CommonStorage.Instance.UserSetting.Hotkey + " failed.");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnHotkey(object sender, HotkeyEventArgs e)
|
private void OnHotkey(object sender, HotkeyEventArgs e)
|
||||||
@@ -66,7 +85,7 @@ namespace Wox
|
|||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
private void MainWindow_Closing(object sender, CancelEventArgs e)
|
||||||
{
|
{
|
||||||
e.Cancel = true;
|
e.Cancel = true;
|
||||||
}
|
}
|
||||||
@@ -77,25 +96,25 @@ namespace Wox
|
|||||||
//This is caused by the Virtual Mermory Page Mechanisam. So, our solution is execute some codes in every min
|
//This is caused by the Virtual Mermory Page Mechanisam. So, our solution is execute some codes in every min
|
||||||
//which may prevent sysetem uninstall memory from RAM to disk.
|
//which may prevent sysetem uninstall memory from RAM to disk.
|
||||||
|
|
||||||
System.Timers.Timer t = new System.Timers.Timer(1000 * 60 * 5) { AutoReset = true, Enabled = true };
|
var t = new Timer(1000*60*5) {AutoReset = true, Enabled = true};
|
||||||
t.Elapsed += (o, e) => Dispatcher.Invoke(new Action(() =>
|
t.Elapsed += (o, e) => Dispatcher.Invoke(new Action(() =>
|
||||||
|
{
|
||||||
|
if (Visibility != Visibility.Visible)
|
||||||
{
|
{
|
||||||
if (Visibility != Visibility.Visible)
|
double oldLeft = Left;
|
||||||
{
|
Left = 20000;
|
||||||
double oldLeft = Left;
|
ShowWox();
|
||||||
Left = 20000;
|
CommandFactory.DispatchCommand(new Query("qq"), false);
|
||||||
ShowWox();
|
HideWox();
|
||||||
CommandFactory.DispatchCommand(new Query("qq"), false);
|
Left = oldLeft;
|
||||||
HideWox();
|
}
|
||||||
Left = oldLeft;
|
}));
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitProgressbarAnimation()
|
private void InitProgressbarAnimation()
|
||||||
{
|
{
|
||||||
DoubleAnimation da = new DoubleAnimation(progressBar.X2, Width + 100, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
|
var da = new DoubleAnimation(progressBar.X2, Width + 100, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
|
||||||
DoubleAnimation da1 = new DoubleAnimation(progressBar.X1, Width, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
|
var da1 = new DoubleAnimation(progressBar.X1, Width, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
|
||||||
Storyboard.SetTargetProperty(da, new PropertyPath("(Line.X2)"));
|
Storyboard.SetTargetProperty(da, new PropertyPath("(Line.X2)"));
|
||||||
Storyboard.SetTargetProperty(da1, new PropertyPath("(Line.X1)"));
|
Storyboard.SetTargetProperty(da1, new PropertyPath("(Line.X1)"));
|
||||||
progressBarStoryboard.Children.Add(da);
|
progressBarStoryboard.Children.Add(da);
|
||||||
@@ -107,50 +126,51 @@ namespace Wox
|
|||||||
|
|
||||||
private void InitialTray()
|
private void InitialTray()
|
||||||
{
|
{
|
||||||
notifyIcon = new NotifyIcon { Text = "Wox", Icon = Properties.Resources.app, Visible = true };
|
notifyIcon = new NotifyIcon {Text = "Wox", Icon = Properties.Resources.app, Visible = true};
|
||||||
notifyIcon.Click += (o, e) => ShowWox();
|
notifyIcon.Click += (o, e) => ShowWox();
|
||||||
System.Windows.Forms.MenuItem open = new System.Windows.Forms.MenuItem("Open");
|
var open = new MenuItem("Open");
|
||||||
open.Click += (o, e) => ShowWox();
|
open.Click += (o, e) => ShowWox();
|
||||||
System.Windows.Forms.MenuItem exit = new System.Windows.Forms.MenuItem("Exit");
|
var exit = new MenuItem("Exit");
|
||||||
exit.Click += (o, e) => CloseApp();
|
exit.Click += (o, e) => CloseApp();
|
||||||
System.Windows.Forms.MenuItem[] childen = { open, exit };
|
MenuItem[] childen = {open, exit};
|
||||||
notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu(childen);
|
notifyIcon.ContextMenu = new ContextMenu(childen);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resultCtrl_resultItemChangedEvent()
|
private void resultCtrl_resultItemChangedEvent()
|
||||||
{
|
{
|
||||||
resultCtrl.Margin = resultCtrl.GetCurrentResultCount() > 0 ? new Thickness { Top = grid.Margin.Top } : new Thickness { Top = 0 };
|
resultCtrl.Margin = resultCtrl.GetCurrentResultCount() > 0
|
||||||
|
? new Thickness {Top = grid.Margin.Top}
|
||||||
|
: new Thickness {Top = 0};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e)
|
private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e)
|
||||||
{
|
{
|
||||||
resultCtrl.Dirty = true;
|
resultCtrl.Dirty = true;
|
||||||
Dispatcher.DelayInvoke("UpdateSearch",
|
Dispatcher.DelayInvoke("UpdateSearch",
|
||||||
o =>
|
o =>
|
||||||
{
|
{
|
||||||
Dispatcher.DelayInvoke("ClearResults", i =>
|
Dispatcher.DelayInvoke("ClearResults", i =>
|
||||||
{
|
{
|
||||||
// first try to use clear method inside resultCtrl, which is more closer to the add new results
|
// first try to use clear method inside resultCtrl, which is more closer to the add new results
|
||||||
// and this will not bring splash issues.After waiting 30ms, if there still no results added, we
|
// and this will not bring splash issues.After waiting 30ms, if there still no results added, we
|
||||||
// must clear the result. otherwise, it will be confused why the query changed, but the results
|
// must clear the result. otherwise, it will be confused why the query changed, but the results
|
||||||
// didn't.
|
// didn't.
|
||||||
if (resultCtrl.Dirty) resultCtrl.Clear();
|
if (resultCtrl.Dirty) resultCtrl.Clear();
|
||||||
}, TimeSpan.FromMilliseconds(30), null);
|
}, TimeSpan.FromMilliseconds(30), null);
|
||||||
var q = new Query(tbQuery.Text);
|
var q = new Query(tbQuery.Text);
|
||||||
CommandFactory.DispatchCommand(q);
|
CommandFactory.DispatchCommand(q);
|
||||||
queryHasReturn = false;
|
queryHasReturn = false;
|
||||||
if (Plugins.HitThirdpartyKeyword(q))
|
if (Plugins.HitThirdpartyKeyword(q))
|
||||||
{
|
{
|
||||||
Dispatcher.DelayInvoke("ShowProgressbar", originQuery =>
|
Dispatcher.DelayInvoke("ShowProgressbar", originQuery =>
|
||||||
{
|
{
|
||||||
if (!queryHasReturn && originQuery == tbQuery.Text)
|
if (!queryHasReturn && originQuery == tbQuery.Text)
|
||||||
{
|
{
|
||||||
StartProgress();
|
StartProgress();
|
||||||
}
|
}
|
||||||
}, TimeSpan.FromSeconds(1), tbQuery.Text);
|
}, TimeSpan.FromSeconds(1), tbQuery.Text);
|
||||||
}
|
}
|
||||||
|
}, TimeSpan.FromMilliseconds(150));
|
||||||
}, TimeSpan.FromMilliseconds(150));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StartProgress()
|
private void StartProgress()
|
||||||
@@ -205,9 +225,10 @@ namespace Wox
|
|||||||
|
|
||||||
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
|
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
Left = (SystemParameters.PrimaryScreenWidth - ActualWidth) / 2;
|
Left = (SystemParameters.PrimaryScreenWidth - ActualWidth)/2;
|
||||||
Top = (SystemParameters.PrimaryScreenHeight - ActualHeight) / 3;
|
Top = (SystemParameters.PrimaryScreenHeight - ActualHeight)/3;
|
||||||
|
|
||||||
|
SetHotkey(CommonStorage.Instance.UserSetting.Hotkey);
|
||||||
WakeupApp();
|
WakeupApp();
|
||||||
Plugins.Init();
|
Plugins.Init();
|
||||||
|
|
||||||
@@ -219,16 +240,16 @@ namespace Wox
|
|||||||
if (CommonStorage.Instance.UserSetting.ReplaceWinR)
|
if (CommonStorage.Instance.UserSetting.ReplaceWinR)
|
||||||
{
|
{
|
||||||
//todo:need refatoring. move those codes to CMD file or expose events
|
//todo:need refatoring. move those codes to CMD file or expose events
|
||||||
if (keyevent == KeyEvent.WM_KEYDOWN && vkcode == (int)Keys.R && state.WinPressed)
|
if (keyevent == KeyEvent.WM_KEYDOWN && vkcode == (int) Keys.R && state.WinPressed)
|
||||||
{
|
{
|
||||||
WinRStroked = true;
|
WinRStroked = true;
|
||||||
Dispatcher.BeginInvoke(new Action(OnWinRPressed));
|
Dispatcher.BeginInvoke(new Action(OnWinRPressed));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (keyevent == KeyEvent.WM_KEYUP && WinRStroked && vkcode == (int)Keys.LWin)
|
if (keyevent == KeyEvent.WM_KEYUP && WinRStroked && vkcode == (int) Keys.LWin)
|
||||||
{
|
{
|
||||||
WinRStroked = false;
|
WinRStroked = false;
|
||||||
keyboardSimulator.ModifiedKeyStroke(WindowsInput.Native.VirtualKeyCode.LWIN, WindowsInput.Native.VirtualKeyCode.CONTROL);
|
keyboardSimulator.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.CONTROL);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -294,15 +315,17 @@ namespace Wox
|
|||||||
if (list.Count > 0)
|
if (list.Count > 0)
|
||||||
{
|
{
|
||||||
//todo:this should be opened to users, it's their choise to use it or not in thier workflows
|
//todo:this should be opened to users, it's their choise to use it or not in thier workflows
|
||||||
list.ForEach(o =>
|
list.ForEach(
|
||||||
{
|
o =>
|
||||||
if (o.AutoAjustScore) o.Score += CommonStorage.Instance.UserSelectedRecords.GetSelectedCount(o);
|
{
|
||||||
});
|
if (o.AutoAjustScore) o.Score += CommonStorage.Instance.UserSelectedRecords.GetSelectedCount(o);
|
||||||
|
});
|
||||||
lock (locker)
|
lock (locker)
|
||||||
{
|
{
|
||||||
resultCtrl.Dispatcher.Invoke(new Action(() =>
|
resultCtrl.Dispatcher.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
List<Result> l = list.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == tbQuery.Text).ToList();
|
List<Result> l =
|
||||||
|
list.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == tbQuery.Text).ToList();
|
||||||
resultCtrl.AddResults(list);
|
resultCtrl.AddResults(list);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@@ -311,7 +334,7 @@ namespace Wox
|
|||||||
|
|
||||||
public void SetTheme(string themeName)
|
public void SetTheme(string themeName)
|
||||||
{
|
{
|
||||||
ResourceDictionary dict = new ResourceDictionary
|
var dict = new ResourceDictionary
|
||||||
{
|
{
|
||||||
Source = new Uri("pack://application:,,,/Themes/" + themeName + ".xaml")
|
Source = new Uri("pack://application:,,,/Themes/" + themeName + ".xaml")
|
||||||
};
|
};
|
||||||
@@ -348,13 +371,13 @@ namespace Wox
|
|||||||
|
|
||||||
public void ShowMsg(string title, string subTitle, string iconPath)
|
public void ShowMsg(string title, string subTitle, string iconPath)
|
||||||
{
|
{
|
||||||
Msg m = new Msg { Owner = GetWindow(this) };
|
var m = new Msg {Owner = GetWindow(this)};
|
||||||
m.Show(title, subTitle, iconPath);
|
m.Show(title, subTitle, iconPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OpenSettingDialog()
|
public void OpenSettingDialog()
|
||||||
{
|
{
|
||||||
SettingWidow s = new SettingWidow(this);
|
var s = new SettingWidow(this);
|
||||||
s.Show();
|
s.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Linq;
|
|||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using Wox.Helper;
|
using Wox.Helper;
|
||||||
|
using Wox.Infrastructure;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
|
|
||||||
namespace Wox
|
namespace Wox
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
<ComboBox x:Name="themeComboBox" SelectionChanged="ThemeComboBox_OnSelectionChanged" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120"/>
|
<ComboBox x:Name="themeComboBox" SelectionChanged="ThemeComboBox_OnSelectionChanged" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<StackPanel Orientation="Horizontal" Margin="10">
|
<StackPanel Orientation="Horizontal" Margin="10">
|
||||||
<wox:HotkeyControl />
|
<wox:HotkeyControl x:Name="ctlHotkey" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ namespace Wox
|
|||||||
this.mainWindow = mainWindow;
|
this.mainWindow = mainWindow;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
Loaded += Setting_Loaded;
|
Loaded += Setting_Loaded;
|
||||||
|
ctlHotkey.OnHotkeyChanged += ctlHotkey_OnHotkeyChanged;
|
||||||
|
ctlHotkey.SetHotkey(CommonStorage.Instance.UserSetting.Hotkey);
|
||||||
cbReplaceWinR.Checked += (o, e) =>
|
cbReplaceWinR.Checked += (o, e) =>
|
||||||
{
|
{
|
||||||
CommonStorage.Instance.UserSetting.ReplaceWinR = true;
|
CommonStorage.Instance.UserSetting.ReplaceWinR = true;
|
||||||
@@ -43,6 +45,16 @@ namespace Wox
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ctlHotkey_OnHotkeyChanged(object sender, System.EventArgs e)
|
||||||
|
{
|
||||||
|
if (ctlHotkey.CurrentHotkeyAvailable)
|
||||||
|
{
|
||||||
|
mainWindow.SetHotkey(ctlHotkey.CurrentHotkey.ToString());
|
||||||
|
CommonStorage.Instance.UserSetting.Hotkey = ctlHotkey.CurrentHotkey.ToString();
|
||||||
|
CommonStorage.Instance.Save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void Setting_Loaded(object sender, RoutedEventArgs e)
|
private void Setting_Loaded(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
foreach (string theme in LoadAvailableThemes())
|
foreach (string theme in LoadAvailableThemes())
|
||||||
|
|||||||
@@ -129,7 +129,6 @@
|
|||||||
<Compile Include="Helper\Log.cs" />
|
<Compile Include="Helper\Log.cs" />
|
||||||
<Compile Include="Helper\PluginInstaller.cs" />
|
<Compile Include="Helper\PluginInstaller.cs" />
|
||||||
<Compile Include="Helper\WoxException.cs" />
|
<Compile Include="Helper\WoxException.cs" />
|
||||||
<Compile Include="Helper\GloablHotkey.cs" />
|
|
||||||
<Compile Include="HotkeyControl.xaml.cs">
|
<Compile Include="HotkeyControl.xaml.cs">
|
||||||
<DependentUpon>HotkeyControl.xaml</DependentUpon>
|
<DependentUpon>HotkeyControl.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|||||||
Reference in New Issue
Block a user