From bd645126431378a218a149e90458df4707499c16 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Tue, 30 Jun 2020 08:15:10 +1000 Subject: [PATCH] add open containing folder to file results --- Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs | 8 ++++++++ Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs | 2 +- .../Search/Constants.cs | 2 ++ .../Search/ResultManager.cs | 12 +++++++++++- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs b/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs index ce067e8a0..98cd777aa 100644 --- a/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs +++ b/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs @@ -8,6 +8,9 @@ namespace Flow.Launcher.Plugin.SharedCommands public static class FilesFolders { private const string FileExplorerProgramName = "explorer"; + + private const string FileExplorerProgramEXE = "explorer.exe"; + public static void Copy(this string sourcePath, string targetPath) { // Get the subdirectories for the specified directory. @@ -128,6 +131,11 @@ namespace Flow.Launcher.Plugin.SharedCommands } } + public static void OpenContainingFolder(string path) + { + Process.Start(FileExplorerProgramEXE, $" /select,\"{path}\""); + } + /// /// This checks whether a given string is a directory path or network location string. /// It does not check if location actually exists. diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs b/Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs index 90a3fb2e8..89dbb3f88 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs @@ -156,7 +156,7 @@ namespace Flow.Launcher.Plugin.Explorer { try { - Process.Start("explorer.exe", $" /select,\"{record.FullPath}\""); + FilesFolders.OpenContainingFolder(record.FullPath); } catch (Exception e) { diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/Constants.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/Constants.cs index 5285dfe6e..d474fb0e7 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/Constants.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/Constants.cs @@ -18,6 +18,8 @@ namespace Flow.Launcher.Plugin.Explorer.Search internal const string ToolTipOpenDirectory = "Ctrl + Enter to open the directory"; + internal const string ToolTipOpenContainingFolder = "Ctrl + Enter to open the containing folder"; + internal const char AllFilesFolderSearchWildcard = '>'; internal const char DirectorySeperator = '\\'; diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs index bfde8c2c7..6a336c59a 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs @@ -1,6 +1,7 @@ using Flow.Launcher.Infrastructure; using Flow.Launcher.Plugin.SharedCommands; using System; +using System.Diagnostics; using System.IO; using System.Linq; using System.Windows; @@ -105,7 +106,14 @@ namespace Flow.Launcher.Plugin.Explorer.Search { try { - FilesFolders.OpenPath(filePath); + if (c.SpecialKeyState.CtrlPressed) + { + FilesFolders.OpenContainingFolder(filePath); + } + else + { + FilesFolders.OpenPath(filePath); + } } catch (Exception ex) { @@ -114,6 +122,8 @@ namespace Flow.Launcher.Plugin.Explorer.Search return true; }, + TitleToolTip = Constants.ToolTipOpenContainingFolder, + SubTitleToolTip = Constants.ToolTipOpenContainingFolder, ContextData = new SearchResult { Type = ResultType.File, FullPath = filePath, ShowIndexState = showIndexState, WindowsIndexed = windowsIndexed } }; return result;