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

@@ -4,7 +4,7 @@ using Newtonsoft.Json;
namespace Wox.Plugin.Folder
{
[Serializable]
[JsonObject(MemberSerialization.OptIn)]
public class FolderLink
{
[JsonProperty]

View File

@@ -5,6 +5,7 @@ using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using Wox.Infrastructure.Storage;
namespace Wox.Plugin.Folder
{
@@ -12,7 +13,20 @@ namespace Wox.Plugin.Folder
{
private static List<string> driverNames;
private PluginInitContext context;
private FolderStorage _settings = FolderStorage.Instance;
private readonly Settings _settings;
private readonly PluginSettingsStorage<Settings> _storage;
public FolderPlugin()
{
_storage = new PluginSettingsStorage<Settings>();
_settings = _storage.Load();
}
~FolderPlugin()
{
_storage.Save();
}
public Control CreateSettingPanel()
{
@@ -26,7 +40,6 @@ namespace Wox.Plugin.Folder
if (_settings.FolderLinks == null)
{
_settings.FolderLinks = new List<FolderLink>();
_settings.Save();
}
}

View File

@@ -14,9 +14,9 @@ namespace Wox.Plugin.Folder
public partial class FileSystemSettings
{
private IPublicAPI woxAPI;
private FolderStorage _settings;
private Settings _settings;
public FileSystemSettings(IPublicAPI woxAPI, FolderStorage settings)
public FileSystemSettings(IPublicAPI woxAPI, Settings settings)
{
this.woxAPI = woxAPI;
InitializeComponent();
@@ -35,7 +35,6 @@ namespace Wox.Plugin.Folder
{
_settings.FolderLinks.Remove(selectedFolder);
lbxFolders.Items.Refresh();
_settings.Save();
}
}
else
@@ -56,8 +55,6 @@ namespace Wox.Plugin.Folder
{
var link = _settings.FolderLinks.First(x => x.Path == selectedFolder.Path);
link.Path = folderBrowserDialog.SelectedPath;
_settings.Save();
}
lbxFolders.Items.Refresh();
@@ -85,7 +82,6 @@ namespace Wox.Plugin.Folder
}
_settings.FolderLinks.Add(newFolder);
_settings.Save();
}
lbxFolders.Items.Refresh();
@@ -112,7 +108,6 @@ namespace Wox.Plugin.Folder
};
_settings.FolderLinks.Add(newFolder);
_settings.Save();
}
lbxFolders.Items.Refresh();

View File

@@ -4,11 +4,10 @@ using Wox.Infrastructure.Storage;
namespace Wox.Plugin.Folder
{
public class FolderStorage : JsonStrorage<FolderStorage>
public class Settings
{
[JsonProperty]
public List<FolderLink> FolderLinks { get; set; }
protected override string FileName { get; } = "settings_folder_plugin";
}
}