This commit is contained in:
bao-qian
2016-06-16 02:59:31 +01:00
parent 3f3a34f788
commit ec5716c436
2 changed files with 15 additions and 18 deletions

View File

@@ -11,8 +11,8 @@ namespace Wox.Plugin.Folder
{ {
public class Main : IPlugin, ISettingProvider, IPluginI18n, ISavable public class Main : IPlugin, ISettingProvider, IPluginI18n, ISavable
{ {
private static List<string> driverNames; private static List<string> _driverNames;
private PluginInitContext context; private PluginInitContext _context;
private readonly Settings _settings; private readonly Settings _settings;
private readonly PluginJsonStorage<Settings> _storage; private readonly PluginJsonStorage<Settings> _storage;
@@ -21,6 +21,7 @@ namespace Wox.Plugin.Folder
{ {
_storage = new PluginJsonStorage<Settings>(); _storage = new PluginJsonStorage<Settings>();
_settings = _storage.Load(); _settings = _storage.Load();
InitialDriverList();
} }
public void Save() public void Save()
@@ -30,17 +31,13 @@ namespace Wox.Plugin.Folder
public Control CreateSettingPanel() public Control CreateSettingPanel()
{ {
return new FileSystemSettings(context.API, _settings); return new FileSystemSettings(_context.API, _settings);
} }
public void Init(PluginInitContext context) public void Init(PluginInitContext context)
{ {
this.context = context; _context = context;
InitialDriverList();
if (_settings.FolderLinks == null)
{
_settings.FolderLinks = new List<FolderLink>();
}
} }
public List<Result> Query(Query query) public List<Result> Query(Query query)
@@ -71,13 +68,13 @@ namespace Wox.Plugin.Folder
return false; return false;
} }
} }
context.API.ChangeQuery($"{query.ActionKeyword} {item.Path}{(item.Path.EndsWith("\\") ? "" : "\\")}"); _context.API.ChangeQuery($"{query.ActionKeyword} {item.Path}{(item.Path.EndsWith("\\") ? "" : "\\")}");
return false; return false;
}, },
ContextData = item, ContextData = item,
}).ToList(); }).ToList();
if (driverNames != null && !driverNames.Any(search.StartsWith)) if (_driverNames != null && !_driverNames.Any(search.StartsWith))
return results; return results;
//if (!input.EndsWith("\\")) //if (!input.EndsWith("\\"))
@@ -97,13 +94,13 @@ namespace Wox.Plugin.Folder
} }
private void InitialDriverList() private void InitialDriverList()
{ {
if (driverNames == null) if (_driverNames == null)
{ {
driverNames = new List<string>(); _driverNames = new List<string>();
DriveInfo[] allDrives = DriveInfo.GetDrives(); DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo driver in allDrives) foreach (DriveInfo driver in allDrives)
{ {
driverNames.Add(driver.Name.ToLower().TrimEnd('\\')); _driverNames.Add(driver.Name.ToLower().TrimEnd('\\'));
} }
} }
} }
@@ -180,7 +177,7 @@ namespace Wox.Plugin.Folder
return false; return false;
} }
} }
context.API.ChangeQuery($"{query.ActionKeyword} {dirCopy.FullName}\\"); _context.API.ChangeQuery($"{query.ActionKeyword} {dirCopy.FullName}\\");
return false; return false;
} }
}; };
@@ -223,12 +220,12 @@ namespace Wox.Plugin.Folder
public string GetTranslatedPluginTitle() public string GetTranslatedPluginTitle()
{ {
return context.API.GetTranslation("wox_plugin_folder_plugin_name"); return _context.API.GetTranslation("wox_plugin_folder_plugin_name");
} }
public string GetTranslatedPluginDescription() public string GetTranslatedPluginDescription()
{ {
return context.API.GetTranslation("wox_plugin_folder_plugin_description"); return _context.API.GetTranslation("wox_plugin_folder_plugin_description");
} }
} }
} }

View File

@@ -7,6 +7,6 @@ namespace Wox.Plugin.Folder
public class Settings public class Settings
{ {
[JsonProperty] [JsonProperty]
public List<FolderLink> FolderLinks { get; set; } public List<FolderLink> FolderLinks { get; set; } = new List<FolderLink>();
} }
} }