From a22028460dfaf0e391c7b9ea57b84dfc66352ce7 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Fri, 24 Mar 2023 15:02:11 +0800
Subject: [PATCH] Add option to open in default file manager
---
.../Languages/en.xaml | 3 ++
.../Search/ResultManager.cs | 43 ++++++++++++++++---
.../Flow.Launcher.Plugin.Explorer/Settings.cs | 1 +
.../Views/ExplorerSettings.xaml | 9 +++-
4 files changed, 48 insertions(+), 8 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml b/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml
index 58fe31dd6..d5352ef1e 100644
--- a/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml
+++ b/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml
@@ -18,6 +18,8 @@
The warning message has been switched off. As an alternative for searching files and folders, would you like to install Everything plugin?{0}{0}Select 'Yes' to install Everything plugin, or 'No' to return
Explorer Alternative
Error occurred during search: {0}
+ Could not open folder
+ Could not open file
Delete
@@ -34,6 +36,7 @@
Shell Path
Index Search Excluded Paths
Use search result's location as the working directory of the executable
+ Hit Enter to open folder in Default File Manager
Use Index Search For Path Search
Indexing Options
Search:
diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs
index 7147c348e..5ac01c3ad 100644
--- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs
+++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs
@@ -8,6 +8,7 @@ using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using Flow.Launcher.Plugin.Explorer.Search.Everything;
+using System.Windows.Input;
namespace Flow.Launcher.Plugin.Explorer.Search
{
@@ -79,7 +80,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
Action = c =>
{
// open folder
- if (c.SpecialKeyState.CtrlPressed || (!Settings.PathSearchKeywordEnabled && !Settings.SearchActionKeywordEnabled))
+ if (c.SpecialKeyState.ToModifierKeys() == (ModifierKeys.Control | ModifierKeys.Shift) || (!Settings.PathSearchKeywordEnabled && !Settings.SearchActionKeywordEnabled))
{
try
{
@@ -88,13 +89,43 @@ namespace Flow.Launcher.Plugin.Explorer.Search
}
catch (Exception ex)
{
- MessageBox.Show(ex.Message, "Could not start " + path);
+ MessageBox.Show(ex.Message, Context.API.GetTranslation("plugin_explorer_opendir_error"));
+ return false;
+ }
+ }
+ // Open containing folder
+ if (c.SpecialKeyState.ToModifierKeys() == ModifierKeys.Control || (!Settings.PathSearchKeywordEnabled && !Settings.SearchActionKeywordEnabled))
+ {
+ try
+ {
+ Context.API.OpenDirectory(Path.GetDirectoryName(path), path);
+ return true;
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, Context.API.GetTranslation("plugin_explorer_opendir_error"));
return false;
}
}
+ if (Settings.DefaultOpenInFileManager)
+ {
+ try
+ {
+ OpenFolder(path);
+ return true;
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, Context.API.GetTranslation("plugin_explorer_opendir_error"));
+ return false;
+ }
+ }
+ else
+ {
// or make this folder the current query
Context.API.ChangeQuery(GetPathWithActionKeyword(path, ResultType.Folder, query.ActionKeyword));
+ }
return false;
},
@@ -222,11 +253,11 @@ namespace Flow.Launcher.Plugin.Explorer.Search
{
try
{
- if (c.SpecialKeyState.CtrlPressed && c.SpecialKeyState.ShiftPressed)
+ if (c.SpecialKeyState.ToModifierKeys() == (ModifierKeys.Control | ModifierKeys.Shift))
{
OpenFileAsAdmin(filePath);
}
- else if (c.SpecialKeyState.CtrlPressed)
+ else if (c.SpecialKeyState.ToModifierKeys() == ModifierKeys.Control)
{
OpenFolder(filePath, filePath);
}
@@ -237,7 +268,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
}
catch (Exception ex)
{
- MessageBox.Show(ex.Message, "Could not start " + filePath);
+ MessageBox.Show(ex.Message, Context.API.GetTranslation("plugin_explorer_openfile_error"));
}
return true;
@@ -265,7 +296,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
private static void OpenFolder(string folderPath, string fileNameOrFilePath = null)
{
IncrementEverythingRunCounterIfNeeded(folderPath);
- Context.API.OpenDirectory(Path.GetDirectoryName(folderPath), fileNameOrFilePath);
+ Context.API.OpenDirectory(folderPath, fileNameOrFilePath);
}
private static void OpenFileAsAdmin(string filePath)
diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs
index 339eaaaaa..b34cc3af9 100644
--- a/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs
+++ b/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs
@@ -32,6 +32,7 @@ namespace Flow.Launcher.Plugin.Explorer
public bool ShowWindowsContextMenu { get; set; } = true;
+ public bool DefaultOpenInFileManager { get; set; } = false;
public string SearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign;
diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml b/Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml
index 33cef6e45..9beb43a48 100644
--- a/Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml
+++ b/Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml
@@ -168,6 +168,11 @@
HorizontalAlignment="Left"
Content="{DynamicResource plugin_explorer_use_location_as_working_dir}"
IsChecked="{Binding Settings.UseLocationAsWorkingDir}" />
+
@@ -348,11 +353,11 @@
Header="{DynamicResource plugin_explorer_everything_setting_header}"
Style="{DynamicResource ExplorerTabItem}">
-
+ IsChecked="{Binding Settings.EverythingSearchFullPath}" />