Remove instance logic for BinaryStorage and JsonStorage, part 1

1. part of #389
2. huge refactoring
This commit is contained in:
bao-qian
2016-04-21 01:53:21 +01:00
parent 0bcb76fa81
commit 8d10c9aa41
52 changed files with 502 additions and 584 deletions

View File

@@ -2,7 +2,6 @@
namespace Wox.Plugin.WebSearch
{
[Serializable]
public class WebSearch
{
public string Title { get; set; }

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows.Controls;
using Wox.Infrastructure.Storage;
using Wox.Plugin.WebSearch.Annotations;
using Wox.Plugin.WebSearch.SuggestionSources;
@@ -10,9 +11,22 @@ namespace Wox.Plugin.WebSearch
{
public class WebSearchPlugin : IPlugin, ISettingProvider, IPluginI18n, IInstantQuery, IMultipleActionKeywords
{
private WebSearchStorage _settings = WebSearchStorage.Instance;
public PluginInitContext Context { get; private set; }
private readonly PluginSettingsStorage<Settings> _storage;
private readonly Settings _settings;
public WebSearchPlugin()
{
_storage = new PluginSettingsStorage<Settings>();
_settings = _storage.Load();
}
~WebSearchPlugin()
{
_storage.Save();
}
public List<Result> Query(Query query)
{
List<Result> results = new List<Result>();

View File

@@ -18,9 +18,9 @@ namespace Wox.Plugin.WebSearch
private WebSearch _updateWebSearch;
private readonly PluginInitContext _context;
private readonly WebSearchPlugin _plugin;
private WebSearchStorage _settings;
private Settings _settings;
public WebSearchSetting(WebSearchesSetting settingWidow, WebSearchStorage settings)
public WebSearchSetting(WebSearchesSetting settingWidow, Settings settings)
{
_plugin = settingWidow.Plugin;
_context = settingWidow.Context;
@@ -122,7 +122,6 @@ namespace Wox.Plugin.WebSearch
});
}
_settings.Save();
_settingWindow.ReloadWebSearchView();
Close();
}

View File

@@ -4,22 +4,9 @@ using Wox.Infrastructure.Storage;
namespace Wox.Plugin.WebSearch
{
public class WebSearchStorage : JsonStrorage<WebSearchStorage>
public class Settings
{
[JsonProperty]
public List<WebSearch> WebSearches { get; set; }
[JsonProperty]
public bool EnableWebSearchSuggestion { get; set; }
[JsonProperty]
public string WebSearchSuggestionSource { get; set; }
protected override string FileName { get; } = "settings_plugin_websearch";
protected override WebSearchStorage LoadDefault()
{
WebSearches = new List<WebSearch>(new List<WebSearch>()
public List<WebSearch> WebSearches { get; set; } = new List<WebSearch>
{
new WebSearch
{
@@ -173,9 +160,10 @@ namespace Wox.Plugin.WebSearch
Url = "http://www.search.yahoo.com/search?p={q}",
Enabled = true
}
});
};
return this;
}
public bool EnableWebSearchSuggestion { get; set; }
public string WebSearchSuggestionSource { get; set; }
}
}

View File

@@ -10,11 +10,11 @@ namespace Wox.Plugin.WebSearch
/// </summary>
public partial class WebSearchesSetting : UserControl
{
private WebSearchStorage _settings;
private Settings _settings;
public PluginInitContext Context { get; }
public WebSearchPlugin Plugin { get; }
public WebSearchesSetting(WebSearchPlugin plugin, WebSearchStorage settings)
public WebSearchesSetting(WebSearchPlugin plugin, Settings settings)
{
Context = plugin.Context;
Plugin = plugin;
@@ -97,14 +97,12 @@ namespace Wox.Plugin.WebSearch
{
comboBoxSuggestionSource.Visibility = Visibility.Visible;
_settings.EnableWebSearchSuggestion = true;
_settings.Save();
}
private void CbEnableWebSearchSuggestion_OnUnchecked(object sender, RoutedEventArgs e)
{
comboBoxSuggestionSource.Visibility = Visibility.Collapsed;
_settings.EnableWebSearchSuggestion = false;
_settings.Save();
}
private void ComboBoxSuggestionSource_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
@@ -112,7 +110,6 @@ namespace Wox.Plugin.WebSearch
if (e.AddedItems.Count > 0)
{
_settings.WebSearchSuggestionSource = ((ComboBoxItem)e.AddedItems[0]).Content.ToString();
_settings.Save();
}
}
}