From 37a4eefc4669dd8c6138fb47d05eeb828fb0fd83 Mon Sep 17 00:00:00 2001 From: AT <14300910+theClueless@users.noreply.github.com> Date: Mon, 9 Dec 2019 00:26:21 +0200 Subject: [PATCH 1/5] updated to use share folder --- Plugins/Wox.Plugin.Folder/Main.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Plugins/Wox.Plugin.Folder/Main.cs b/Plugins/Wox.Plugin.Folder/Main.cs index b5c122b10..f36029cb8 100644 --- a/Plugins/Wox.Plugin.Folder/Main.cs +++ b/Plugins/Wox.Plugin.Folder/Main.cs @@ -44,7 +44,7 @@ namespace Wox.Plugin.Folder var results = GetUserFolderResults(query); string search = query.Search.ToLower(); - if (_driverNames != null && !_driverNames.Any(search.StartsWith)) + if (!IsDriveOrSharedFolder(search)) return results; results.AddRange(QueryInternal_Directory_Exists(query)); @@ -58,6 +58,26 @@ namespace Wox.Plugin.Folder return results; } + private static bool IsDriveOrSharedFolder(string search) + { + if (search.StartsWith(@"\\")) + { + return true; + } + + if (_driverNames != null && _driverNames.Any(search.StartsWith)) + { + return true; + } + + if (_driverNames == null && search.Length > 2 && char.IsLetter(search[0]) && search[1] == ':') + { + return true; // we don't know so let's give it the possibility + } + + return false; + } + private Result CreateFolderResult(string title, string path) { return new Result From bcc9379ebc9087f6cd5ae75f143354dfbb766026 Mon Sep 17 00:00:00 2001 From: AT <14300910+theClueless@users.noreply.github.com> Date: Tue, 10 Dec 2019 12:18:24 +0200 Subject: [PATCH 2/5] typo in log --- Wox.Infrastructure/Logger/Log.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Wox.Infrastructure/Logger/Log.cs b/Wox.Infrastructure/Logger/Log.cs index dfa05c715..ff72dff1c 100644 --- a/Wox.Infrastructure/Logger/Log.cs +++ b/Wox.Infrastructure/Logger/Log.cs @@ -87,7 +87,7 @@ namespace Wox.Infrastructure.Logger do { - logger.Error($"Exception fulle name:\n <{e.GetType().FullName}>"); + logger.Error($"Exception full name:\n <{e.GetType().FullName}>"); logger.Error($"Exception message:\n <{e.Message}>"); logger.Error($"Exception stack trace:\n <{e.StackTrace}>"); logger.Error($"Exception source:\n <{e.Source}>"); From 3f3deb8e2afcd4660c0d79659abefc348370d100 Mon Sep 17 00:00:00 2001 From: AT <14300910+theClueless@users.noreply.github.com> Date: Tue, 10 Dec 2019 12:38:03 +0200 Subject: [PATCH 3/5] added share folder --- Plugins/Wox.Plugin.Folder/Main.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Plugins/Wox.Plugin.Folder/Main.cs b/Plugins/Wox.Plugin.Folder/Main.cs index 2c8cf2703..4f8fac60d 100644 --- a/Plugins/Wox.Plugin.Folder/Main.cs +++ b/Plugins/Wox.Plugin.Folder/Main.cs @@ -44,7 +44,7 @@ namespace Wox.Plugin.Folder var results = GetUserFolderResults(query); string search = query.Search.ToLower(); - if (_driverNames != null && !_driverNames.Any(search.StartsWith)) + if (!IsDriveOrSharedFolder(search)) return results; results.AddRange(QueryInternal_Directory_Exists(query)); @@ -58,6 +58,26 @@ namespace Wox.Plugin.Folder return results; } + private static bool IsDriveOrSharedFolder(string search) + { + if (search.StartsWith(@"\\")) + { // share folder + return true; + } + + if (_driverNames != null && _driverNames.Any(search.StartsWith)) + { // normal drive letter + return true; + } + + if (_driverNames == null && search.Length > 2 && char.IsLetter(search[0]) && search[1] == ':') + { // when we don't have the drive letters we can try... + return true; // we don't know so let's give it the possibility + } + + return false; + } + private Result CreateFolderResult(string title, string path, string queryActionKeyword) { return new Result From bec52b81fd3832fe5f3be14972ee1fbced2483da Mon Sep 17 00:00:00 2001 From: AT <14300910+theClueless@users.noreply.github.com> Date: Wed, 11 Dec 2019 02:21:50 +0200 Subject: [PATCH 4/5] adding conetxt menu start --- .../Wox.Plugin.Folder/ContextMenuLoader.cs | 113 ++++++++++++++++++ Plugins/Wox.Plugin.Folder/Main.cs | 14 ++- .../Wox.Plugin.Folder.csproj | 1 + 3 files changed, 125 insertions(+), 3 deletions(-) create mode 100644 Plugins/Wox.Plugin.Folder/ContextMenuLoader.cs diff --git a/Plugins/Wox.Plugin.Folder/ContextMenuLoader.cs b/Plugins/Wox.Plugin.Folder/ContextMenuLoader.cs new file mode 100644 index 000000000..e1a923b4e --- /dev/null +++ b/Plugins/Wox.Plugin.Folder/ContextMenuLoader.cs @@ -0,0 +1,113 @@ +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Windows; + +namespace Wox.Plugin.Folder +{ + internal class ContextMenuLoader : IContextMenu + { + private readonly PluginInitContext _context; + + public ContextMenuLoader(PluginInitContext context) + { + _context = context; + } + + public List LoadContextMenus(Result selectedResult) + { + var contextMenus = new List(); + if (selectedResult.ContextData is SearchResult record) + { + string editorPath = "notepad.exe"; // TODO add the ability to create a custom editor + + var name = "Open With Editor: " + Path.GetFileNameWithoutExtension(editorPath); + contextMenus.Add(new Result + { + Title = name, + Action = _ => + { + try + { + Process.Start(editorPath, record.FullPath); + } + catch + { + // TODO: update this + _context.API.ShowMsg( + string.Format(_context.API.GetTranslation("wox_plugin_everything_canot_start"), + record.FullPath), string.Empty, string.Empty); + return false; + } + + return true; + }, + IcoPath = editorPath + }); + + var icoPath = (record.Type == ResultType.File) ? "Images\\file.png" : "Images\\folder.png"; + contextMenus.Add(new Result + { + Title = _context.API.GetTranslation("wox_plugin_everything_copy_path"), + Action = (context) => + { + Clipboard.SetText(record.FullPath); + return true; + }, + IcoPath = icoPath + }); + + contextMenus.Add(new Result + { + Title = _context.API.GetTranslation("wox_plugin_everything_copy"), + Action = (context) => + { + Clipboard.SetFileDropList(new System.Collections.Specialized.StringCollection { record.FullPath }); + return true; + }, + IcoPath = icoPath + }); + + if (record.Type == ResultType.File || record.Type == ResultType.Folder) + contextMenus.Add(new Result + { + Title = _context.API.GetTranslation("wox_plugin_everything_delete"), + Action = (context) => + { + try + { + if (record.Type == ResultType.File) + System.IO.File.Delete(record.FullPath); + else + System.IO.Directory.Delete(record.FullPath); + } + catch + { + _context.API.ShowMsg(string.Format(_context.API.GetTranslation("wox_plugin_everything_canot_delete"), record.FullPath), string.Empty, string.Empty); + return false; + } + + return true; + }, + IcoPath = icoPath + }); + + } + + return contextMenus; + } + } + + public class SearchResult + { + public string FullPath { get; set; } + public ResultType Type { get; set; } + } + + public enum ResultType + { + Volume, + Folder, + File + } +} \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Folder/Main.cs b/Plugins/Wox.Plugin.Folder/Main.cs index 4f8fac60d..baac79b1e 100644 --- a/Plugins/Wox.Plugin.Folder/Main.cs +++ b/Plugins/Wox.Plugin.Folder/Main.cs @@ -9,13 +9,14 @@ using Wox.Infrastructure.Storage; namespace Wox.Plugin.Folder { - public class Main : IPlugin, ISettingProvider, IPluginI18n, ISavable + public class Main : IPlugin, ISettingProvider, IPluginI18n, ISavable, IContextMenu { private static List _driverNames; private PluginInitContext _context; private readonly Settings _settings; private readonly PluginJsonStorage _storage; + private readonly IContextMenu _contextMenuLoader = new ContextMenuLoader(); public Main() { @@ -104,7 +105,8 @@ namespace Wox.Plugin.Folder string changeTo = path.EndsWith("\\") ? path : path + "\\"; _context.API.ChangeQuery(string.IsNullOrEmpty(queryActionKeyword)? changeTo : queryActionKeyword + " " + changeTo); return false; - } + }, + ContextData = new SearchResult { Type = ResultType.Folder, FullPath = path } }; } @@ -226,7 +228,8 @@ namespace Wox.Plugin.Folder } return true; - } + }, + ContextData = new SearchResult { Type = ResultType.File, FullPath = filePath} }; return result; } @@ -263,5 +266,10 @@ namespace Wox.Plugin.Folder { return _context.API.GetTranslation("wox_plugin_folder_plugin_description"); } + + public List LoadContextMenus(Result selectedResult) + { + return _contextMenuLoader.LoadContextMenus(selectedResult); + } } } \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Folder/Wox.Plugin.Folder.csproj b/Plugins/Wox.Plugin.Folder/Wox.Plugin.Folder.csproj index 6a05ebd26..d29dc9874 100644 --- a/Plugins/Wox.Plugin.Folder/Wox.Plugin.Folder.csproj +++ b/Plugins/Wox.Plugin.Folder/Wox.Plugin.Folder.csproj @@ -58,6 +58,7 @@ Properties\SolutionAssemblyInfo.cs + From 2c87c00906175bb2c2d2c8176043d853b79443d4 Mon Sep 17 00:00:00 2001 From: AT <14300910+theClueless@users.noreply.github.com> Date: Fri, 13 Dec 2019 03:20:16 +0200 Subject: [PATCH 5/5] added context menu support (same as everything plugin) --- .../Wox.Plugin.Folder/ContextMenuLoader.cs | 130 +++++++++++++----- Plugins/Wox.Plugin.Folder/Images/file.png | Bin 0 -> 290 bytes Plugins/Wox.Plugin.Folder/Main.cs | 7 +- .../Wox.Plugin.Folder.csproj | 3 + 4 files changed, 107 insertions(+), 33 deletions(-) create mode 100644 Plugins/Wox.Plugin.Folder/Images/file.png diff --git a/Plugins/Wox.Plugin.Folder/ContextMenuLoader.cs b/Plugins/Wox.Plugin.Folder/ContextMenuLoader.cs index e1a923b4e..92fae4620 100644 --- a/Plugins/Wox.Plugin.Folder/ContextMenuLoader.cs +++ b/Plugins/Wox.Plugin.Folder/ContextMenuLoader.cs @@ -1,7 +1,9 @@ +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Windows; +using Wox.Infrastructure.Logger; namespace Wox.Plugin.Folder { @@ -19,51 +21,55 @@ namespace Wox.Plugin.Folder var contextMenus = new List(); if (selectedResult.ContextData is SearchResult record) { - string editorPath = "notepad.exe"; // TODO add the ability to create a custom editor + if (record.Type == ResultType.File) + { + contextMenus.Add(CreateOpenWithEditorResult(record)); + contextMenus.Add(CreateOpenContainingFolderResult(record)); + } - var name = "Open With Editor: " + Path.GetFileNameWithoutExtension(editorPath); + var icoPath = (record.Type == ResultType.File) ? Main.FileImagePath : Main.FolderImagePath; + var fileOrFolder = (record.Type == ResultType.File) ? "file" : "folder"; contextMenus.Add(new Result { - Title = name, - Action = _ => + Title = "Copy Path", + SubTitle = $"Copy the path of {fileOrFolder} into the clipboard", + Action = (context) => { try { - Process.Start(editorPath, record.FullPath); + Clipboard.SetText(record.FullPath); + return true; } - catch + catch (Exception e) { - // TODO: update this - _context.API.ShowMsg( - string.Format(_context.API.GetTranslation("wox_plugin_everything_canot_start"), - record.FullPath), string.Empty, string.Empty); + var message = "Fail to set text in clipboard"; + LogException(message, e); + _context.API.ShowMsg(message); return false; } - - return true; - }, - IcoPath = editorPath - }); - - var icoPath = (record.Type == ResultType.File) ? "Images\\file.png" : "Images\\folder.png"; - contextMenus.Add(new Result - { - Title = _context.API.GetTranslation("wox_plugin_everything_copy_path"), - Action = (context) => - { - Clipboard.SetText(record.FullPath); - return true; }, IcoPath = icoPath }); contextMenus.Add(new Result { - Title = _context.API.GetTranslation("wox_plugin_everything_copy"), + Title = "Copy", + SubTitle = $"Copy the {fileOrFolder} to the clipboard", Action = (context) => { - Clipboard.SetFileDropList(new System.Collections.Specialized.StringCollection { record.FullPath }); - return true; + try + { + Clipboard.SetFileDropList(new System.Collections.Specialized.StringCollection { record.FullPath }); + return true; + } + catch (Exception e) + { + var message = $"Fail to set {fileOrFolder} in clipboard"; + LogException(message, e); + _context.API.ShowMsg(message); + return false; + } + }, IcoPath = icoPath }); @@ -71,19 +77,21 @@ namespace Wox.Plugin.Folder if (record.Type == ResultType.File || record.Type == ResultType.Folder) contextMenus.Add(new Result { - Title = _context.API.GetTranslation("wox_plugin_everything_delete"), + Title = "Delete", Action = (context) => { try { if (record.Type == ResultType.File) - System.IO.File.Delete(record.FullPath); + File.Delete(record.FullPath); else - System.IO.Directory.Delete(record.FullPath); + Directory.Delete(record.FullPath); } - catch + catch(Exception e) { - _context.API.ShowMsg(string.Format(_context.API.GetTranslation("wox_plugin_everything_canot_delete"), record.FullPath), string.Empty, string.Empty); + var message = $"Fail to delete {fileOrFolder} at {record.FullPath}"; + LogException(message, e); + _context.API.ShowMsg(message); return false; } @@ -96,6 +104,64 @@ namespace Wox.Plugin.Folder return contextMenus; } + + private Result CreateOpenContainingFolderResult(SearchResult record) + { + return new Result + { + Title = "Open containing folder", + Action = _ => + { + try + { + Process.Start("explorer.exe", $" /select,\"{record.FullPath}\""); + } + catch(Exception e) + { + var message = $"Fail to open file at {record.FullPath}"; + LogException(message, e); + _context.API.ShowMsg(message); + return false; + } + + return true; + }, + IcoPath = Main.FolderImagePath + }; + } + + + private Result CreateOpenWithEditorResult(SearchResult record) + { + string editorPath = "notepad.exe"; // TODO add the ability to create a custom editor + + var name = "Open With Editor: " + Path.GetFileNameWithoutExtension(editorPath); + return new Result + { + Title = name, + Action = _ => + { + try + { + Process.Start(editorPath, record.FullPath); + return true; + } + catch (Exception e) + { + var message = $"Fail to editor for file at {record.FullPath}"; + LogException(message, e); + _context.API.ShowMsg(message); + return false; + } + }, + IcoPath = editorPath + }; + } + + public void LogException(string message, Exception e) + { + Log.Exception($"|Wox.Plugin.Folder.ContextMenu|{message}", e); + } } public class SearchResult diff --git a/Plugins/Wox.Plugin.Folder/Images/file.png b/Plugins/Wox.Plugin.Folder/Images/file.png new file mode 100644 index 0000000000000000000000000000000000000000..36156767a6572d31205104d16a8e909c5af378b4 GIT binary patch literal 290 zcmV+-0p0$IP)=FA?pM#)7Nq6>`@rGF3#p%4mjka3Wys(?018&wG;f _driverNames; private PluginInitContext _context; private readonly Settings _settings; private readonly PluginJsonStorage _storage; - private readonly IContextMenu _contextMenuLoader = new ContextMenuLoader(); + private IContextMenu _contextMenuLoader; public Main() { @@ -38,6 +42,7 @@ namespace Wox.Plugin.Folder public void Init(PluginInitContext context) { _context = context; + _contextMenuLoader = new ContextMenuLoader(context); InitialDriverList(); } diff --git a/Plugins/Wox.Plugin.Folder/Wox.Plugin.Folder.csproj b/Plugins/Wox.Plugin.Folder/Wox.Plugin.Folder.csproj index d29dc9874..e0305a648 100644 --- a/Plugins/Wox.Plugin.Folder/Wox.Plugin.Folder.csproj +++ b/Plugins/Wox.Plugin.Folder/Wox.Plugin.Folder.csproj @@ -81,6 +81,9 @@ PreserveNewest + + PreserveNewest + MSBuild:Compile Designer