mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 20:57:22 +02:00
Combined 2 cases
Stupid automatic formatting changed more then I wanted Here is the change I made if you just want the code case Key.Tab: case Key.Enter: AcceptSelect(resultCtrl.GetActiveResult()); e.Handled = true; break;
This commit is contained in:
@@ -35,10 +35,8 @@ using Rectangle = System.Drawing.Rectangle;
|
|||||||
using TextBox = System.Windows.Controls.TextBox;
|
using TextBox = System.Windows.Controls.TextBox;
|
||||||
using ToolTip = System.Windows.Controls.ToolTip;
|
using ToolTip = System.Windows.Controls.ToolTip;
|
||||||
|
|
||||||
namespace Wox
|
namespace Wox {
|
||||||
{
|
public partial class MainWindow : IPublicAPI {
|
||||||
public partial class MainWindow : IPublicAPI
|
|
||||||
{
|
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
|
|
||||||
@@ -60,84 +58,67 @@ namespace Wox
|
|||||||
|
|
||||||
#region Public API
|
#region Public API
|
||||||
|
|
||||||
public void ChangeQuery(string query, bool requery = false)
|
public void ChangeQuery(string query, bool requery = false) {
|
||||||
{
|
Dispatcher.Invoke(new Action(() => {
|
||||||
Dispatcher.Invoke(new Action(() =>
|
|
||||||
{
|
|
||||||
tbQuery.Text = query;
|
tbQuery.Text = query;
|
||||||
tbQuery.CaretIndex = tbQuery.Text.Length;
|
tbQuery.CaretIndex = tbQuery.Text.Length;
|
||||||
if (requery)
|
if (requery) {
|
||||||
{
|
|
||||||
TextBoxBase_OnTextChanged(null, null);
|
TextBoxBase_OnTextChanged(null, null);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CloseApp()
|
public void CloseApp() {
|
||||||
{
|
Dispatcher.Invoke(new Action(() => {
|
||||||
Dispatcher.Invoke(new Action(() =>
|
|
||||||
{
|
|
||||||
notifyIcon.Visible = false;
|
notifyIcon.Visible = false;
|
||||||
Close();
|
Close();
|
||||||
Environment.Exit(0);
|
Environment.Exit(0);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HideApp()
|
public void HideApp() {
|
||||||
{
|
|
||||||
Dispatcher.Invoke(new Action(HideWox));
|
Dispatcher.Invoke(new Action(HideWox));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShowApp()
|
public void ShowApp() {
|
||||||
{
|
|
||||||
Dispatcher.Invoke(new Action(() => ShowWox()));
|
Dispatcher.Invoke(new Action(() => ShowWox()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShowMsg(string title, string subTitle, string iconPath)
|
public void ShowMsg(string title, string subTitle, string iconPath) {
|
||||||
{
|
Dispatcher.Invoke(new Action(() => {
|
||||||
Dispatcher.Invoke(new Action(() =>
|
|
||||||
{
|
|
||||||
var 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() {
|
||||||
{
|
|
||||||
Dispatcher.Invoke(new Action(() => WindowOpener.Open<SettingWindow>(this)));
|
Dispatcher.Invoke(new Action(() => WindowOpener.Open<SettingWindow>(this)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StartLoadingBar()
|
public void StartLoadingBar() {
|
||||||
{
|
|
||||||
Dispatcher.Invoke(new Action(StartProgress));
|
Dispatcher.Invoke(new Action(StartProgress));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StopLoadingBar()
|
public void StopLoadingBar() {
|
||||||
{
|
|
||||||
Dispatcher.Invoke(new Action(StopProgress));
|
Dispatcher.Invoke(new Action(StopProgress));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InstallPlugin(string path)
|
public void InstallPlugin(string path) {
|
||||||
{
|
|
||||||
Dispatcher.Invoke(new Action(() => PluginInstaller.Install(path)));
|
Dispatcher.Invoke(new Action(() => PluginInstaller.Install(path)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReloadPlugins()
|
public void ReloadPlugins() {
|
||||||
{
|
|
||||||
Dispatcher.Invoke(new Action(Plugins.Init));
|
Dispatcher.Invoke(new Action(Plugins.Init));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PluginPair> GetAllPlugins()
|
public List<PluginPair> GetAllPlugins() {
|
||||||
{
|
|
||||||
return Plugins.AllPlugins;
|
return Plugins.AllPlugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
public event WoxKeyDownEventHandler BackKeyDownEvent;
|
public event WoxKeyDownEventHandler BackKeyDownEvent;
|
||||||
|
|
||||||
public void PushResults(Query query, PluginMetadata plugin, List<Result> results)
|
public void PushResults(Query query, PluginMetadata plugin, List<Result> results) {
|
||||||
{
|
results.ForEach(o => {
|
||||||
results.ForEach(o =>
|
|
||||||
{
|
|
||||||
o.PluginDirectory = plugin.PluginDirectory;
|
o.PluginDirectory = plugin.PluginDirectory;
|
||||||
o.OriginQuery = query;
|
o.OriginQuery = query;
|
||||||
});
|
});
|
||||||
@@ -147,8 +128,7 @@ namespace Wox
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
public MainWindow()
|
public MainWindow() {
|
||||||
{
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
if (UserSettingStorage.Instance.OpacityMode == OpacityMode.LayeredWindow)
|
if (UserSettingStorage.Instance.OpacityMode == OpacityMode.LayeredWindow)
|
||||||
@@ -161,12 +141,10 @@ namespace Wox
|
|||||||
resultCtrl.OnMouseClickItem += AcceptSelect;
|
resultCtrl.OnMouseClickItem += AcceptSelect;
|
||||||
|
|
||||||
ThreadPool.SetMaxThreads(30, 10);
|
ThreadPool.SetMaxThreads(30, 10);
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
SetTheme(UserSettingStorage.Instance.Theme);
|
SetTheme(UserSettingStorage.Instance.Theme);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception) {
|
||||||
{
|
|
||||||
SetTheme(UserSettingStorage.Instance.Theme = "Dark");
|
SetTheme(UserSettingStorage.Instance.Theme = "Dark");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,8 +156,7 @@ namespace Wox
|
|||||||
this.Closing += MainWindow_Closing;
|
this.Closing += MainWindow_Closing;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
|
||||||
{
|
|
||||||
UserSettingStorage.Instance.WindowLeft = Left;
|
UserSettingStorage.Instance.WindowLeft = Left;
|
||||||
UserSettingStorage.Instance.WindowTop = Top;
|
UserSettingStorage.Instance.WindowTop = Top;
|
||||||
UserSettingStorage.Instance.Save();
|
UserSettingStorage.Instance.Save();
|
||||||
@@ -187,18 +164,15 @@ namespace Wox
|
|||||||
e.Cancel = true;
|
e.Cancel = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
|
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e) {
|
||||||
{
|
|
||||||
if (UserSettingStorage.Instance.WindowLeft == 0
|
if (UserSettingStorage.Instance.WindowLeft == 0
|
||||||
&& UserSettingStorage.Instance.WindowTop == 0)
|
&& UserSettingStorage.Instance.WindowTop == 0) {
|
||||||
{
|
|
||||||
Left = UserSettingStorage.Instance.WindowLeft
|
Left = UserSettingStorage.Instance.WindowLeft
|
||||||
= (SystemParameters.PrimaryScreenWidth - ActualWidth) / 2;
|
= (SystemParameters.PrimaryScreenWidth - ActualWidth) / 2;
|
||||||
Top = UserSettingStorage.Instance.WindowTop
|
Top = UserSettingStorage.Instance.WindowTop
|
||||||
= (SystemParameters.PrimaryScreenHeight - ActualHeight) / 5;
|
= (SystemParameters.PrimaryScreenHeight - ActualHeight) / 5;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
Left = UserSettingStorage.Instance.WindowLeft;
|
Left = UserSettingStorage.Instance.WindowLeft;
|
||||||
Top = UserSettingStorage.Instance.WindowTop;
|
Top = UserSettingStorage.Instance.WindowTop;
|
||||||
}
|
}
|
||||||
@@ -217,56 +191,44 @@ namespace Wox
|
|||||||
WindowIntelopHelper.DisableControlBox(this);
|
WindowIntelopHelper.DisableControlBox(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetHotkey(string hotkeyStr, EventHandler<HotkeyEventArgs> action)
|
public void SetHotkey(string hotkeyStr, EventHandler<HotkeyEventArgs> action) {
|
||||||
{
|
|
||||||
var hotkey = new HotkeyModel(hotkeyStr);
|
var hotkey = new HotkeyModel(hotkeyStr);
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
HotkeyManager.Current.AddOrReplace(hotkeyStr, hotkey.CharKey, hotkey.ModifierKeys, action);
|
HotkeyManager.Current.AddOrReplace(hotkeyStr, hotkey.CharKey, hotkey.ModifierKeys, action);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception) {
|
||||||
{
|
|
||||||
MessageBox.Show("Register hotkey: " + hotkeyStr + " failed.");
|
MessageBox.Show("Register hotkey: " + hotkeyStr + " failed.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveHotkey(string hotkeyStr)
|
public void RemoveHotkey(string hotkeyStr) {
|
||||||
{
|
if (!string.IsNullOrEmpty(hotkeyStr)) {
|
||||||
if (!string.IsNullOrEmpty(hotkeyStr))
|
|
||||||
{
|
|
||||||
HotkeyManager.Current.Remove(hotkeyStr);
|
HotkeyManager.Current.Remove(hotkeyStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetCustomPluginHotkey()
|
private void SetCustomPluginHotkey() {
|
||||||
{
|
|
||||||
if (UserSettingStorage.Instance.CustomPluginHotkeys == null) return;
|
if (UserSettingStorage.Instance.CustomPluginHotkeys == null) return;
|
||||||
foreach (CustomPluginHotkey hotkey in UserSettingStorage.Instance.CustomPluginHotkeys)
|
foreach (CustomPluginHotkey hotkey in UserSettingStorage.Instance.CustomPluginHotkeys) {
|
||||||
{
|
|
||||||
CustomPluginHotkey hotkey1 = hotkey;
|
CustomPluginHotkey hotkey1 = hotkey;
|
||||||
SetHotkey(hotkey.Hotkey, delegate
|
SetHotkey(hotkey.Hotkey, delegate {
|
||||||
{
|
|
||||||
ShowApp();
|
ShowApp();
|
||||||
ChangeQuery(hotkey1.ActionKeyword, true);
|
ChangeQuery(hotkey1.ActionKeyword, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnHotkey(object sender, HotkeyEventArgs e)
|
private void OnHotkey(object sender, HotkeyEventArgs e) {
|
||||||
{
|
if (!IsVisible) {
|
||||||
if (!IsVisible)
|
|
||||||
{
|
|
||||||
ShowWox();
|
ShowWox();
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
HideWox();
|
HideWox();
|
||||||
}
|
}
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitProgressbarAnimation()
|
private void InitProgressbarAnimation() {
|
||||||
{
|
|
||||||
var da = new DoubleAnimation(progressBar.X2, ActualWidth + 100, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
|
var da = new DoubleAnimation(progressBar.X2, ActualWidth + 100, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
|
||||||
var da1 = new DoubleAnimation(progressBar.X1, ActualWidth, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
|
var da1 = new DoubleAnimation(progressBar.X1, ActualWidth, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
|
||||||
Storyboard.SetTargetProperty(da, new PropertyPath("(Line.X2)"));
|
Storyboard.SetTargetProperty(da, new PropertyPath("(Line.X2)"));
|
||||||
@@ -278,8 +240,7 @@ namespace Wox
|
|||||||
progressBar.BeginStoryboard(progressBarStoryboard);
|
progressBar.BeginStoryboard(progressBarStoryboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
var open = new MenuItem("Open");
|
var open = new MenuItem("Open");
|
||||||
@@ -292,18 +253,15 @@ namespace Wox
|
|||||||
notifyIcon.ContextMenu = new ContextMenu(childen);
|
notifyIcon.ContextMenu = new ContextMenu(childen);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e)
|
private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e) {
|
||||||
{
|
|
||||||
if (ignoreTextChange) { ignoreTextChange = false; return; }
|
if (ignoreTextChange) { ignoreTextChange = false; return; }
|
||||||
|
|
||||||
lastQuery = tbQuery.Text;
|
lastQuery = tbQuery.Text;
|
||||||
toolTip.IsOpen = false;
|
toolTip.IsOpen = false;
|
||||||
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
|
||||||
@@ -313,72 +271,55 @@ namespace Wox
|
|||||||
queryHasReturn = false;
|
queryHasReturn = false;
|
||||||
var q = new Query(lastQuery);
|
var q = new Query(lastQuery);
|
||||||
CommandFactory.DispatchCommand(q);
|
CommandFactory.DispatchCommand(q);
|
||||||
if (Plugins.HitThirdpartyKeyword(q))
|
if (Plugins.HitThirdpartyKeyword(q)) {
|
||||||
{
|
Dispatcher.DelayInvoke("ShowProgressbar", originQuery => {
|
||||||
Dispatcher.DelayInvoke("ShowProgressbar", originQuery =>
|
if (!queryHasReturn && originQuery == lastQuery) {
|
||||||
{
|
|
||||||
if (!queryHasReturn && originQuery == lastQuery)
|
|
||||||
{
|
|
||||||
StartProgress();
|
StartProgress();
|
||||||
}
|
}
|
||||||
}, TimeSpan.FromSeconds(0), lastQuery);
|
}, TimeSpan.FromSeconds(0), lastQuery);
|
||||||
}
|
}
|
||||||
}, TimeSpan.FromMilliseconds(ShouldNotDelayQuery ? 0 : 150));
|
}, TimeSpan.FromMilliseconds(ShouldNotDelayQuery ? 0 : 150));
|
||||||
}
|
}
|
||||||
private bool ShouldNotDelayQuery
|
private bool ShouldNotDelayQuery {
|
||||||
{
|
get {
|
||||||
get
|
return (bool)Dispatcher.Invoke(new Func<bool>(() => {
|
||||||
{
|
|
||||||
return (bool)Dispatcher.Invoke(new Func<bool>(() =>
|
|
||||||
{
|
|
||||||
return IsCMDMode || IsWebSearchMode;
|
return IsCMDMode || IsWebSearchMode;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsCMDMode
|
private bool IsCMDMode {
|
||||||
{
|
get {
|
||||||
get
|
|
||||||
{
|
|
||||||
return tbQuery.Text.StartsWith(">");
|
return tbQuery.Text.StartsWith(">");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsWebSearchMode
|
private bool IsWebSearchMode {
|
||||||
{
|
get {
|
||||||
get
|
|
||||||
{
|
|
||||||
Query q = new Query(tbQuery.Text);
|
Query q = new Query(tbQuery.Text);
|
||||||
return !UserSettingStorage.Instance.EnableWebSearchSuggestion &&
|
return !UserSettingStorage.Instance.EnableWebSearchSuggestion &&UserSettingStorage.Instance.WebSearches.Exists(o => o.ActionWord == q.ActionName && o.Enabled);
|
||||||
UserSettingStorage.Instance.WebSearches.Exists(o => o.ActionWord == q.ActionName && o.Enabled);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void Border_OnMouseDown(object sender, MouseButtonEventArgs e)
|
private void Border_OnMouseDown(object sender, MouseButtonEventArgs e) {
|
||||||
{
|
|
||||||
if (e.ChangedButton == MouseButton.Left) DragMove();
|
if (e.ChangedButton == MouseButton.Left) DragMove();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StartProgress()
|
private void StartProgress() {
|
||||||
{
|
|
||||||
progressBar.Visibility = Visibility.Visible;
|
progressBar.Visibility = Visibility.Visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StopProgress()
|
private void StopProgress() {
|
||||||
{
|
|
||||||
progressBar.Visibility = Visibility.Hidden;
|
progressBar.Visibility = Visibility.Hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HideWox()
|
private void HideWox() {
|
||||||
{
|
|
||||||
Hide();
|
Hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ShowWox(bool selectAll = true)
|
private void ShowWox(bool selectAll = true) {
|
||||||
{
|
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));
|
||||||
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
|
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
|
||||||
var coordX = (Left - origScreen.WorkingArea.Left) / (origScreen.WorkingArea.Width - ActualWidth);
|
var coordX = (Left - origScreen.WorkingArea.Left) / (origScreen.WorkingArea.Width - ActualWidth);
|
||||||
@@ -394,19 +335,15 @@ namespace Wox
|
|||||||
if (selectAll) tbQuery.SelectAll();
|
if (selectAll) tbQuery.SelectAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ParseArgs(string[] args)
|
public void ParseArgs(string[] args) {
|
||||||
{
|
if (args != null && args.Length > 0) {
|
||||||
if (args != null && args.Length > 0)
|
switch (args[0].ToLower()) {
|
||||||
{
|
|
||||||
switch (args[0].ToLower())
|
|
||||||
{
|
|
||||||
case "reloadplugin":
|
case "reloadplugin":
|
||||||
Plugins.Init();
|
Plugins.Init();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "query":
|
case "query":
|
||||||
if (args.Length > 1)
|
if (args.Length > 1) {
|
||||||
{
|
|
||||||
string query = args[1];
|
string query = args[1];
|
||||||
tbQuery.Text = query;
|
tbQuery.Text = query;
|
||||||
tbQuery.SelectAll();
|
tbQuery.SelectAll();
|
||||||
@@ -419,8 +356,7 @@ namespace Wox
|
|||||||
|
|
||||||
case "installplugin":
|
case "installplugin":
|
||||||
var path = args[1];
|
var path = args[1];
|
||||||
if (!File.Exists(path))
|
if (!File.Exists(path)) {
|
||||||
{
|
|
||||||
MessageBox.Show("Plugin " + path + " didn't exist");
|
MessageBox.Show("Plugin " + path + " didn't exist");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -430,27 +366,21 @@ namespace Wox
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MainWindow_OnDeactivated(object sender, EventArgs e)
|
private void MainWindow_OnDeactivated(object sender, EventArgs e) {
|
||||||
{
|
if (UserSettingStorage.Instance.HideWhenDeactive) {
|
||||||
if (UserSettingStorage.Instance.HideWhenDeactive)
|
|
||||||
{
|
|
||||||
HideWox();
|
HideWox();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, SpecialKeyState state)
|
private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, SpecialKeyState state) {
|
||||||
{
|
if (UserSettingStorage.Instance.ReplaceWinR) {
|
||||||
if (UserSettingStorage.Instance.ReplaceWinR)
|
|
||||||
{
|
|
||||||
//todo:need refactoring. move those codes to CMD file or expose events
|
//todo:need refactoring. 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(VirtualKeyCode.LWIN, VirtualKeyCode.CONTROL);
|
keyboardSimulator.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.CONTROL);
|
||||||
return false;
|
return false;
|
||||||
@@ -459,11 +389,9 @@ namespace Wox
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnWinRPressed()
|
private void OnWinRPressed() {
|
||||||
{
|
|
||||||
ShowWox(false);
|
ShowWox(false);
|
||||||
if (!tbQuery.Text.StartsWith(">"))
|
if (!tbQuery.Text.StartsWith(">")) {
|
||||||
{
|
|
||||||
resultCtrl.Clear();
|
resultCtrl.Clear();
|
||||||
ChangeQuery(">");
|
ChangeQuery(">");
|
||||||
}
|
}
|
||||||
@@ -472,23 +400,19 @@ namespace Wox
|
|||||||
tbQuery.SelectionLength = tbQuery.Text.Length - 1;
|
tbQuery.SelectionLength = tbQuery.Text.Length - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateCmdMode()
|
private void updateCmdMode() {
|
||||||
{
|
|
||||||
var currentSelectedItem = resultCtrl.GetActiveResult();
|
var currentSelectedItem = resultCtrl.GetActiveResult();
|
||||||
if (currentSelectedItem != null)
|
if (currentSelectedItem != null) {
|
||||||
{
|
|
||||||
ignoreTextChange = true;
|
ignoreTextChange = true;
|
||||||
tbQuery.Text = ">" + currentSelectedItem.Title;
|
tbQuery.Text = ">" + currentSelectedItem.Title;
|
||||||
tbQuery.CaretIndex = tbQuery.Text.Length;
|
tbQuery.CaretIndex = tbQuery.Text.Length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void TbQuery_OnPreviewKeyDown(object sender, KeyEventArgs e)
|
private void TbQuery_OnPreviewKeyDown(object sender, KeyEventArgs e) {
|
||||||
{
|
|
||||||
//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);
|
||||||
switch (key)
|
switch (key) {
|
||||||
{
|
|
||||||
case Key.Escape:
|
case Key.Escape:
|
||||||
HideWox();
|
HideWox();
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
@@ -522,16 +446,9 @@ namespace Wox
|
|||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Key.Enter:
|
|
||||||
AcceptSelect(resultCtrl.GetActiveResult());
|
|
||||||
e.Handled = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Key.Back:
|
case Key.Back:
|
||||||
if (BackKeyDownEvent != null)
|
if (BackKeyDownEvent != null) {
|
||||||
{
|
BackKeyDownEvent(tbQuery, new WoxKeyDownEventArgs() {
|
||||||
BackKeyDownEvent(tbQuery, new WoxKeyDownEventArgs()
|
|
||||||
{
|
|
||||||
Query = tbQuery.Text,
|
Query = tbQuery.Text,
|
||||||
keyEventArgs = e
|
keyEventArgs = e
|
||||||
});
|
});
|
||||||
@@ -539,24 +456,20 @@ namespace Wox
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Key.Tab:
|
case Key.Tab:
|
||||||
|
case Key.Enter:
|
||||||
AcceptSelect(resultCtrl.GetActiveResult());
|
AcceptSelect(resultCtrl.GetActiveResult());
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AcceptSelect(Result result)
|
private void AcceptSelect(Result result) {
|
||||||
{
|
if (!resultCtrl.Dirty && result != null) {
|
||||||
if (!resultCtrl.Dirty && result != null)
|
if (result.Action != null) {
|
||||||
{
|
bool hideWindow = result.Action(new ActionContext() {
|
||||||
if (result.Action != null)
|
|
||||||
{
|
|
||||||
bool hideWindow = result.Action(new ActionContext()
|
|
||||||
{
|
|
||||||
SpecialKeyState = new GlobalHotkey().CheckModifiers()
|
SpecialKeyState = new GlobalHotkey().CheckModifiers()
|
||||||
});
|
});
|
||||||
if (hideWindow)
|
if (hideWindow) {
|
||||||
{
|
|
||||||
HideWox();
|
HideWox();
|
||||||
}
|
}
|
||||||
UserSelectedRecordStorage.Instance.Add(result);
|
UserSelectedRecordStorage.Instance.Add(result);
|
||||||
@@ -564,26 +477,21 @@ namespace Wox
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnUpdateResultView(List<Result> list)
|
public void OnUpdateResultView(List<Result> list) {
|
||||||
{
|
|
||||||
queryHasReturn = true;
|
queryHasReturn = true;
|
||||||
progressBar.Dispatcher.Invoke(new Action(StopProgress));
|
progressBar.Dispatcher.Invoke(new Action(StopProgress));
|
||||||
if (list == null || list.Count == 0) return;
|
if (list == null || list.Count == 0) return;
|
||||||
|
|
||||||
if (list.Count > 0)
|
if (list.Count > 0) {
|
||||||
{
|
|
||||||
//todo:this should be opened to users, it's their choice to use it or not in their workflows
|
//todo:this should be opened to users, it's their choice to use it or not in their workflows
|
||||||
list.ForEach(
|
list.ForEach(
|
||||||
o =>
|
o => {
|
||||||
{
|
|
||||||
if (o.AutoAjustScore) o.Score += UserSelectedRecordStorage.Instance.GetSelectedCount(o);
|
if (o.AutoAjustScore) o.Score += UserSelectedRecordStorage.Instance.GetSelectedCount(o);
|
||||||
});
|
});
|
||||||
lock (locker)
|
lock (locker) {
|
||||||
{
|
|
||||||
waitShowResultList.AddRange(list);
|
waitShowResultList.AddRange(list);
|
||||||
}
|
}
|
||||||
Dispatcher.DelayInvoke("ShowResult", k => resultCtrl.Dispatcher.Invoke(new Action(() =>
|
Dispatcher.DelayInvoke("ShowResult", k => resultCtrl.Dispatcher.Invoke(new Action(() => {
|
||||||
{
|
|
||||||
List<Result> l = waitShowResultList.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == lastQuery).ToList();
|
List<Result> l = waitShowResultList.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == lastQuery).ToList();
|
||||||
waitShowResultList.Clear();
|
waitShowResultList.Clear();
|
||||||
resultCtrl.AddResults(l);
|
resultCtrl.AddResults(l);
|
||||||
@@ -591,17 +499,14 @@ namespace Wox
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetTheme(string themeName)
|
public void SetTheme(string themeName) {
|
||||||
{
|
var dict = new ResourceDictionary {
|
||||||
var dict = new ResourceDictionary
|
|
||||||
{
|
|
||||||
Source = new Uri(Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Themes\\" + themeName + ".xaml"), UriKind.Absolute)
|
Source = new Uri(Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Themes\\" + themeName + ".xaml"), UriKind.Absolute)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Style queryBoxStyle = dict["QueryBoxStyle"] as Style;
|
Style queryBoxStyle = dict["QueryBoxStyle"] as Style;
|
||||||
if (queryBoxStyle != null)
|
if (queryBoxStyle != null) {
|
||||||
{
|
|
||||||
queryBoxStyle.Setters.Add(new Setter(TextBox.FontFamilyProperty, new FontFamily(UserSettingStorage.Instance.QueryBoxFont)));
|
queryBoxStyle.Setters.Add(new Setter(TextBox.FontFamilyProperty, new FontFamily(UserSettingStorage.Instance.QueryBoxFont)));
|
||||||
queryBoxStyle.Setters.Add(new Setter(TextBox.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontStyle)));
|
queryBoxStyle.Setters.Add(new Setter(TextBox.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontStyle)));
|
||||||
queryBoxStyle.Setters.Add(new Setter(TextBox.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontWeight)));
|
queryBoxStyle.Setters.Add(new Setter(TextBox.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontWeight)));
|
||||||
@@ -612,8 +517,7 @@ namespace Wox
|
|||||||
Style resultSubItemStyle = dict["ItemSubTitleStyle"] as Style;
|
Style resultSubItemStyle = dict["ItemSubTitleStyle"] as Style;
|
||||||
Style resultItemSelectedStyle = dict["ItemTitleSelectedStyle"] as Style;
|
Style resultItemSelectedStyle = dict["ItemTitleSelectedStyle"] as Style;
|
||||||
Style resultSubItemSelectedStyle = dict["ItemSubTitleSelectedStyle"] as Style;
|
Style resultSubItemSelectedStyle = dict["ItemSubTitleSelectedStyle"] as Style;
|
||||||
if (resultItemStyle != null && resultSubItemStyle != null && resultSubItemSelectedStyle != null && resultItemSelectedStyle != null)
|
if (resultItemStyle != null && resultSubItemStyle != null && resultSubItemSelectedStyle != null && resultItemSelectedStyle != null) {
|
||||||
{
|
|
||||||
Setter fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(UserSettingStorage.Instance.ResultItemFont));
|
Setter fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(UserSettingStorage.Instance.ResultItemFont));
|
||||||
Setter fontStyle = new Setter(TextBlock.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontStyle));
|
Setter fontStyle = new Setter(TextBlock.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontStyle));
|
||||||
Setter fontWeight = new Setter(TextBlock.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontWeight));
|
Setter fontWeight = new Setter(TextBlock.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontWeight));
|
||||||
@@ -629,42 +533,34 @@ namespace Wox
|
|||||||
this.Opacity = this.AllowsTransparency ? UserSettingStorage.Instance.Opacity : 1;
|
this.Opacity = this.AllowsTransparency ? UserSettingStorage.Instance.Opacity : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ShellRun(string cmd)
|
public bool ShellRun(string cmd) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(cmd))
|
if (string.IsNullOrEmpty(cmd))
|
||||||
throw new ArgumentNullException();
|
throw new ArgumentNullException();
|
||||||
|
|
||||||
Wox.Infrastructure.WindowsShellRun.Start(cmd);
|
Wox.Infrastructure.WindowsShellRun.Start(cmd);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex) {
|
||||||
{
|
|
||||||
ShowMsg("Could not start " + cmd, ex.Message, null);
|
ShowMsg("Could not start " + cmd, ex.Message, null);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MainWindow_OnDrop(object sender, DragEventArgs e)
|
private void MainWindow_OnDrop(object sender, DragEventArgs e) {
|
||||||
{
|
if (e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop)) {
|
||||||
if (e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop))
|
|
||||||
{
|
|
||||||
// Note that you can have more than one file.
|
// Note that you can have more than one file.
|
||||||
string[] files = (string[])e.Data.GetData(System.Windows.DataFormats.FileDrop);
|
string[] files = (string[])e.Data.GetData(System.Windows.DataFormats.FileDrop);
|
||||||
if (files[0].ToLower().EndsWith(".wox"))
|
if (files[0].ToLower().EndsWith(".wox")) {
|
||||||
{
|
|
||||||
PluginInstaller.Install(files[0]);
|
PluginInstaller.Install(files[0]);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
MessageBox.Show("incorrect wox plugin file.");
|
MessageBox.Show("incorrect wox plugin file.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void TbQuery_OnPreviewDragOver(object sender, DragEventArgs e)
|
private void TbQuery_OnPreviewDragOver(object sender, DragEventArgs e) {
|
||||||
{
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user