Use variable instead of global static method

1. introduce variable
2. part of #389
3. refactoring program suffix in program plugin
4. 全局变量一时爽,代码重构火葬场
This commit is contained in:
bao-qian
2016-03-28 03:09:57 +01:00
parent c596039453
commit b22a4501cc
36 changed files with 402 additions and 343 deletions

View File

@@ -10,13 +10,14 @@ namespace Wox.Plugin.WebSearch
{
public class WebSearchPlugin : IPlugin, ISettingProvider, IPluginI18n, IInstantQuery, IMultipleActionKeywords
{
private WebSearchStorage _settings = WebSearchStorage.Instance;
public PluginInitContext Context { get; private set; }
public List<Result> Query(Query query)
{
List<Result> results = new List<Result>();
WebSearch webSearch =
WebSearchStorage.Instance.WebSearches.FirstOrDefault(o => o.ActionKeyword == query.ActionKeyword && o.Enabled);
_settings.WebSearches.FirstOrDefault(o => o.ActionKeyword == query.ActionKeyword && o.Enabled);
if (webSearch != null)
{
@@ -42,7 +43,7 @@ namespace Wox.Plugin.WebSearch
};
results.Add(result);
if (WebSearchStorage.Instance.EnableWebSearchSuggestion && !string.IsNullOrEmpty(keyword))
if (_settings.EnableWebSearchSuggestion && !string.IsNullOrEmpty(keyword))
{
// todo use Task.Wait when .net upgraded
results.AddRange(ResultsFromSuggestions(keyword, subtitle, webSearch));
@@ -53,7 +54,7 @@ namespace Wox.Plugin.WebSearch
private IEnumerable<Result> ResultsFromSuggestions(string keyword, string subtitle, WebSearch webSearch)
{
ISuggestionSource sugg = SuggestionSourceFactory.GetSuggestionSource(WebSearchStorage.Instance.WebSearchSuggestionSource, Context);
ISuggestionSource sugg = SuggestionSourceFactory.GetSuggestionSource(_settings.WebSearchSuggestionSource, Context);
var suggestions = sugg?.GetSuggestions(keyword);
if (suggestions != null)
{
@@ -83,7 +84,7 @@ namespace Wox.Plugin.WebSearch
public Control CreateSettingPanel()
{
return new WebSearchesSetting(this);
return new WebSearchesSetting(this, _settings);
}
#endregion