Made Plugin Folder Unit tests & Expanding enviroment search (#6600)

* Made Plugin Folder Unit tests. Fixes '>' not recursive searching (with max). Added that paths with an UnauthorizedAccessException are ignored. Added expanding enviroment search.

* Fixed some merging errors

* Added feedback from review

* Made the change that  ryanbodrug-microsoft suggested

* Stupid merge request... fixed

Co-authored-by: p-storm <paul.de.man@gmail.com>
This commit is contained in:
P-Storm
2020-10-01 05:37:46 +02:00
committed by GitHub
parent b2c00b1e1a
commit 5c84de5400
31 changed files with 1264 additions and 296 deletions

View File

@@ -0,0 +1,39 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Wox.Plugin;
namespace Microsoft.Plugin.Folder.Sources.Result
{
public class CreateOpenCurrentFolderResult : IItemResult
{
private readonly IExplorerAction _explorerAction;
public string Search { get; set; }
public CreateOpenCurrentFolderResult(string search)
: this(search, new ExplorerAction())
{
}
public CreateOpenCurrentFolderResult(string search, IExplorerAction explorerAction)
{
Search = search;
_explorerAction = explorerAction;
}
public Wox.Plugin.Result Create(IPublicAPI contextApi)
{
return new Wox.Plugin.Result
{
Title = $"Open {Search}",
QueryTextDisplay = Search,
SubTitle = $"Folder: Use > to search within the directory. Use * to search for file extensions. Or use both >*.",
IcoPath = Search,
Score = 500,
Action = c => _explorerAction.ExecuteSanitized(Search, contextApi),
};
}
}
}

View File

@@ -0,0 +1,35 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.IO;
using Wox.Infrastructure;
using Wox.Plugin;
namespace Microsoft.Plugin.Folder.Sources.Result
{
public class FileItemResult : IItemResult
{
private static readonly IExplorerAction ExplorerAction = new ExplorerAction();
public string FilePath { get; set; }
public string Title => Path.GetFileName(FilePath);
public string Search { get; set; }
public Wox.Plugin.Result Create(IPublicAPI contextApi)
{
var result = new Wox.Plugin.Result
{
Title = Title,
SubTitle = "Folder: " + FilePath,
IcoPath = FilePath,
TitleHighlightData = StringMatcher.FuzzySearch(Search, Path.GetFileName(FilePath)).MatchData,
Action = c => ExplorerAction.Execute(FilePath, contextApi),
ContextData = new SearchResult { Type = ResultType.File, FullPath = FilePath },
};
return result;
}
}
}

View File

@@ -0,0 +1,36 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
namespace Microsoft.Plugin.Folder.Sources.Result
{
public class FileSystemResult : List<DisplayFileInfo>
{
public FileSystemResult()
{
}
public FileSystemResult([NotNull] IEnumerable<DisplayFileInfo> collection)
: base(collection)
{
}
public FileSystemResult(int capacity)
: base(capacity)
{
}
public static FileSystemResult Error(Exception exception)
{
return new FileSystemResult { Exception = exception };
}
public Exception Exception { get; private set; }
public bool HasException() => Exception != null;
}
}

View File

@@ -0,0 +1,47 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Wox.Infrastructure;
using Wox.Plugin;
namespace Microsoft.Plugin.Folder.Sources.Result
{
public class FolderItemResult : IItemResult
{
private static readonly IExplorerAction ExplorerAction = new ExplorerAction();
public FolderItemResult()
{
}
public FolderItemResult(DisplayFileInfo fileSystemInfo)
{
Title = fileSystemInfo.Name;
Subtitle = fileSystemInfo.FullName;
Path = fileSystemInfo.FullName;
}
public string Title { get; set; }
public string Subtitle { get; set; }
public string Path { get; set; }
public string Search { get; set; }
public Wox.Plugin.Result Create(IPublicAPI contextApi)
{
return new Wox.Plugin.Result
{
Title = Title,
IcoPath = Path,
SubTitle = "Folder: " + Subtitle,
QueryTextDisplay = Path,
TitleHighlightData = StringMatcher.FuzzySearch(Search, Title).MatchData,
ContextData = new SearchResult { Type = ResultType.Folder, FullPath = Path },
Action = c => ExplorerAction.Execute(Path, contextApi),
};
}
}
}

View File

@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Wox.Plugin;
namespace Microsoft.Plugin.Folder.Sources.Result
{
public interface IItemResult
{
string Search { get; set; }
Wox.Plugin.Result Create(IPublicAPI contextApi);
}
}

View File

@@ -0,0 +1,31 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Globalization;
using Wox.Plugin;
namespace Microsoft.Plugin.Folder.Sources.Result
{
public class TruncatedItemResult : IItemResult
{
public int PreTruncationCount { get; set; }
public int PostTruncationCount { get; set; }
public string WarningIconPath { get; set; }
public string Search { get; set; }
public Wox.Plugin.Result Create(IPublicAPI contextApi)
{
return new Wox.Plugin.Result
{
Title = Properties.Resources.Microsoft_plugin_folder_truncation_warning_title,
QueryTextDisplay = Search,
SubTitle = string.Format(CultureInfo.InvariantCulture, Properties.Resources.Microsoft_plugin_folder_truncation_warning_subtitle, PostTruncationCount, PreTruncationCount),
IcoPath = WarningIconPath,
};
}
}
}