mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 12:46:47 +02:00
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:
committed by
GitHub
parent
082a78bd92
commit
3781d1e06b
@@ -27,20 +27,14 @@ namespace Microsoft.Plugin.Folder
|
|||||||
|
|
||||||
private const string _fileExplorerProgramName = "explorer";
|
private const string _fileExplorerProgramName = "explorer";
|
||||||
|
|
||||||
private readonly FolderSettings _settings;
|
private static readonly PluginJsonStorage<FolderSettings> _storage = new PluginJsonStorage<FolderSettings>();
|
||||||
private readonly PluginJsonStorage<FolderSettings> _storage;
|
private static readonly FolderSettings _settings = _storage.Load();
|
||||||
|
|
||||||
private static List<string> _driverNames;
|
private static List<string> _driverNames;
|
||||||
private PluginInitContext _context;
|
private PluginInitContext _context;
|
||||||
|
|
||||||
private IContextMenu _contextMenuLoader;
|
private IContextMenu _contextMenuLoader;
|
||||||
|
|
||||||
public Main()
|
|
||||||
{
|
|
||||||
_storage = new PluginJsonStorage<FolderSettings>();
|
|
||||||
_settings = _storage.Load();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Save()
|
public void Save()
|
||||||
{
|
{
|
||||||
_storage.Save();
|
_storage.Save();
|
||||||
@@ -66,15 +60,7 @@ namespace Microsoft.Plugin.Folder
|
|||||||
throw new ArgumentNullException(paramName: nameof(query));
|
throw new ArgumentNullException(paramName: nameof(query));
|
||||||
}
|
}
|
||||||
|
|
||||||
var results = GetUserFolderResults(query);
|
var results = GetFolderPluginResults(query);
|
||||||
|
|
||||||
string search = query.Search.ToLower(CultureInfo.InvariantCulture);
|
|
||||||
if (!IsDriveOrSharedFolder(search))
|
|
||||||
{
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
results.AddRange(QueryInternal_Directory_Exists(query));
|
|
||||||
|
|
||||||
// todo why was this hack here?
|
// todo why was this hack here?
|
||||||
foreach (var result in results)
|
foreach (var result in results)
|
||||||
@@ -85,8 +71,28 @@ namespace Microsoft.Plugin.Folder
|
|||||||
return results;
|
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)
|
private static bool IsDriveOrSharedFolder(string search)
|
||||||
{
|
{
|
||||||
|
if (search == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(search));
|
||||||
|
}
|
||||||
|
|
||||||
if (search.StartsWith(@"\\", StringComparison.InvariantCulture))
|
if (search.StartsWith(@"\\", StringComparison.InvariantCulture))
|
||||||
{ // share folder
|
{ // share folder
|
||||||
return true;
|
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")]
|
[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)
|
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")]
|
[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 search = query.Search;
|
||||||
var results = new List<Result>();
|
var results = new List<Result>();
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@@ -56,40 +57,8 @@ namespace Microsoft.Plugin.Shell
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string basedir = null;
|
List<Result> folderPluginResults = Folder.Main.GetFolderPluginResults(query);
|
||||||
string dir = null;
|
results.AddRange(folderPluginResults);
|
||||||
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;
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -63,6 +63,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj" />
|
<ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj" />
|
||||||
<ProjectReference Include="..\..\Wox.Plugin\Wox.Plugin.csproj" />
|
<ProjectReference Include="..\..\Wox.Plugin\Wox.Plugin.csproj" />
|
||||||
|
<ProjectReference Include="..\Microsoft.Plugin.Folder\Microsoft.Plugin.Folder.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user