mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 11:16:51 +02:00
Add Program Plugin
This commit is contained in:
@@ -1,27 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Ports;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Threading;
|
||||
using WinAlfred.Commands;
|
||||
using WinAlfred.Helper;
|
||||
using WinAlfred.Plugin;
|
||||
using WinAlfred.PluginLoader;
|
||||
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
|
||||
using MessageBox = System.Windows.MessageBox;
|
||||
using Timer = System.Threading.Timer;
|
||||
|
||||
namespace WinAlfred
|
||||
{
|
||||
public partial class MainWindow : Window
|
||||
public partial class MainWindow
|
||||
{
|
||||
private KeyboardHook hook = new KeyboardHook();
|
||||
private List<Result> results = new List<Result>();
|
||||
private NotifyIcon notifyIcon = null;
|
||||
private NotifyIcon notifyIcon;
|
||||
private Command cmdDispatcher;
|
||||
|
||||
public MainWindow()
|
||||
@@ -31,7 +29,7 @@ namespace WinAlfred
|
||||
hook.KeyPressed += OnHotKey;
|
||||
hook.RegisterHotKey(XModifierKeys.Alt, Keys.Space);
|
||||
resultCtrl.resultItemChangedEvent += resultCtrl_resultItemChangedEvent;
|
||||
ThreadPool.SetMaxThreads(10, 5);
|
||||
ThreadPool.SetMaxThreads(30, 10);
|
||||
}
|
||||
|
||||
private void InitialTray()
|
||||
@@ -54,11 +52,6 @@ namespace WinAlfred
|
||||
{
|
||||
Height = resultCtrl.pnlContainer.ActualHeight + tbQuery.Height + tbQuery.Margin.Top + tbQuery.Margin.Bottom;
|
||||
resultCtrl.Margin = resultCtrl.GetCurrentResultCount() > 0 ? new Thickness { Bottom = 10, Left = 10, Right = 10 } : new Thickness { Bottom = 0, Left = 10, Right = 10 };
|
||||
|
||||
if (resultCtrl.GetCurrentResultCount() == 1)
|
||||
{
|
||||
resultCtrl.SelectFirst();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnHotKey(object sender, KeyPressedEventArgs e)
|
||||
@@ -75,17 +68,18 @@ namespace WinAlfred
|
||||
|
||||
private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
//MessageBox.Show("s");
|
||||
resultCtrl.Dirty = true;
|
||||
//auto clear results after 50ms if there are any results returned by plugins
|
||||
//why we do this? because if we clear resulsts in the start of the text changed event
|
||||
//we will see the splash. The more closer that clear and addResult method, the less splash we will see.
|
||||
////auto clear results after 50ms if there are any results returned by plugins
|
||||
////why we do this? because if we clear resulsts in the start of the text changed event
|
||||
////we will see the splash. The more closer that clear and addResult method, the less splash we will see.
|
||||
new Timer(o =>
|
||||
{
|
||||
if (resultCtrl.Dirty)
|
||||
{
|
||||
resultCtrl.Dispatcher.Invoke(new Action(() => resultCtrl.Clear()));
|
||||
}
|
||||
}, null, TimeSpan.FromMilliseconds(50),TimeSpan.FromMilliseconds(-1));
|
||||
}, null, TimeSpan.FromMilliseconds(50), TimeSpan.FromMilliseconds(-1));
|
||||
if (string.IsNullOrEmpty(tbQuery.Text)) return;
|
||||
|
||||
var q = new Query(tbQuery.Text);
|
||||
@@ -99,17 +93,16 @@ namespace WinAlfred
|
||||
|
||||
public void ShowWinAlfred()
|
||||
{
|
||||
tbQuery.SelectAll();
|
||||
Show();
|
||||
Focus();
|
||||
FocusManager.SetFocusedElement(this, tbQuery);
|
||||
//FocusManager.SetFocusedElement(this, tbQuery);
|
||||
Keyboard.Focus(tbQuery);
|
||||
tbQuery.SelectAll();
|
||||
}
|
||||
|
||||
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Plugins.Init(this);
|
||||
cmdDispatcher = new Command(this);
|
||||
ShowWinAlfred();
|
||||
InitialTray();
|
||||
}
|
||||
|
||||
@@ -145,7 +138,7 @@ namespace WinAlfred
|
||||
resultCtrl.Dispatcher.Invoke(new Action(() =>
|
||||
{
|
||||
List<Result> l = list.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == tbQuery.Text).OrderByDescending(o => o.Score).ToList();
|
||||
resultCtrl.AddResults(l);
|
||||
resultCtrl.AddResults(l);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user