diff --git a/Plugins/Wox.Plugin.Folder/FolderPlugin.cs b/Plugins/Wox.Plugin.Folder/FolderPlugin.cs index 18d83ac4d4..18109c7092 100644 --- a/Plugins/Wox.Plugin.Folder/FolderPlugin.cs +++ b/Plugins/Wox.Plugin.Folder/FolderPlugin.cs @@ -22,7 +22,6 @@ namespace Wox.Plugin.Folder { this.context = context; this.context.API.BackKeyDownEvent += ApiBackKeyDownEvent; - this.context.API.ResultItemDropEvent += ResultDropEvent; InitialDriverList(); if (FolderStorage.Instance.FolderLinks == null) { @@ -31,38 +30,6 @@ namespace Wox.Plugin.Folder } } - void ResultDropEvent(Result result, IDataObject dropObject, DragEventArgs e) - { - if (dropObject.GetDataPresent(DataFormats.FileDrop)) - { - HanldeFilesDrop(result, dropObject); - } - e.Handled = true; - } - - private void HanldeFilesDrop(Result targetResult, IDataObject dropObject) - { - List files = ((string[])dropObject.GetData(DataFormats.FileDrop, false)).ToList(); - context.API.ShowContextMenu(context.CurrentPluginMetadata, GetContextMenusForFileDrop(targetResult, files)); - } - - private static List GetContextMenusForFileDrop(Result targetResult, List files) - { - List contextMenus = new List(); - string folderPath = ((FolderLink) targetResult.ContextData).Path; - contextMenus.Add(new Result - { - Title = "Copy to this folder", - IcoPath = "Images/copy.png", - Action = _ => - { - MessageBox.Show("Copy"); - return true; - } - }); - return contextMenus; - } - private void ApiBackKeyDownEvent(WoxKeyDownEventArgs e) { string query = e.Query; diff --git a/Plugins/Wox.Plugin.Program/Programs.cs b/Plugins/Wox.Plugin.Program/Programs.cs index 6f856899ec..3a84087f53 100644 --- a/Plugins/Wox.Plugin.Program/Programs.cs +++ b/Plugins/Wox.Plugin.Program/Programs.cs @@ -61,7 +61,6 @@ namespace Wox.Plugin.Program public void Init(PluginInitContext context) { this.context = context; - this.context.API.ResultItemDropEvent += ResultDropEvent; Stopwatch.Debug("Preload programs", () => { programs = ProgramCacheStorage.Instance.Programs; @@ -70,12 +69,6 @@ namespace Wox.Plugin.Program Stopwatch.Debug("Program Index", IndexPrograms); } - void ResultDropEvent(Result result, IDataObject dropObject, DragEventArgs e) - { - - e.Handled = true; - } - public static void IndexPrograms() { lock (lockObject) diff --git a/Wox.Core/Plugin/PluginManager.cs b/Wox.Core/Plugin/PluginManager.cs index 9388248810..ba114c3d3e 100644 --- a/Wox.Core/Plugin/PluginManager.cs +++ b/Wox.Core/Plugin/PluginManager.cs @@ -229,20 +229,33 @@ namespace Wox.Core.Plugin public static List GetContextMenusForPlugin(Result result) { var pluginPair = _contextMenuPlugins.FirstOrDefault(o => o.Metadata.ID == result.PluginID); - var plugin = (IContextMenu)pluginPair?.Plugin; - if (plugin != null) + if (pluginPair != null) { + var metadata = pluginPair.Metadata; + var plugin = (IContextMenu)pluginPair?.Plugin; + try { - return plugin.LoadContextMenus(result); + var results = plugin.LoadContextMenus(result); + foreach (var r in results) + { + r.PluginDirectory = metadata.PluginDirectory; + r.PluginID = metadata.ID; + r.OriginQuery = result.OriginQuery; + } + return results; } catch (Exception e) { - Log.Error(new WoxPluginException(pluginPair.Metadata.Name, $"Couldn't load plugin context menus", e)); + Log.Error(new WoxPluginException(metadata.Name, "Couldn't load plugin context menus", e)); + return new List(); } } + else + { + return new List(); + } - return new List(); } public static void UpdateActionKeywordForPlugin(PluginPair plugin, string oldActionKeyword, string newActionKeyword) diff --git a/Wox.Plugin/IPublicAPI.cs b/Wox.Plugin/IPublicAPI.cs index 86a4bc6250..d8b41aef46 100644 --- a/Wox.Plugin/IPublicAPI.cs +++ b/Wox.Plugin/IPublicAPI.cs @@ -15,12 +15,6 @@ namespace Wox.Plugin /// void PushResults(Query query, PluginMetadata plugin, List results); - /// - /// Show context menu with giving results - /// - /// - void ShowContextMenu(PluginMetadata plugin, List results); - /// /// Change Wox query /// @@ -115,11 +109,5 @@ namespace Wox.Plugin /// if you want to hook something like Ctrl+R, you should use this event /// event WoxGlobalKeyboardEventHandler GlobalKeyboardEvent; - - /// - /// Fired after drop to result item of current plugin - /// - /// todo: ResultItem -> Result - event ResultItemDropEventHandler ResultItemDropEvent; } } diff --git a/Wox/MainWindow.xaml b/Wox/MainWindow.xaml index 971a029e24..70e734c194 100644 --- a/Wox/MainWindow.xaml +++ b/Wox/MainWindow.xaml @@ -27,7 +27,8 @@ d:DataContext="{d:DesignInstance vm:MainViewModel, IsDesignTimeCreatable=True}"> - + + @@ -43,10 +44,8 @@ - - - - + + \ No newline at end of file diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index fc0f7ae165..5f892ce027 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -4,6 +4,7 @@ using System.Windows; using System.Windows.Forms; using System.Windows.Input; using System.Windows.Media.Animation; +using System.Windows.Controls; using Wox.Core.Plugin; using Wox.Core.Resource; using Wox.Core.Updater; @@ -35,9 +36,9 @@ namespace Wox private void OnClosing(object sender, CancelEventArgs e) { - UserSettingStorage.Instance.WindowLeft = Left; - UserSettingStorage.Instance.WindowTop = Top; - UserSettingStorage.Instance.Save(); + UserSettingStorage.Instance.WindowLeft = Left; + UserSettingStorage.Instance.WindowTop = Top; + UserSettingStorage.Instance.Save(); e.Cancel = true; } @@ -71,12 +72,13 @@ namespace Wox } else { - UserSettingStorage.Instance.WindowLeft = Left; - UserSettingStorage.Instance.WindowTop = Top; - UserSettingStorage.Instance.Save(); + UserSettingStorage.Instance.WindowLeft = Left; + UserSettingStorage.Instance.WindowTop = Top; + UserSettingStorage.Instance.Save(); } }; + // happlebao todo delete vm.Left = GetWindowsLeft(); vm.Top = GetWindowsTop(); vm.MainWindowVisibility = Visibility.Visible; @@ -160,7 +162,6 @@ namespace Wox private void OnPreviewKeyDown(object sender, KeyEventArgs e) { var vm = DataContext as MainViewModel; - if (null == vm) return; //when alt is pressed, the real key should be e.SystemKey var key = (e.Key == Key.System ? e.SystemKey : e.Key); @@ -202,10 +203,22 @@ namespace Wox case Key.O: if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed) { - vm.CtrlOCommand.Execute(null); + vm.LoadContextMenuCommand.Execute(null); } break; + case Key.Enter: + if (GlobalHotkey.Instance.CheckModifiers().ShiftPressed) + { + vm.LoadContextMenuCommand.Execute(null); + } + else + { + vm.OpenResultCommand.Execute(null); + } + e.Handled = true; + break; + case Key.Down: if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed) { @@ -262,18 +275,6 @@ namespace Wox vm.StartHelpCommand.Execute(null); break; - case Key.Enter: - if (GlobalHotkey.Instance.CheckModifiers().ShiftPressed) - { - vm.ShiftEnterCommand.Execute(null); - } - else - { - vm.OpenResultCommand.Execute(null); - } - e.Handled = true; - break; - case Key.D1: if (GlobalHotkey.Instance.CheckModifiers().AltPressed) @@ -315,10 +316,45 @@ namespace Wox vm.OpenResultCommand.Execute(5); } break; - } } + private void OnPreviewMouseButtonDown(object sender, MouseButtonEventArgs e) + { + if (sender != null && e.OriginalSource != null) + { + var r = (ResultListBox)sender; + var d = (DependencyObject)e.OriginalSource; + var item = ItemsControl.ContainerFromElement(r, d) as ListBoxItem; + var result = (ResultViewModel)item?.DataContext; + if (result != null) + { + var vm = DataContext as MainViewModel; + if (vm != null) + { + if (vm.ContextMenuVisibility.IsVisible()) + { + vm.ContextMenu.SelectResult(result); + } + else + { + vm.Results.SelectResult(result); + } + + if (e.ChangedButton == MouseButton.Left) + { + vm.OpenResultCommand.Execute(null); + } + else if (e.ChangedButton == MouseButton.Right) + { + vm.LoadContextMenuCommand.Execute(null); + } + } + } + } + } + + private void OnDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) diff --git a/Wox/PublicAPIInstance.cs b/Wox/PublicAPIInstance.cs index 7e5b7530b6..bbf4556736 100644 --- a/Wox/PublicAPIInstance.cs +++ b/Wox/PublicAPIInstance.cs @@ -30,9 +30,10 @@ namespace Wox GlobalHotkey.Instance.hookedKeyboardCallback += KListener_hookedKeyboardCallback; WebRequest.RegisterPrefix("data", new DataWebRequestFactory()); - MainVM.ListeningKeyPressed += (o, e) => { + MainVM.ListeningKeyPressed += (o, e) => + { - if(e.KeyEventArgs.Key == Key.Back) + if (e.KeyEventArgs.Key == Key.Back) { BackKeyDownEvent?.Invoke(new WoxKeyDownEventArgs { @@ -158,20 +159,6 @@ namespace Wox MainVM.UpdateResultView(results, plugin, query); } - public void ShowContextMenu(PluginMetadata plugin, List results) - { - if (results != null && results.Count > 0) - { - results.ForEach(o => - { - o.PluginDirectory = plugin.PluginDirectory; - o.PluginID = plugin.ID; - }); - - MainVM.ShowContextMenu(results, plugin.ID); - } - } - #endregion #region Private Methods diff --git a/Wox/ResultListBox.xaml b/Wox/ResultListBox.xaml index 97b2e4eb8b..e1851dbd43 100644 --- a/Wox/ResultListBox.xaml +++ b/Wox/ResultListBox.xaml @@ -16,18 +16,14 @@ -