mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 19:57:07 +02:00
Remove instance logic for BinaryStorage and JsonStorage, part 1
1. part of #389 2. huge refactoring
This commit is contained in:
@@ -4,7 +4,7 @@ using Newtonsoft.Json;
|
||||
|
||||
namespace Wox.Plugin.Folder
|
||||
{
|
||||
[Serializable]
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class FolderLink
|
||||
{
|
||||
[JsonProperty]
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user