From 52252453d99249ae7da8eb1c2a8faa1f9ed5adf1 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Thu, 1 Aug 2019 20:55:13 +1000 Subject: [PATCH 1/8] Update WebSearch plugin as System Plugin or User Plugin --- Plugins/Wox.Plugin.WebSearch/Main.cs | 80 +++++++++++++++------------- 1 file changed, 44 insertions(+), 36 deletions(-) diff --git a/Plugins/Wox.Plugin.WebSearch/Main.cs b/Plugins/Wox.Plugin.WebSearch/Main.cs index 1581ddb334..ddb126d84d 100644 --- a/Plugins/Wox.Plugin.WebSearch/Main.cs +++ b/Plugins/Wox.Plugin.WebSearch/Main.cs @@ -23,6 +23,8 @@ namespace Wox.Plugin.WebSearch public const string Images = "Images"; public static string ImagesDirectory; + private readonly string SystemPluginSearchSourceWildCardSign = "*"; + public void Save() { _viewModel.Save(); @@ -33,49 +35,55 @@ namespace Wox.Plugin.WebSearch _updateSource?.Cancel(); _updateSource = new CancellationTokenSource(); _updateToken = _updateSource.Token; + + var searchSourceList = new List(); + + _settings.SearchSources.Where(o => (o.ActionKeyword == query.ActionKeyword || o.ActionKeyword == SystemPluginSearchSourceWildCardSign) + && o.Enabled) + .ToList() + .ForEach(x => searchSourceList.Add(x)); - SearchSource searchSource = - _settings.SearchSources.FirstOrDefault(o => o.ActionKeyword == query.ActionKeyword && o.Enabled); - - if (searchSource != null) + if (searchSourceList.Any()) { - string keyword = query.Search; - string title = keyword; - string subtitle = _context.API.GetTranslation("wox_plugin_websearch_search") + " " + searchSource.Title; - if (string.IsNullOrEmpty(keyword)) + foreach (SearchSource searchSource in searchSourceList) { - var result = new Result + string keyword = query.Search; + string title = keyword; + string subtitle = _context.API.GetTranslation("wox_plugin_websearch_search") + " " + + searchSource.Title; + if (string.IsNullOrEmpty(keyword)) { - Title = subtitle, - SubTitle = string.Empty, - IcoPath = searchSource.IconPath - }; - return new List {result}; - } - else - { - var results = new List(); - var result = new Result - { - Title = title, - SubTitle = subtitle, - Score = 6, - IcoPath = searchSource.IconPath, - Action = c => + var result = new Result { - Process.Start(searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword))); - return true; - } - }; - results.Add(result); - UpdateResultsFromSuggestion(results, keyword, subtitle, searchSource, query); - return results; + Title = subtitle, + SubTitle = string.Empty, + IcoPath = searchSource.IconPath + }; + return new List {result}; + } + else + { + var results = new List(); + var result = new Result + { + Title = title, + SubTitle = subtitle, + Score = 6, + IcoPath = searchSource.IconPath, + Action = c => + { + Process.Start(searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword))); + return true; + } + }; + results.Add(result); + UpdateResultsFromSuggestion(results, keyword, subtitle, searchSource, query); + return results; + } } } - else - { - return new List(); - } + + return new List(); } private void UpdateResultsFromSuggestion(List results, string keyword, string subtitle, From 89f0cdffc72a6aac432cbe9832beb093770a67e8 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Fri, 2 Aug 2019 12:32:02 +1000 Subject: [PATCH 2/8] Update Main.cs --- Plugins/Wox.Plugin.WebSearch/Main.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Plugins/Wox.Plugin.WebSearch/Main.cs b/Plugins/Wox.Plugin.WebSearch/Main.cs index ddb126d84d..8340a326f8 100644 --- a/Plugins/Wox.Plugin.WebSearch/Main.cs +++ b/Plugins/Wox.Plugin.WebSearch/Main.cs @@ -23,7 +23,7 @@ namespace Wox.Plugin.WebSearch public const string Images = "Images"; public static string ImagesDirectory; - private readonly string SystemPluginSearchSourceWildCardSign = "*"; + private readonly string SearchSourceGlobalPluginWildCardSign = "*"; public void Save() { @@ -38,7 +38,7 @@ namespace Wox.Plugin.WebSearch var searchSourceList = new List(); - _settings.SearchSources.Where(o => (o.ActionKeyword == query.ActionKeyword || o.ActionKeyword == SystemPluginSearchSourceWildCardSign) + _settings.SearchSources.Where(o => (o.ActionKeyword == query.ActionKeyword || o.ActionKeyword == SearchSourceGlobalPluginWildCardSign) && o.Enabled) .ToList() .ForEach(x => searchSourceList.Add(x)); @@ -168,4 +168,4 @@ namespace Wox.Plugin.WebSearch public event ResultUpdatedEventHandler ResultsUpdated; } -} \ No newline at end of file +} From 977d21c929a4cc33b2fc947399ea74b9bc472684 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Fri, 2 Aug 2019 13:18:38 +1000 Subject: [PATCH 3/8] Bug fix- Edit & Delete buttons will crash if selected search source is null SelectedSearchSource will be null if the user clicks on Edit or Delete after finishing with previous edit and not highlighting the search source again. --- .../SettingsControl.xaml.cs | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/Plugins/Wox.Plugin.WebSearch/SettingsControl.xaml.cs b/Plugins/Wox.Plugin.WebSearch/SettingsControl.xaml.cs index d50e595a89..6e210c0d3f 100644 --- a/Plugins/Wox.Plugin.WebSearch/SettingsControl.xaml.cs +++ b/Plugins/Wox.Plugin.WebSearch/SettingsControl.xaml.cs @@ -1,4 +1,4 @@ -using System.Windows; +using System.Windows; using System.Windows.Controls; using Wox.Core.Plugin; @@ -28,27 +28,33 @@ namespace Wox.Plugin.WebSearch private void OnDeleteSearchSearchClick(object sender, RoutedEventArgs e) { - var selected = _settings.SelectedSearchSource; - var warning = _context.API.GetTranslation("wox_plugin_websearch_delete_warning"); - var formated = string.Format(warning, selected.Title); - - var result = MessageBox.Show(formated, string.Empty, MessageBoxButton.YesNo); - if (result == MessageBoxResult.Yes) + if (_settings.SelectedSearchSource != null) { - var id = _context.CurrentPluginMetadata.ID; - PluginManager.RemoveActionKeyword(id, selected.ActionKeyword); - _settings.SearchSources.Remove(selected); + var selected = _settings.SelectedSearchSource; + var warning = _context.API.GetTranslation("wox_plugin_websearch_delete_warning"); + var formated = string.Format(warning, selected.Title); + + var result = MessageBox.Show(formated, string.Empty, MessageBoxButton.YesNo); + if (result == MessageBoxResult.Yes) + { + var id = _context.CurrentPluginMetadata.ID; + PluginManager.RemoveActionKeyword(id, selected.ActionKeyword); + _settings.SearchSources.Remove(selected); + } } } private void OnEditSearchSourceClick(object sender, RoutedEventArgs e) { - var selected = _settings.SelectedSearchSource; - var webSearch = new SearchSourceSettingWindow + if (_settings.SelectedSearchSource != null) + { + var webSearch = new SearchSourceSettingWindow ( - _settings.SearchSources, _context, selected + _settings.SearchSources, _context, _settings.SelectedSearchSource ); - webSearch.ShowDialog(); + + webSearch.ShowDialog(); + } } } -} \ No newline at end of file +} From cb4fde9a0b45d9c4883536fac819c11b67fa6f7f Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Sun, 4 Aug 2019 11:42:08 +1000 Subject: [PATCH 4/8] Mini refactor Move Process.Start to static class level --- .../Commands/SearchWeb.cs | 27 +++++++++++++++++++ Plugins/Wox.Plugin.WebSearch/Main.cs | 6 +++-- .../Wox.Plugin.WebSearch.csproj | 1 + 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 Plugins/Wox.Plugin.WebSearch/Commands/SearchWeb.cs diff --git a/Plugins/Wox.Plugin.WebSearch/Commands/SearchWeb.cs b/Plugins/Wox.Plugin.WebSearch/Commands/SearchWeb.cs new file mode 100644 index 0000000000..7c2cc31813 --- /dev/null +++ b/Plugins/Wox.Plugin.WebSearch/Commands/SearchWeb.cs @@ -0,0 +1,27 @@ +using System; +using System.Diagnostics; +using System.IO; +using System.Linq; + +namespace Wox.Plugin.WebSearch.Commands +{ + internal static class SearchWeb + { + /// Opens search in a new browser. If no browser path is passed in then Chrome is used. + /// Leave browser path blank to use Chrome. + /// + internal static void NewBrowserWindow(this string url, string browserPath) + { + var browserExecutableName = browserPath? + .Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None) + .Last(); + + var browser = string.IsNullOrEmpty(browserExecutableName) ? "chrome" : browserPath; + + // Internet Explorer will open url in new browser window, and does not take the --new-window parameter + var browserArguements = browserExecutableName == "iexplore.exe" ? url : "--new-window " + url; + + Process.Start(browser, browserArguements); + } + } +} diff --git a/Plugins/Wox.Plugin.WebSearch/Main.cs b/Plugins/Wox.Plugin.WebSearch/Main.cs index 8340a326f8..28d0757613 100644 --- a/Plugins/Wox.Plugin.WebSearch/Main.cs +++ b/Plugins/Wox.Plugin.WebSearch/Main.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using System.Windows.Controls; using Wox.Infrastructure; using Wox.Infrastructure.Storage; +using Wox.Plugin.WebSearch.Commands; namespace Wox.Plugin.WebSearch { @@ -72,7 +73,8 @@ namespace Wox.Plugin.WebSearch IcoPath = searchSource.IconPath, Action = c => { - Process.Start(searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword))); + searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword)).NewBrowserWindow(""); + return true; } }; @@ -123,7 +125,7 @@ namespace Wox.Plugin.WebSearch IcoPath = searchSource.IconPath, Action = c => { - Process.Start(searchSource.Url.Replace("{q}", Uri.EscapeDataString(o))); + searchSource.Url.Replace("{q}", Uri.EscapeDataString(o)).NewBrowserWindow(""); return true; } }); diff --git a/Plugins/Wox.Plugin.WebSearch/Wox.Plugin.WebSearch.csproj b/Plugins/Wox.Plugin.WebSearch/Wox.Plugin.WebSearch.csproj index 858b6fd433..ae06a9f3c4 100644 --- a/Plugins/Wox.Plugin.WebSearch/Wox.Plugin.WebSearch.csproj +++ b/Plugins/Wox.Plugin.WebSearch/Wox.Plugin.WebSearch.csproj @@ -58,6 +58,7 @@ Properties\SolutionAssemblyInfo.cs + From 9d89c1d692127b0c5be252b483d714502a4887b2 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Sun, 4 Aug 2019 21:38:36 +1000 Subject: [PATCH 5/8] update --- Plugins/Wox.Plugin.WebSearch/Main.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Plugins/Wox.Plugin.WebSearch/Main.cs b/Plugins/Wox.Plugin.WebSearch/Main.cs index 28d0757613..1df937d564 100644 --- a/Plugins/Wox.Plugin.WebSearch/Main.cs +++ b/Plugins/Wox.Plugin.WebSearch/Main.cs @@ -33,12 +33,13 @@ namespace Wox.Plugin.WebSearch public List Query(Query query) { + var searchSourceList = new List(); + var results = new List(); + _updateSource?.Cancel(); _updateSource = new CancellationTokenSource(); _updateToken = _updateSource.Token; - var searchSourceList = new List(); - _settings.SearchSources.Where(o => (o.ActionKeyword == query.ActionKeyword || o.ActionKeyword == SearchSourceGlobalPluginWildCardSign) && o.Enabled) .ToList() @@ -60,11 +61,10 @@ namespace Wox.Plugin.WebSearch SubTitle = string.Empty, IcoPath = searchSource.IconPath }; - return new List {result}; + results.Add(result); } else { - var results = new List(); var result = new Result { Title = title, @@ -79,13 +79,12 @@ namespace Wox.Plugin.WebSearch } }; results.Add(result); - UpdateResultsFromSuggestion(results, keyword, subtitle, searchSource, query); - return results; + UpdateResultsFromSuggestion(results, keyword, subtitle, searchSource, query); } } } - return new List(); + return results; } private void UpdateResultsFromSuggestion(List results, string keyword, string subtitle, From 45483809c50ec35ce448d95a53348a51eff5bee3 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Sun, 4 Aug 2019 21:44:56 +1000 Subject: [PATCH 6/8] Update RemoveActionKeyword method Update the method to handle removal when a plugin has multiple ActionKeywords ie. mix of global and non-global ActionKeywords --- Wox.Core/Plugin/PluginManager.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Wox.Core/Plugin/PluginManager.cs b/Wox.Core/Plugin/PluginManager.cs index ecbf9e3905..97b260114e 100644 --- a/Wox.Core/Plugin/PluginManager.cs +++ b/Wox.Core/Plugin/PluginManager.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -289,14 +289,20 @@ namespace Wox.Core.Plugin public static void RemoveActionKeyword(string id, string oldActionkeyword) { var plugin = GetPluginForId(id); - if (oldActionkeyword == Query.GlobalPluginWildcardSign) + if (oldActionkeyword == Query.GlobalPluginWildcardSign + && // Plugins may have multiple ActionKeywords that are global, eg. WebSearch + plugin.Metadata.ActionKeywords + .Where(x => x == Query.GlobalPluginWildcardSign) + .ToList() + .Count == 1) { GlobalPlugins.Remove(plugin); } - else - { + + if(oldActionkeyword != Query.GlobalPluginWildcardSign) NonGlobalPlugins.Remove(oldActionkeyword); - } + + plugin.Metadata.ActionKeywords.Remove(oldActionkeyword); } From ef34a63f7a4416e1499e98fa32055262079f6f6d Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Sun, 4 Aug 2019 21:47:05 +1000 Subject: [PATCH 7/8] Update Initialisation of plugin method Handle when plugin has a mix of global and non-global action keywords --- Wox.Core/Plugin/PluginManager.cs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Wox.Core/Plugin/PluginManager.cs b/Wox.Core/Plugin/PluginManager.cs index 97b260114e..6ca826fd9b 100644 --- a/Wox.Core/Plugin/PluginManager.cs +++ b/Wox.Core/Plugin/PluginManager.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -106,16 +106,12 @@ namespace Wox.Core.Plugin foreach (var plugin in AllPlugins) { if (IsGlobalPlugin(plugin.Metadata)) - { GlobalPlugins.Add(plugin); - } - else - { - foreach (string actionKeyword in plugin.Metadata.ActionKeywords) - { - NonGlobalPlugins[actionKeyword] = plugin; - } - } + + // Plugins may have multiple ActionKeywords, eg. WebSearch + plugin.Metadata.ActionKeywords.Where(x => x != Query.GlobalPluginWildcardSign) + .ToList() + .ForEach(x => NonGlobalPlugins[x] = plugin); } } From 06d4a82706e832e03a64752fcda5fe960feb03e0 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Tue, 6 Aug 2019 21:49:51 +1000 Subject: [PATCH 8/8] Add shared commands and move to shared --- .../Commands/SearchWeb.cs | 27 ------------------- Plugins/Wox.Plugin.WebSearch/Main.cs | 2 +- .../Wox.Plugin.WebSearch.csproj | 1 - Wox.Plugin/SharedCommands/SearchWeb.cs | 6 ++--- 4 files changed, 4 insertions(+), 32 deletions(-) delete mode 100644 Plugins/Wox.Plugin.WebSearch/Commands/SearchWeb.cs diff --git a/Plugins/Wox.Plugin.WebSearch/Commands/SearchWeb.cs b/Plugins/Wox.Plugin.WebSearch/Commands/SearchWeb.cs deleted file mode 100644 index 7c2cc31813..0000000000 --- a/Plugins/Wox.Plugin.WebSearch/Commands/SearchWeb.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Diagnostics; -using System.IO; -using System.Linq; - -namespace Wox.Plugin.WebSearch.Commands -{ - internal static class SearchWeb - { - /// Opens search in a new browser. If no browser path is passed in then Chrome is used. - /// Leave browser path blank to use Chrome. - /// - internal static void NewBrowserWindow(this string url, string browserPath) - { - var browserExecutableName = browserPath? - .Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None) - .Last(); - - var browser = string.IsNullOrEmpty(browserExecutableName) ? "chrome" : browserPath; - - // Internet Explorer will open url in new browser window, and does not take the --new-window parameter - var browserArguements = browserExecutableName == "iexplore.exe" ? url : "--new-window " + url; - - Process.Start(browser, browserArguements); - } - } -} diff --git a/Plugins/Wox.Plugin.WebSearch/Main.cs b/Plugins/Wox.Plugin.WebSearch/Main.cs index 1df937d564..ea7720329f 100644 --- a/Plugins/Wox.Plugin.WebSearch/Main.cs +++ b/Plugins/Wox.Plugin.WebSearch/Main.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; using System.Windows.Controls; using Wox.Infrastructure; using Wox.Infrastructure.Storage; -using Wox.Plugin.WebSearch.Commands; +using Wox.Plugin.SharedCommands; namespace Wox.Plugin.WebSearch { diff --git a/Plugins/Wox.Plugin.WebSearch/Wox.Plugin.WebSearch.csproj b/Plugins/Wox.Plugin.WebSearch/Wox.Plugin.WebSearch.csproj index ae06a9f3c4..858b6fd433 100644 --- a/Plugins/Wox.Plugin.WebSearch/Wox.Plugin.WebSearch.csproj +++ b/Plugins/Wox.Plugin.WebSearch/Wox.Plugin.WebSearch.csproj @@ -58,7 +58,6 @@ Properties\SolutionAssemblyInfo.cs - diff --git a/Wox.Plugin/SharedCommands/SearchWeb.cs b/Wox.Plugin/SharedCommands/SearchWeb.cs index 7c2cc31813..0dc03ee6d5 100644 --- a/Wox.Plugin/SharedCommands/SearchWeb.cs +++ b/Wox.Plugin/SharedCommands/SearchWeb.cs @@ -3,14 +3,14 @@ using System.Diagnostics; using System.IO; using System.Linq; -namespace Wox.Plugin.WebSearch.Commands +namespace Wox.Plugin.SharedCommands { - internal static class SearchWeb + public static class SearchWeb { /// Opens search in a new browser. If no browser path is passed in then Chrome is used. /// Leave browser path blank to use Chrome. /// - internal static void NewBrowserWindow(this string url, string browserPath) + public static void NewBrowserWindow(this string url, string browserPath) { var browserExecutableName = browserPath? .Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None)