From 88a47e7788abf2cab49adc85d1c3754a9676d3ec Mon Sep 17 00:00:00 2001 From: stafford Date: Fri, 11 Mar 2016 12:13:47 +1100 Subject: [PATCH 1/4] made margins consistent --- Wox/SettingWindow.xaml | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/Wox/SettingWindow.xaml b/Wox/SettingWindow.xaml index 7a2780fda4..b55fa458d3 100644 --- a/Wox/SettingWindow.xaml +++ b/Wox/SettingWindow.xaml @@ -22,7 +22,7 @@ - + @@ -55,8 +55,8 @@ - - + + @@ -129,8 +129,8 @@ - - + + @@ -294,25 +294,30 @@ + + + - - - + + + - - + + - + - + - + From d6f9fddc94bd2bd05ff5ad3a3b2060c0637fd960 Mon Sep 17 00:00:00 2001 From: bao-qian Date: Fri, 25 Mar 2016 01:22:24 +0000 Subject: [PATCH 2/4] Refactoring CustomizedPluginConfig 1. Reorder the sequence of initialization of UserSettings. 2. Use dictionary for CustomizedPluginConfigs, so code logic like `.FirstOrDefault(o => o.ID == id);` are removed 3. part of #389 --- .../PluginIndicator.cs | 5 +- Wox.Core/Plugin/PluginConfig.cs | 12 +-- Wox.Core/Plugin/PluginManager.cs | 4 +- .../UserSettings/CustomizedPluginConfig.cs | 5 +- Wox.Core/UserSettings/UserSettingStorage.cs | 101 +++++++++--------- Wox.Plugin/Wox.Plugin.csproj | 5 + Wox.Plugin/packages.config | 4 + Wox/App.xaml.cs | 10 +- Wox/PublicAPIInstance.cs | 11 +- Wox/SettingWindow.xaml.cs | 8 +- 10 files changed, 79 insertions(+), 86 deletions(-) create mode 100644 Wox.Plugin/packages.config diff --git a/Plugins/Wox.Plugin.PluginIndicator/PluginIndicator.cs b/Plugins/Wox.Plugin.PluginIndicator/PluginIndicator.cs index 63f0c2e186..1283c77639 100644 --- a/Plugins/Wox.Plugin.PluginIndicator/PluginIndicator.cs +++ b/Plugins/Wox.Plugin.PluginIndicator/PluginIndicator.cs @@ -14,9 +14,8 @@ namespace Wox.Plugin.PluginIndicator var results = from keyword in PluginManager.NonGlobalPlugins.Keys where keyword.StartsWith(query.Terms[0]) let metadata = PluginManager.NonGlobalPlugins[keyword].Metadata - let customizedPluginConfig = - UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == metadata.ID) - where customizedPluginConfig == null || !customizedPluginConfig.Disabled + let customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs[metadata.ID] + where !customizedPluginConfig.Disabled select new Result { Title = keyword, diff --git a/Wox.Core/Plugin/PluginConfig.cs b/Wox.Core/Plugin/PluginConfig.cs index 0a8d286c1d..7d0ba4958e 100644 --- a/Wox.Core/Plugin/PluginConfig.cs +++ b/Wox.Core/Plugin/PluginConfig.cs @@ -1,9 +1,7 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using Newtonsoft.Json; -using Wox.Core.UserSettings; using Wox.Infrastructure.Exception; using Wox.Infrastructure.Logger; using Wox.Plugin; @@ -74,7 +72,7 @@ namespace Wox.Core.Plugin metadata = JsonConvert.DeserializeObject(File.ReadAllText(configPath)); metadata.PluginDirectory = pluginDirectory; // for plugins which doesn't has ActionKeywords key - metadata.ActionKeywords = metadata.ActionKeywords ?? new List {metadata.ActionKeyword}; + metadata.ActionKeywords = metadata.ActionKeywords ?? new List { metadata.ActionKeyword }; // for plugin still use old ActionKeyword metadata.ActionKeyword = metadata.ActionKeywords?[0]; } @@ -100,14 +98,6 @@ namespace Wox.Core.Plugin return null; } - //replace action keyword if user customized it. - var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == metadata.ID); - if (customizedPluginConfig?.ActionKeywords?.Count > 0) - { - metadata.ActionKeywords = customizedPluginConfig.ActionKeywords; - metadata.ActionKeyword = customizedPluginConfig.ActionKeywords[0]; - } - return metadata; } } diff --git a/Wox.Core/Plugin/PluginManager.cs b/Wox.Core/Plugin/PluginManager.cs index f3da6bb0ea..9388248810 100644 --- a/Wox.Core/Plugin/PluginManager.cs +++ b/Wox.Core/Plugin/PluginManager.cs @@ -156,8 +156,8 @@ namespace Wox.Core.Plugin foreach (var plugin in pluginPairs) { var customizedPluginConfig = UserSettingStorage.Instance. - CustomizedPluginConfigs.FirstOrDefault(o => o.ID == plugin.Metadata.ID); - if (customizedPluginConfig != null && customizedPluginConfig.Disabled) continue; + CustomizedPluginConfigs[plugin.Metadata.ID]; + if (customizedPluginConfig.Disabled) continue; if (IsInstantQueryPlugin(plugin)) { Stopwatch.Normal($"Instant QueryForPlugin for {plugin.Metadata.Name}", () => diff --git a/Wox.Core/UserSettings/CustomizedPluginConfig.cs b/Wox.Core/UserSettings/CustomizedPluginConfig.cs index bce1fd9bc8..c58bb96477 100644 --- a/Wox.Core/UserSettings/CustomizedPluginConfig.cs +++ b/Wox.Core/UserSettings/CustomizedPluginConfig.cs @@ -1,9 +1,8 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; namespace Wox.Core.UserSettings { - [Serializable] + public class CustomizedPluginConfig { public string ID { get; set; } diff --git a/Wox.Core/UserSettings/UserSettingStorage.cs b/Wox.Core/UserSettings/UserSettingStorage.cs index d5d54a48f3..b9a7f8ab7f 100644 --- a/Wox.Core/UserSettings/UserSettingStorage.cs +++ b/Wox.Core/UserSettings/UserSettingStorage.cs @@ -1,110 +1,80 @@ using System; using System.Collections.Generic; using System.Drawing; -using System.IO; using System.Linq; -using System.Reflection; -using Newtonsoft.Json; +using Wox.Core.Plugin; using Wox.Infrastructure.Storage; using Wox.Plugin; +using Newtonsoft.Json; namespace Wox.Core.UserSettings { public class UserSettingStorage : JsonStrorage { - [JsonProperty] public bool DontPromptUpdateMsg { get; set; } - [JsonProperty] public int ActivateTimes { get; set; } - - [JsonProperty] public bool EnableUpdateLog { get; set; } - [JsonProperty] public string Hotkey { get; set; } - [JsonProperty] public string Language { get; set; } - [JsonProperty] public string Theme { get; set; } - [JsonProperty] public string QueryBoxFont { get; set; } - [JsonProperty] public string QueryBoxFontStyle { get; set; } - [JsonProperty] public string QueryBoxFontWeight { get; set; } - [JsonProperty] public string QueryBoxFontStretch { get; set; } - [JsonProperty] public string ResultFont { get; set; } - [JsonProperty] public string ResultFontStyle { get; set; } - [JsonProperty] public string ResultFontWeight { get; set; } - [JsonProperty] public string ResultFontStretch { get; set; } - [JsonProperty] public double WindowLeft { get; set; } - [JsonProperty] public double WindowTop { get; set; } - public List CustomizedPluginConfigs { get; set; } + // Order defaults to 0 or -1, so 1 will let this property appear last + [JsonProperty(Order = 1)] + public Dictionary CustomizedPluginConfigs { get; set; } - [JsonProperty] public List CustomPluginHotkeys { get; set; } - [JsonProperty] public bool StartWoxOnSystemStartup { get; set; } [Obsolete] - [JsonProperty] public double Opacity { get; set; } [Obsolete] - [JsonProperty] public OpacityMode OpacityMode { get; set; } - [JsonProperty] public bool LeaveCmdOpen { get; set; } - [JsonProperty] public bool HideWhenDeactive { get; set; } - [JsonProperty] public bool RememberLastLaunchLocation { get; set; } - [JsonProperty] public bool IgnoreHotkeysOnFullscreen { get; set; } - [JsonProperty] public string ProxyServer { get; set; } - [JsonProperty] public bool ProxyEnabled { get; set; } - [JsonProperty] public int ProxyPort { get; set; } - [JsonProperty] public string ProxyUserName { get; set; } - [JsonProperty] public string ProxyPassword { get; set; } - [JsonProperty] public int MaxResultsToShow { get; set; } protected override string FileName { get; } = "Settings"; @@ -123,7 +93,7 @@ namespace Wox.Core.UserSettings DontPromptUpdateMsg = false; Theme = "Dark"; Language = "en"; - CustomizedPluginConfigs = new List(); + CustomizedPluginConfigs = new Dictionary(); Hotkey = "Alt + Space"; QueryBoxFont = FontFamily.GenericSansSerif.Name; ResultFont = FontFamily.GenericSansSerif.Name; @@ -139,10 +109,38 @@ namespace Wox.Core.UserSettings protected override void OnAfterLoad(UserSettingStorage storage) { + var metadatas = PluginManager.AllPlugins.Select(p => p.Metadata); if (storage.CustomizedPluginConfigs == null) { - storage.CustomizedPluginConfigs = new List(); + var configs = new Dictionary(); + foreach (var metadata in metadatas) + { + addPluginMetadata(configs, metadata); + } + storage.CustomizedPluginConfigs = configs; } + else + { + var configs = storage.CustomizedPluginConfigs; + foreach (var metadata in metadatas) + { + if (configs.ContainsKey(metadata.ID)) + { + var config = configs[metadata.ID]; + if (config.ActionKeywords?.Count > 0) + { + metadata.ActionKeywords = config.ActionKeywords; + metadata.ActionKeyword = config.ActionKeywords[0]; + } + } + else + { + addPluginMetadata(configs, metadata); + } + } + } + + if (storage.QueryBoxFont == null) { storage.QueryBoxFont = FontFamily.GenericSansSerif.Name; @@ -157,23 +155,22 @@ namespace Wox.Core.UserSettings } } + + private void addPluginMetadata(Dictionary configs, PluginMetadata metadata) + { + configs[metadata.ID] = new CustomizedPluginConfig + { + ID = metadata.ID, + Name = metadata.Name, + ActionKeywords = metadata.ActionKeywords, + Disabled = false + }; + } + public void UpdateActionKeyword(PluginMetadata metadata) { - var customizedPluginConfig = CustomizedPluginConfigs.FirstOrDefault(o => o.ID == metadata.ID); - if (customizedPluginConfig == null) - { - CustomizedPluginConfigs.Add(new CustomizedPluginConfig - { - Disabled = false, - ID = metadata.ID, - Name = metadata.Name, - ActionKeywords = metadata.ActionKeywords - }); - } - else - { - customizedPluginConfig.ActionKeywords = metadata.ActionKeywords; - } + var config = CustomizedPluginConfigs[metadata.ID]; + config.ActionKeywords = metadata.ActionKeywords; Save(); } } diff --git a/Wox.Plugin/Wox.Plugin.csproj b/Wox.Plugin/Wox.Plugin.csproj index 559f6cf463..fef71853ef 100644 --- a/Wox.Plugin/Wox.Plugin.csproj +++ b/Wox.Plugin/Wox.Plugin.csproj @@ -34,6 +34,10 @@ false + + ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll + True + @@ -64,6 +68,7 @@ + diff --git a/Wox.Plugin/packages.config b/Wox.Plugin/packages.config new file mode 100644 index 0000000000..1975352b1b --- /dev/null +++ b/Wox.Plugin/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Wox/App.xaml.cs b/Wox/App.xaml.cs index a7d98d7348..4cbd7cea2d 100644 --- a/Wox/App.xaml.cs +++ b/Wox/App.xaml.cs @@ -8,9 +8,9 @@ using System.Threading; using System.Windows; using Wox.CommandArgs; using Wox.Core.Plugin; +using Wox.Core.UserSettings; using Wox.Helper; using Wox.Infrastructure; -using Wox.Plugin; using Wox.ViewModel; using Stopwatch = Wox.Infrastructure.Stopwatch; @@ -21,7 +21,7 @@ namespace Wox private const string Unique = "Wox_Unique_Application_Mutex"; public static MainWindow Window { get; private set; } - public static IPublicAPI API { get; private set; } + public static PublicAPIInstance API { get; private set; } [STAThread] public static void Main() @@ -50,11 +50,13 @@ namespace Wox MainViewModel mainVM = new MainViewModel(); API = new PublicAPIInstance(mainVM); Window = new MainWindow {DataContext = mainVM}; - NotifyIconManager notifyIconManager = new NotifyIconManager(API); - PluginManager.Init(API); CommandArgsFactory.Execute(e.Args.ToList()); + + // happlebao todo: the whole setting releated initialization should be put into seperate class/method + API.SetHotkey(UserSettingStorage.Instance.Hotkey, API.OnHotkey); + API.SetCustomPluginHotkey(); }); } diff --git a/Wox/PublicAPIInstance.cs b/Wox/PublicAPIInstance.cs index aec4094d35..1ab1cf0b3e 100644 --- a/Wox/PublicAPIInstance.cs +++ b/Wox/PublicAPIInstance.cs @@ -30,9 +30,6 @@ namespace Wox GlobalHotkey.Instance.hookedKeyboardCallback += KListener_hookedKeyboardCallback; WebRequest.RegisterPrefix("data", new DataWebRequestFactory()); - SetHotkey(UserSettingStorage.Instance.Hotkey, OnHotkey); - SetCustomPluginHotkey(); - MainVM.ListeningKeyPressed += (o, e) => { if(e.KeyEventArgs.Key == Key.Back) @@ -98,7 +95,7 @@ namespace Wox ShowWox(); } - public void ShowMsg(string title, string subTitle, string iconPath) + public void ShowMsg(string title, string subTitle = "", string iconPath = "") { Application.Current.Dispatcher.Invoke(() => { @@ -202,7 +199,7 @@ namespace Wox MainVM.OnTextBoxSelected(); } - public void SetHotkey(string hotkeyStr, EventHandler action) + internal void SetHotkey(string hotkeyStr, EventHandler action) { var hotkey = new HotkeyModel(hotkeyStr); SetHotkey(hotkey, action); @@ -244,7 +241,7 @@ namespace Wox return false; } - private void SetCustomPluginHotkey() + internal void SetCustomPluginHotkey() { if (UserSettingStorage.Instance.CustomPluginHotkeys == null) return; foreach (CustomPluginHotkey hotkey in UserSettingStorage.Instance.CustomPluginHotkeys) @@ -259,7 +256,7 @@ namespace Wox } } - private void OnHotkey(object sender, HotkeyEventArgs e) + protected internal void OnHotkey(object sender, HotkeyEventArgs e) { if (ShouldIgnoreHotkeys()) return; ToggleWox(); diff --git a/Wox/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs index 312060e406..f222e59035 100644 --- a/Wox/SettingWindow.xaml.cs +++ b/Wox/SettingWindow.xaml.cs @@ -567,7 +567,7 @@ namespace Wox pluginId = pair.Metadata.ID; pluginIcon.Source = ImageLoader.ImageLoader.Load(pair.Metadata.FullIcoPath); - var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == pluginId); + var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs[pluginId]; cbDisablePlugin.IsChecked = customizedPluginConfig != null && customizedPluginConfig.Disabled; PluginContentPanel.Content = null; @@ -615,17 +615,17 @@ namespace Wox id = pair.Metadata.ID; name = pair.Metadata.Name; } - var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == id); + var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs[id]; if (customizedPluginConfig == null) { // todo when this part will be invoked - UserSettingStorage.Instance.CustomizedPluginConfigs.Add(new CustomizedPluginConfig + UserSettingStorage.Instance.CustomizedPluginConfigs[id] = new CustomizedPluginConfig { Disabled = cbDisabled.IsChecked ?? true, ID = id, Name = name, ActionKeywords = null - }); + }; } else { From fbc6f78cb53c9fc135043522757c6404e4140b3d Mon Sep 17 00:00:00 2001 From: bao-qian Date: Fri, 25 Mar 2016 02:38:10 +0000 Subject: [PATCH 3/4] Fix position 1. Fix "Remember launch location", this was introduced since e7aa6022. Fix #511 2. Fix opening position ( #510 ), bug introduced from PR #494 (commit e7aa602) --- Wox/MainWindow.xaml.cs | 41 +++++++++++++++++++++++++++++----------- Wox/PublicAPIInstance.cs | 3 --- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index a28647f487..fc0f7ae165 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -34,9 +34,11 @@ 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; } @@ -63,6 +65,15 @@ namespace Wox { Activate(); QueryTextBox.Focus(); + Left = GetWindowsLeft(); + Top = GetWindowsTop(); + UserSettingStorage.Instance.IncreaseActivateTimes(); + } + else + { + UserSettingStorage.Instance.WindowLeft = Left; + UserSettingStorage.Instance.WindowTop = Top; + UserSettingStorage.Instance.Save(); } }; @@ -73,22 +84,30 @@ namespace Wox private double GetWindowsLeft() { - if (UserSettingStorage.Instance.RememberLastLaunchLocation) return UserSettingStorage.Instance.WindowLeft; + if (UserSettingStorage.Instance.RememberLastLaunchLocation) + { + return UserSettingStorage.Instance.WindowLeft; + } var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); - var dipPoint = WindowIntelopHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0); - UserSettingStorage.Instance.WindowLeft = (dipPoint.X - ActualWidth) / 2; - return UserSettingStorage.Instance.WindowLeft; + var dip1 = WindowIntelopHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0); + var dip2 = WindowIntelopHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0); + var left = (dip2.X - ActualWidth) / 2 + dip1.X; + return left; } private double GetWindowsTop() { - if (UserSettingStorage.Instance.RememberLastLaunchLocation) return UserSettingStorage.Instance.WindowTop; + if (UserSettingStorage.Instance.RememberLastLaunchLocation) + { + return UserSettingStorage.Instance.WindowTop; + } var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); - var dipPoint = WindowIntelopHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Height); - UserSettingStorage.Instance.WindowTop = (dipPoint.Y - QueryTextBox.ActualHeight) / 4; - return UserSettingStorage.Instance.WindowTop; + var dip1 = WindowIntelopHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y); + var dip2 = WindowIntelopHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Height); + var top = (dip2.Y - ActualHeight) / 4 + dip1.Y; + return top; } private void CheckUpdate() diff --git a/Wox/PublicAPIInstance.cs b/Wox/PublicAPIInstance.cs index 1ab1cf0b3e..7e5b7530b6 100644 --- a/Wox/PublicAPIInstance.cs +++ b/Wox/PublicAPIInstance.cs @@ -187,14 +187,11 @@ namespace Wox private void HideWox() { - UserSettingStorage.Instance.WindowLeft = MainVM.Left; - UserSettingStorage.Instance.WindowTop = MainVM.Top; MainVM.MainWindowVisibility = Visibility.Collapsed; } private void ShowWox(bool selectAll = true) { - UserSettingStorage.Instance.IncreaseActivateTimes(); MainVM.MainWindowVisibility = Visibility.Visible; MainVM.OnTextBoxSelected(); } From 5ac0837be3496112f7ae14efe2f46e3a80625555 Mon Sep 17 00:00:00 2001 From: bao-qian Date: Sat, 26 Mar 2016 01:20:42 +0000 Subject: [PATCH 4/4] Refactoring ContextMenu 1. Remove ItemDropEvent 2. Remove ShowContextMenus from API 3. Fix context menu item can't be opened ( #535 ), bug introduced from PR #494 (commit 45dbb50) 4. Move open result command and load context menu command back to MainViewModel 5. unify load context menu logic 6. other performance enhancement and potential bug fixed --- Plugins/Wox.Plugin.Folder/FolderPlugin.cs | 33 ---- Plugins/Wox.Plugin.Program/Programs.cs | 7 - Wox.Core/Plugin/PluginManager.cs | 23 ++- Wox.Plugin/IPublicAPI.cs | 12 -- Wox/MainWindow.xaml | 9 +- Wox/MainWindow.xaml.cs | 78 ++++++-- Wox/PublicAPIInstance.cs | 19 +- Wox/ResultListBox.xaml | 8 +- Wox/ViewModel/MainViewModel.cs | 231 ++++++++++------------ Wox/ViewModel/ResultViewModel.cs | 77 +------- Wox/ViewModel/ResultsViewModel.cs | 9 +- 11 files changed, 192 insertions(+), 314 deletions(-) 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 @@ -