diff --git a/Plugins/Wox.Plugin.PluginManagement/Main.cs b/Plugins/Wox.Plugin.PluginManagement/Main.cs index 7af6db925..eba761825 100644 --- a/Plugins/Wox.Plugin.PluginManagement/Main.cs +++ b/Plugins/Wox.Plugin.PluginManagement/Main.cs @@ -113,7 +113,7 @@ namespace Wox.Plugin.PluginManagement string json; try { - json = Http.Get(pluginSearchUrl + pluginName, context.Proxy).Result; + json = Http.Get(pluginSearchUrl + pluginName).Result; } catch (WebException e) { @@ -156,7 +156,7 @@ namespace Wox.Plugin.PluginManagement try { - Http.Download(pluginUrl, filePath, context.Proxy); + Http.Download(pluginUrl, filePath); } catch (WebException e) { diff --git a/Plugins/Wox.Plugin.WebSearch/Languages/de.xaml b/Plugins/Wox.Plugin.WebSearch/Languages/de.xaml index 1ff21cba4..9cc70038b 100644 --- a/Plugins/Wox.Plugin.WebSearch/Languages/de.xaml +++ b/Plugins/Wox.Plugin.WebSearch/Languages/de.xaml @@ -5,6 +5,7 @@ Löschen Bearbeiten Hinzufügen + Confirm Aktionsschlüsselwort URL Suche @@ -12,7 +13,7 @@ Bitte wähle einen Suchdienst Willst du wirklich {0} löschen? - + Titel Aktivieren diff --git a/Plugins/Wox.Plugin.WebSearch/Languages/en.xaml b/Plugins/Wox.Plugin.WebSearch/Languages/en.xaml index cdfc44cb3..f3d8135ca 100644 --- a/Plugins/Wox.Plugin.WebSearch/Languages/en.xaml +++ b/Plugins/Wox.Plugin.WebSearch/Languages/en.xaml @@ -5,13 +5,14 @@ Delete Edit Add + Confirm Action Keyword URL Search Enable search suggestions Please select a web search Are you sure you want to delete {0}? - + Title Enable diff --git a/Plugins/Wox.Plugin.WebSearch/Languages/pl.xaml b/Plugins/Wox.Plugin.WebSearch/Languages/pl.xaml index f3bb831ac..fb6acf941 100644 --- a/Plugins/Wox.Plugin.WebSearch/Languages/pl.xaml +++ b/Plugins/Wox.Plugin.WebSearch/Languages/pl.xaml @@ -5,13 +5,14 @@ Usuń Edytuj Dodaj + Confirm Wyzwalacz Adres URL Szukaj Pokazuj podpowiedzi wyszukiwania Musisz wybrać coś z listy Czy jesteś pewnie że chcesz usunąć {0}? - + Tytuł Aktywne diff --git a/Plugins/Wox.Plugin.WebSearch/Languages/zh-cn.xaml b/Plugins/Wox.Plugin.WebSearch/Languages/zh-cn.xaml index 880048136..d580fb0f5 100644 --- a/Plugins/Wox.Plugin.WebSearch/Languages/zh-cn.xaml +++ b/Plugins/Wox.Plugin.WebSearch/Languages/zh-cn.xaml @@ -5,6 +5,7 @@ 删除 编辑 添加 + 确认 触发关键字 URL 搜索 diff --git a/Plugins/Wox.Plugin.WebSearch/Languages/zh-tw.xaml b/Plugins/Wox.Plugin.WebSearch/Languages/zh-tw.xaml index 9e665167c..b0882d487 100644 --- a/Plugins/Wox.Plugin.WebSearch/Languages/zh-tw.xaml +++ b/Plugins/Wox.Plugin.WebSearch/Languages/zh-tw.xaml @@ -5,6 +5,7 @@ 刪除 編輯 添加 + 确认 觸發關鍵字 URL 搜索 @@ -28,5 +29,5 @@ 網頁搜索 提供網頁搜索能力 - + \ No newline at end of file diff --git a/Plugins/Wox.Plugin.WebSearch/Main.cs b/Plugins/Wox.Plugin.WebSearch/Main.cs index e06b28dfd..a34f0a455 100644 --- a/Plugins/Wox.Plugin.WebSearch/Main.cs +++ b/Plugins/Wox.Plugin.WebSearch/Main.cs @@ -6,28 +6,26 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using System.Windows.Controls; -using JetBrains.Annotations; using Wox.Infrastructure; using Wox.Infrastructure.Storage; -using Wox.Plugin.WebSearch.SuggestionSources; namespace Wox.Plugin.WebSearch { - public class Main : IPlugin, ISettingProvider, IPluginI18n, IMultipleActionKeywords, ISavable, IResultUpdated + public class Main : IPlugin, ISettingProvider, IPluginI18n, ISavable, IResultUpdated { - public PluginInitContext Context { get; private set; } + private PluginInitContext _context; - private PluginJsonStorage _storage; - private Settings _settings; + private readonly Settings _settings; + private readonly SettingsViewModel _viewModel; private CancellationTokenSource _updateSource; private CancellationToken _updateToken; public const string Images = "Images"; - public static string ImagesDirectory; + public static readonly string ImagesDirectory; public void Save() { - _storage.Save(); + _viewModel.Save(); } public List Query(Query query) @@ -36,23 +34,23 @@ namespace Wox.Plugin.WebSearch _updateSource = new CancellationTokenSource(); _updateToken = _updateSource.Token; - WebSearch webSearch = - _settings.WebSearches.FirstOrDefault(o => o.ActionKeyword == query.ActionKeyword && o.Enabled); + SearchSource searchSource = + _settings.SearchSources.FirstOrDefault(o => o.ActionKeyword == query.ActionKeyword && o.Enabled); - if (webSearch != null) + if (searchSource != null) { string keyword = query.Search; string title = keyword; - string subtitle = Context.API.GetTranslation("wox_plugin_websearch_search") + " " + webSearch.Title; + string subtitle = _context.API.GetTranslation("wox_plugin_websearch_search") + " " + searchSource.Title; if (string.IsNullOrEmpty(keyword)) { var result = new Result { Title = subtitle, SubTitle = string.Empty, - IcoPath = webSearch.IconPath + IcoPath = searchSource.IconPath }; - return new List { result }; + return new List {result}; } else { @@ -62,15 +60,15 @@ namespace Wox.Plugin.WebSearch Title = title, SubTitle = subtitle, Score = 6, - IcoPath = webSearch.IconPath, + IcoPath = searchSource.IconPath, Action = c => { - Process.Start(webSearch.Url.Replace("{q}", Uri.EscapeDataString(keyword))); + Process.Start(searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword))); return true; } }; results.Add(result); - UpdateResultsFromSuggestion(results, keyword, subtitle, webSearch, query); + UpdateResultsFromSuggestion(results, keyword, subtitle, searchSource, query); return results; } } @@ -80,14 +78,15 @@ namespace Wox.Plugin.WebSearch } } - private void UpdateResultsFromSuggestion(List results, string keyword, string subtitle, WebSearch webSearch, Query query) + private void UpdateResultsFromSuggestion(List results, string keyword, string subtitle, + SearchSource searchSource, Query query) { - if (_settings.EnableWebSearchSuggestion) + if (_settings.EnableSuggestion) { const int waittime = 300; var task = Task.Run(async () => { - var suggestions = await Suggestions(keyword, subtitle, webSearch); + var suggestions = await Suggestions(keyword, subtitle, searchSource); results.AddRange(suggestions); }, _updateToken); @@ -102,21 +101,21 @@ namespace Wox.Plugin.WebSearch } } - private async Task> Suggestions(string keyword, string subtitle, WebSearch webSearch) + private async Task> Suggestions(string keyword, string subtitle, SearchSource searchSource) { - var source = SuggestionSource.GetSuggestionSource(_settings.WebSearchSuggestionSource, Context); + var source = _settings.SelectedSuggestion; if (source != null) { - var suggestions = await source.GetSuggestions(keyword); + var suggestions = await source.Suggestions(keyword); var resultsFromSuggestion = suggestions.Select(o => new Result { Title = o, SubTitle = subtitle, Score = 5, - IcoPath = webSearch.IconPath, + IcoPath = searchSource.IconPath, Action = c => { - Process.Start(webSearch.Url.Replace("{q}", Uri.EscapeDataString(o))); + Process.Start(searchSource.Url.Replace("{q}", Uri.EscapeDataString(o))); return true; } }); @@ -127,18 +126,21 @@ namespace Wox.Plugin.WebSearch static Main() { - var plugins = Infrastructure.Constant.Plugins; - var assemblyName = typeof(Main).Assembly.GetName().Name; - var pluginDirectory = Path.Combine(Infrastructure.Constant.SettingsPath, plugins, assemblyName); + var plugins = Constant.Plugins; + var assemblyName = typeof (Main).Assembly.GetName().Name; + var pluginDirectory = Path.Combine(Constant.SettingsPath, plugins, assemblyName); ImagesDirectory = Path.Combine(pluginDirectory, Images); } + public Main() + { + _viewModel = new SettingsViewModel(); + _settings = _viewModel.Settings; + } + public void Init(PluginInitContext context) { - Context = context; - - _storage = new PluginJsonStorage(); - _settings = _storage.Load(); + _context = context; var pluginDirectory = context.CurrentPluginMetadata.PluginDirectory; var bundledImagesDirectory = Path.Combine(pluginDirectory, Images); @@ -149,43 +151,21 @@ namespace Wox.Plugin.WebSearch public Control CreateSettingPanel() { - return new WebSearchesSetting(this, _settings); + return new SettingsControl(_context, _viewModel); } #endregion public string GetTranslatedPluginTitle() { - return Context.API.GetTranslation("wox_plugin_websearch_plugin_name"); + return _context.API.GetTranslation("wox_plugin_websearch_plugin_name"); } public string GetTranslatedPluginDescription() { - return Context.API.GetTranslation("wox_plugin_websearch_plugin_description"); + return _context.API.GetTranslation("wox_plugin_websearch_plugin_description"); } - public bool IsInstantQuery(string query) => false; - - [NotifyPropertyChangedInvocator] - public void NotifyActionKeywordsUpdated(string oldActionKeywords, string newActionKeywords) - { - ActionKeywordsChanged?.Invoke(this, new ActionKeywordsChangedEventArgs - { - OldActionKeyword = oldActionKeywords, - NewActionKeyword = newActionKeywords - }); - } - - [NotifyPropertyChangedInvocator] - public void NotifyActionKeywordsAdded(string newActionKeywords) - { - ActionKeywordsChanged?.Invoke(this, new ActionKeywordsChangedEventArgs - { - NewActionKeyword = newActionKeywords - }); - } - - public event ActionKeywordsChangedEventHandler ActionKeywordsChanged; public event ResultUpdatedEventHandler ResultsUpdated; } -} +} \ No newline at end of file diff --git a/Plugins/Wox.Plugin.WebSearch/SearchSource.cs b/Plugins/Wox.Plugin.WebSearch/SearchSource.cs new file mode 100644 index 000000000..7857c487d --- /dev/null +++ b/Plugins/Wox.Plugin.WebSearch/SearchSource.cs @@ -0,0 +1,44 @@ +using System.IO; +using System.Windows.Media; +using JetBrains.Annotations; +using Newtonsoft.Json; +using Wox.Infrastructure.Image; + +namespace Wox.Plugin.WebSearch +{ + public class SearchSource : BaseModel + { + public const string DefaultIcon = "web_search.png"; + public string Title { get; set; } + public string ActionKeyword { get; set; } + + [NotNull] + public string Icon { private get; set; } = DefaultIcon; + + /// + /// All icon should be put under Images directory + /// + [NotNull] + [JsonIgnore] + internal string IconPath => Path.Combine(Main.ImagesDirectory, Icon); + + [JsonIgnore] + public ImageSource Image => ImageLoader.Load(IconPath); + + public string Url { get; set; } + public bool Enabled { get; set; } + + public SearchSource DeepCopy() + { + var webSearch = new SearchSource + { + Title = string.Copy(Title), + ActionKeyword = string.Copy(ActionKeyword), + Url = string.Copy(Url), + Icon = string.Copy(Icon), + Enabled = Enabled + }; + return webSearch; + } + } +} \ No newline at end of file diff --git a/Plugins/Wox.Plugin.WebSearch/SearchSourceSetting.xaml b/Plugins/Wox.Plugin.WebSearch/SearchSourceSetting.xaml new file mode 100644 index 000000000..5a1e5bce5 --- /dev/null +++ b/Plugins/Wox.Plugin.WebSearch/SearchSourceSetting.xaml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - -