From e4898bbbb3162d512856761dba131e06ccf08cff Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Mon, 30 Jun 2014 22:50:54 +0800 Subject: [PATCH] Allow drag drop to install wox plugin. --- Wox.sln | 6 ------ Wox/App.xaml.cs | 1 - Wox/MainWindow.xaml | 4 +++- Wox/MainWindow.xaml.cs | 48 +++++++++++++++++++++++++++++++++--------- 4 files changed, 41 insertions(+), 18 deletions(-) diff --git a/Wox.sln b/Wox.sln index 6319333b15..1b7a9f6859 100644 --- a/Wox.sln +++ b/Wox.sln @@ -15,8 +15,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.SystemPlugins", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Infrastructure", "Wox.Infrastructure\Wox.Infrastructure.csproj", "{4FD29318-A8AB-4D8F-AA47-60BC241B8DA3}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.UAC", "Wox.UAC\Wox.UAC.csproj", "{C9BC17A0-C2BC-4185-AC1F-32E3352C1233}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.PluginManagement", "Plugins\Wox.Plugin.PluginManagement\Wox.Plugin.PluginManagement.csproj", "{049490F0-ECD2-4148-9B39-2135EC346EBE}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.BrowserBookmark", "Plugins\Wox.Plugin.BrowserBookmark\Wox.Plugin.BrowserBookmark.csproj", "{9B130CC5-14FB-41FF-B310-0A95B6894C37}" @@ -49,10 +47,6 @@ Global {4FD29318-A8AB-4D8F-AA47-60BC241B8DA3}.Debug|Any CPU.Build.0 = Debug|Any CPU {4FD29318-A8AB-4D8F-AA47-60BC241B8DA3}.Release|Any CPU.ActiveCfg = Release|Any CPU {4FD29318-A8AB-4D8F-AA47-60BC241B8DA3}.Release|Any CPU.Build.0 = Release|Any CPU - {C9BC17A0-C2BC-4185-AC1F-32E3352C1233}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C9BC17A0-C2BC-4185-AC1F-32E3352C1233}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C9BC17A0-C2BC-4185-AC1F-32E3352C1233}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C9BC17A0-C2BC-4185-AC1F-32E3352C1233}.Release|Any CPU.Build.0 = Release|Any CPU {049490F0-ECD2-4148-9B39-2135EC346EBE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {049490F0-ECD2-4148-9B39-2135EC346EBE}.Debug|Any CPU.Build.0 = Debug|Any CPU {049490F0-ECD2-4148-9B39-2135EC346EBE}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/Wox/App.xaml.cs b/Wox/App.xaml.cs index feef2833db..0bf4f342ad 100644 --- a/Wox/App.xaml.cs +++ b/Wox/App.xaml.cs @@ -90,7 +90,6 @@ namespace Wox { } PluginInstaller.Install(path); Environment.Exit(0); - return; } if (e.Args.Length > 0 && e.Args[0].ToLower() == "plugindebugger") { diff --git a/Wox/MainWindow.xaml b/Wox/MainWindow.xaml index db95e2c228..e1e9db800e 100644 --- a/Wox/MainWindow.xaml +++ b/Wox/MainWindow.xaml @@ -9,6 +9,8 @@ Deactivated="MainWindow_OnDeactivated" WindowStyle="None" WindowStartupLocation="Manual" + Drop="MainWindow_OnDrop" + AllowDrop="True" ShowInTaskbar="False" Style="{DynamicResource WindowStyle}" Icon="Images\app.png" @@ -18,7 +20,7 @@ - + diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index 9b63dfbd1e..d25a444b44 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -24,6 +24,7 @@ using Application = System.Windows.Application; using Brushes = System.Windows.Media.Brushes; using Color = System.Windows.Media.Color; using ContextMenu = System.Windows.Forms.ContextMenu; +using DragEventArgs = System.Windows.DragEventArgs; using FontFamily = System.Windows.Media.FontFamily; using KeyEventArgs = System.Windows.Input.KeyEventArgs; using MenuItem = System.Windows.Forms.MenuItem; @@ -39,6 +40,10 @@ namespace Wox { #region Properties + private static readonly object locker = new object(); + public static bool initialized = false; + + private static readonly List waitShowResultList = new List(); private readonly GlobalHotkey globalHotkey = new GlobalHotkey(); private readonly KeyboardSimulator keyboardSimulator = new KeyboardSimulator(new InputSimulator()); private readonly Storyboard progressBarStoryboard = new Storyboard(); @@ -454,16 +459,25 @@ namespace Wox { queryHasReturn = true; progressBar.Dispatcher.Invoke(new Action(StopProgress)); - if (list.Count > 0) { - list.ForEach( - o => { - if (o.AutoAjustScore) o.Score += UserSelectedRecordStorage.Instance.GetSelectedCount(o); - }); - Dispatcher.DelayInvoke("ShowResult", k => resultCtrl.Dispatcher.Invoke(new Action(() => { - List results = list.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == lastQuery).ToList(); - resultCtrl.AddResults(results); - })), TimeSpan.FromMilliseconds(isCMDMode ? 0 : 50)); - } + if (list.Count > 0) + { + //todo:this should be opened to users, it's their choice to use it or not in their workflows + list.ForEach( + o => + { + if (o.AutoAjustScore) o.Score += UserSelectedRecordStorage.Instance.GetSelectedCount(o); + }); + lock (locker) + { + waitShowResultList.AddRange(list); + } + Dispatcher.DelayInvoke("ShowResult", k => resultCtrl.Dispatcher.Invoke(new Action(() => + { + List l = waitShowResultList.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == lastQuery).ToList(); + waitShowResultList.Clear(); + resultCtrl.AddResults(l); + })), TimeSpan.FromMilliseconds(isCMDMode ? 0 : 50)); + } } public void SetTheme(string themeName) { @@ -514,5 +528,19 @@ namespace Wox { return false; } + private void MainWindow_OnDrop(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop)) + { + // Note that you can have more than one file. + string[] files = (string[])e.Data.GetData(System.Windows.DataFormats.FileDrop); + PluginInstaller.Install(files[0]); + } + } + + private void TbQuery_OnPreviewDragOver(object sender, DragEventArgs e) + { + e.Handled = true; + } } } \ No newline at end of file