mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 11:46:30 +02:00
Remove instance logic for BinaryStorage and JsonStorage, part 1
1. part of #389 2. huge refactoring
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
[Serializable]
|
||||
public class WebSearch
|
||||
{
|
||||
public string Title { get; set; }
|
||||
|
||||
@@ -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>();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user