diff --git a/WinAlfred.Plugin.System/Sys.cs b/WinAlfred.Plugin.System/Sys.cs index a2badb7ce..2494cfc6d 100644 --- a/WinAlfred.Plugin.System/Sys.cs +++ b/WinAlfred.Plugin.System/Sys.cs @@ -25,6 +25,8 @@ namespace WinAlfred.Plugin.System public List Query(Query query) { + if (string.IsNullOrEmpty(query.RawQuery) || query.RawQuery.EndsWith(" ") || query.RawQuery.Length <= 1) return new List(); + List results = new List(); foreach (Result availableResult in availableResults) diff --git a/WinAlfred/DispatcherExtensions.cs b/WinAlfred/DispatcherExtensions.cs new file mode 100644 index 000000000..72f5be8ed --- /dev/null +++ b/WinAlfred/DispatcherExtensions.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows.Threading; + +namespace WinAlfred +{ + public static class DispatcherExtensions + { + private static Dictionary timers = + new Dictionary(); + private static readonly object syncRoot = new object(); + + public static string DelayInvoke(this Dispatcher dispatcher, string namedInvocation, + Action action, TimeSpan delay, + DispatcherPriority priority = DispatcherPriority.Normal) + { + lock (syncRoot) + { + if (String.IsNullOrEmpty(namedInvocation)) + { + namedInvocation = Guid.NewGuid().ToString(); + } + else + { + RemoveTimer(namedInvocation); + } + var timer = new DispatcherTimer(delay, priority, (s, e) => + { + RemoveTimer(namedInvocation); + action(); + }, dispatcher); + timer.Start(); + timers.Add(namedInvocation, timer); + return namedInvocation; + } + } + + + public static void CancelNamedInvocation(this Dispatcher dispatcher, string namedInvocation) + { + lock (syncRoot) + { + RemoveTimer(namedInvocation); + } + } + + private static void RemoveTimer(string namedInvocation) + { + if (!timers.ContainsKey(namedInvocation)) return; + timers[namedInvocation].Stop(); + timers.Remove(namedInvocation); + } + + } +} diff --git a/WinAlfred/MainWindow.xaml b/WinAlfred/MainWindow.xaml index 0d1d3d8bb..d07aa89fd 100644 --- a/WinAlfred/MainWindow.xaml +++ b/WinAlfred/MainWindow.xaml @@ -12,9 +12,15 @@ ShowInTaskbar="False" Icon="Images\ico.png" > - - - - + + + + + + + + + + diff --git a/WinAlfred/MainWindow.xaml.cs b/WinAlfred/MainWindow.xaml.cs index 5027b88ce..00e00e86c 100644 --- a/WinAlfred/MainWindow.xaml.cs +++ b/WinAlfred/MainWindow.xaml.cs @@ -6,6 +6,8 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Forms; using System.Windows.Input; +using System.Windows.Media.Animation; +using System.Windows.Shapes; using IWshRuntimeLibrary; using Microsoft.Win32; using WinAlfred.Commands; @@ -23,6 +25,7 @@ namespace WinAlfred private KeyboardHook hook = new KeyboardHook(); private NotifyIcon notifyIcon; private Command cmdDispatcher; + Storyboard progressBarStoryboard = new Storyboard(); public MainWindow() { @@ -32,6 +35,20 @@ namespace WinAlfred hook.RegisterHotKey(XModifierKeys.Alt, Keys.Space); resultCtrl.resultItemChangedEvent += resultCtrl_resultItemChangedEvent; ThreadPool.SetMaxThreads(30, 10); + InitProgressbarAnimation(); + } + + private void InitProgressbarAnimation() + { + DoubleAnimation 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))); + Storyboard.SetTargetProperty(da, new PropertyPath("(Line.X1)")); + Storyboard.SetTargetProperty(da1, new PropertyPath("(Line.X2)")); + progressBarStoryboard.Children.Add(da); + progressBarStoryboard.Children.Add(da1); + progressBarStoryboard.RepeatBehavior = RepeatBehavior.Forever; + progressBar.Visibility = Visibility.Hidden; + progressBar.BeginStoryboard(progressBarStoryboard); } private void InitialTray() @@ -66,22 +83,26 @@ 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. - new Timer(o => - { - if (resultCtrl.Dirty) - { - resultCtrl.Dispatcher.Invoke(new Action(() => resultCtrl.Clear())); - } - }, null, TimeSpan.FromMilliseconds(50), TimeSpan.FromMilliseconds(-1)); - if (string.IsNullOrEmpty(tbQuery.Text)) return; + Dispatcher.DelayInvoke("UpdateSearch", + () => + { + resultCtrl.Clear(); + var q = new Query(tbQuery.Text); + cmdDispatcher.DispatchCommand(q); + }, TimeSpan.FromMilliseconds(300)); - var q = new Query(tbQuery.Text); - cmdDispatcher.DispatchCommand(q); + } + + + private void StartProgress() + { + progressBar.Visibility = Visibility.Visible; + } + + private void StopProgress() + { + progressBar.Visibility = Visibility.Hidden; } private void HideWinAlfred() @@ -130,6 +151,7 @@ namespace WinAlfred SetAutoStart(true); //var engine = new Jurassic.ScriptEngine(); //MessageBox.Show(engine.Evaluate("5 * 10 + 2").ToString()); + StartProgress(); } private void TbQuery_OnPreviewKeyDown(object sender, KeyEventArgs e) diff --git a/WinAlfred/WinAlfred.csproj b/WinAlfred/WinAlfred.csproj index 1dbb749da..197c21d9e 100644 --- a/WinAlfred/WinAlfred.csproj +++ b/WinAlfred/WinAlfred.csproj @@ -93,6 +93,7 @@ +