mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-18 22:43:31 +08:00
Merge pull request #59 from cxfksword/master
Add Everything support show file icon
This commit is contained in:
commit
10cbe25f17
@ -171,7 +171,7 @@ namespace Wox.Plugin.Everything
|
||||
/// </summary>
|
||||
/// <param name="keyWord">The key word.</param>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<string> Search(string keyWord)
|
||||
public IEnumerable<SearchResult> Search(string keyWord)
|
||||
{
|
||||
return Search(keyWord, 0, int.MaxValue);
|
||||
}
|
||||
@ -204,7 +204,7 @@ namespace Wox.Plugin.Everything
|
||||
/// <param name="offset">The offset.</param>
|
||||
/// <param name="maxCount">The max count.</param>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<string> Search(string keyWord, int offset, int maxCount)
|
||||
public IEnumerable<SearchResult> Search(string keyWord, int offset, int maxCount)
|
||||
{
|
||||
if (string.IsNullOrEmpty(keyWord))
|
||||
throw new ArgumentNullException("keyWord");
|
||||
@ -254,12 +254,31 @@ namespace Wox.Plugin.Everything
|
||||
for (int idx = 0; idx < Everything_GetNumResults(); ++idx)
|
||||
{
|
||||
Everything_GetResultFullPathName(idx, buffer, bufferSize);
|
||||
yield return buffer.ToString();
|
||||
|
||||
var result = new SearchResult() { FullPath = buffer.ToString() };
|
||||
if (Everything_IsFolderResult(idx))
|
||||
result.Type = ResultType.Folder;
|
||||
else if (Everything_IsFileResult(idx))
|
||||
result.Type = ResultType.File;
|
||||
|
||||
yield return result;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
public enum ResultType
|
||||
{
|
||||
Volume,
|
||||
Folder,
|
||||
File
|
||||
}
|
||||
|
||||
public class SearchResult
|
||||
{
|
||||
public string FullPath { get; set; }
|
||||
public ResultType Type { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
|
BIN
Plugins/Wox.Plugin.Everything/Images/folder.png
Normal file
BIN
Plugins/Wox.Plugin.Everything/Images/folder.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.2 KiB |
BIN
Plugins/Wox.Plugin.Everything/Images/image.png
Normal file
BIN
Plugins/Wox.Plugin.Everything/Images/image.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.4 KiB |
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Wox.Plugin.Everything
|
||||
{
|
||||
@ -10,6 +11,7 @@ namespace Wox.Plugin.Everything
|
||||
{
|
||||
Wox.Plugin.PluginInitContext context;
|
||||
EverythingAPI api = new EverythingAPI();
|
||||
private static List<string> imageExts = new List<string>() { ".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tiff" };
|
||||
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
@ -17,13 +19,14 @@ namespace Wox.Plugin.Everything
|
||||
if (query.ActionParameters.Count > 0 && query.ActionParameters[0].Length > 0)
|
||||
{
|
||||
var keyword = string.Join(" ", query.ActionParameters.ToArray());
|
||||
IEnumerable<string> enumerable = api.Search(keyword, 0, 100);
|
||||
foreach (string s in enumerable)
|
||||
var enumerable = api.Search(keyword, 0, 100);
|
||||
foreach (var s in enumerable)
|
||||
{
|
||||
var path = s;
|
||||
var path = s.FullPath;
|
||||
Result r = new Result();
|
||||
r.Title = Path.GetFileName(path);
|
||||
r.SubTitle = path;
|
||||
r.IcoPath = GetIconPath(s);
|
||||
r.Action = (c) =>
|
||||
{
|
||||
context.HideApp();
|
||||
@ -49,6 +52,22 @@ namespace Wox.Plugin.Everything
|
||||
return results;
|
||||
}
|
||||
|
||||
private string GetIconPath(SearchResult s)
|
||||
{
|
||||
if (s.Type == ResultType.Folder)
|
||||
{
|
||||
return "Images\\folder.png";
|
||||
}
|
||||
else
|
||||
{
|
||||
var ext = Path.GetExtension(s.FullPath);
|
||||
if (!string.IsNullOrEmpty(ext) && imageExts.Contains(ext.ToLower()))
|
||||
return "Images\\image.png";
|
||||
else
|
||||
return s.FullPath;
|
||||
}
|
||||
}
|
||||
|
||||
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
|
||||
private static extern int LoadLibrary(string name);
|
||||
|
||||
|
@ -53,6 +53,12 @@
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Images\folder.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Images\image.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="x64\Everything.dll">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
@ -65,6 +71,7 @@
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>
|
||||
|
@ -14,6 +14,7 @@ namespace Wox
|
||||
public class ImagePathConverter : IMultiValueConverter
|
||||
{
|
||||
private static Dictionary<string, object> imageCache = new Dictionary<string, object>();
|
||||
private static List<string> imageExts = new List<string>() { ".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tiff" };
|
||||
|
||||
private static ImageSource GetIcon(string fileName)
|
||||
{
|
||||
@ -36,10 +37,15 @@ namespace Wox
|
||||
string path = values[0].ToString();
|
||||
string pluginDirectory = values[1].ToString();
|
||||
string fullPath = Path.Combine(pluginDirectory, path);
|
||||
string ext = Path.GetExtension(path).ToLower();
|
||||
if (imageCache.ContainsKey(fullPath))
|
||||
{
|
||||
return imageCache[fullPath];
|
||||
}
|
||||
if (imageCache.ContainsKey(ext))
|
||||
{
|
||||
return imageCache[ext];
|
||||
}
|
||||
|
||||
string resolvedPath = string.Empty;
|
||||
if (!string.IsNullOrEmpty(path) && path.Contains(":\\") && File.Exists(path))
|
||||
@ -51,18 +57,24 @@ namespace Wox
|
||||
resolvedPath = fullPath;
|
||||
}
|
||||
|
||||
var cacheKey = fullPath;
|
||||
if (resolvedPath.ToLower().EndsWith(".exe") || resolvedPath.ToLower().EndsWith(".lnk"))
|
||||
{
|
||||
img = GetIcon(resolvedPath);
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(resolvedPath) && File.Exists(resolvedPath))
|
||||
else if (!string.IsNullOrEmpty(resolvedPath) && imageExts.Contains(ext) && File.Exists(resolvedPath))
|
||||
{
|
||||
img = new BitmapImage(new Uri(resolvedPath));
|
||||
}
|
||||
else
|
||||
{
|
||||
img = GetIcon(resolvedPath);
|
||||
cacheKey = ext;
|
||||
}
|
||||
|
||||
if (img != null)
|
||||
{
|
||||
imageCache.Add(fullPath, img);
|
||||
imageCache.Add(cacheKey, img);
|
||||
}
|
||||
|
||||
return img;
|
||||
|
Loading…
Reference in New Issue
Block a user