Consolidate folder and shell plugin (#5843)

* Added folder plugin functionality to shell plugin

* Added QueryTextDisplay for shell plugin

* Remove QueryTextDisplay change

* Fix merge conflict issues
This commit is contained in:
Divyansh Srivastava
2020-08-10 15:51:02 -07:00
committed by GitHub
parent 082a78bd92
commit 3781d1e06b
3 changed files with 29 additions and 53 deletions

View File

@@ -27,20 +27,14 @@ namespace Microsoft.Plugin.Folder
private const string _fileExplorerProgramName = "explorer";
private readonly FolderSettings _settings;
private readonly PluginJsonStorage<FolderSettings> _storage;
private static readonly PluginJsonStorage<FolderSettings> _storage = new PluginJsonStorage<FolderSettings>();
private static readonly FolderSettings _settings = _storage.Load();
private static List<string> _driverNames;
private PluginInitContext _context;
private IContextMenu _contextMenuLoader;
public Main()
{
_storage = new PluginJsonStorage<FolderSettings>();
_settings = _storage.Load();
}
public void Save()
{
_storage.Save();
@@ -66,15 +60,7 @@ namespace Microsoft.Plugin.Folder
throw new ArgumentNullException(paramName: nameof(query));
}
var results = GetUserFolderResults(query);
string search = query.Search.ToLower(CultureInfo.InvariantCulture);
if (!IsDriveOrSharedFolder(search))
{
return results;
}
results.AddRange(QueryInternal_Directory_Exists(query));
var results = GetFolderPluginResults(query);
// todo why was this hack here?
foreach (var result in results)
@@ -85,8 +71,28 @@ namespace Microsoft.Plugin.Folder
return results;
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1308:Normalize strings to uppercase", Justification = "Do not want to change the behavior of the application, but want to enforce static analysis")]
public static List<Result> GetFolderPluginResults(Query query)
{
var results = GetUserFolderResults(query);
string search = query.Search.ToLower(CultureInfo.InvariantCulture);
if (!IsDriveOrSharedFolder(search))
{
return results;
}
results.AddRange(QueryInternalDirectoryExists(query));
return results;
}
private static bool IsDriveOrSharedFolder(string search)
{
if (search == null)
{
throw new ArgumentNullException(nameof(search));
}
if (search.StartsWith(@"\\", StringComparison.InvariantCulture))
{ // share folder
return true;
@@ -124,7 +130,7 @@ namespace Microsoft.Plugin.Folder
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1308:Normalize strings to uppercase", Justification = "Do not want to change the behavior of the application, but want to enforce static analysis")]
private List<Result> GetUserFolderResults(Query query)
private static List<Result> GetUserFolderResults(Query query)
{
if (query == null)
{
@@ -159,7 +165,7 @@ namespace Microsoft.Plugin.Folder
};
[System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1308:Normalize strings to uppercase", Justification = "Do not want to change the behavior of the application, but want to enforce static analysis")]
private static List<Result> QueryInternal_Directory_Exists(Query query)
private static List<Result> QueryInternalDirectoryExists(Query query)
{
var search = query.Search;
var results = new List<Result>();

View File

@@ -6,6 +6,7 @@ using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
@@ -56,40 +57,8 @@ namespace Microsoft.Plugin.Shell
try
{
string basedir = null;
string dir = null;
string excmd = Environment.ExpandEnvironmentVariables(cmd);
if (Directory.Exists(excmd) && (cmd.EndsWith("/") || cmd.EndsWith(@"\")))
{
basedir = excmd;
dir = cmd;
}
else if (Directory.Exists(Path.GetDirectoryName(excmd) ?? string.Empty))
{
basedir = Path.GetDirectoryName(excmd);
var dirn = Path.GetDirectoryName(cmd);
dir = (dirn.EndsWith("/") || dirn.EndsWith(@"\")) ? dirn : cmd.Substring(0, dirn.Length + 1);
}
if (basedir != null)
{
var autocomplete = Directory.GetFileSystemEntries(basedir).
Select(o => dir + Path.GetFileName(o)).
Where(o => o.StartsWith(cmd, StringComparison.OrdinalIgnoreCase) &&
!results.Any(p => o.Equals(p.Title, StringComparison.OrdinalIgnoreCase)) &&
!results.Any(p => o.Equals(p.Title, StringComparison.OrdinalIgnoreCase))).ToList();
autocomplete.Sort();
results.AddRange(autocomplete.ConvertAll(m => new Result
{
Title = m,
IcoPath = IconPath,
Action = c =>
{
Execute(Process.Start, PrepareProcessStartInfo(m));
return true;
},
}));
}
List<Result> folderPluginResults = Folder.Main.GetFolderPluginResults(query);
results.AddRange(folderPluginResults);
}
catch (Exception e)
{

View File

@@ -63,6 +63,7 @@
<ItemGroup>
<ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj" />
<ProjectReference Include="..\..\Wox.Plugin\Wox.Plugin.csproj" />
<ProjectReference Include="..\Microsoft.Plugin.Folder\Microsoft.Plugin.Folder.csproj" />
</ItemGroup>
<ItemGroup>