Add option to open in default file manager

This commit is contained in:
Vic 2023-03-24 15:02:11 +08:00
parent 2d13d5684b
commit a22028460d
4 changed files with 48 additions and 8 deletions

View file

@ -18,6 +18,8 @@
<system:String x:Key="plugin_explorer_alternative">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</system:String> <system:String x:Key="plugin_explorer_alternative">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</system:String>
<system:String x:Key="plugin_explorer_alternative_title">Explorer Alternative</system:String> <system:String x:Key="plugin_explorer_alternative_title">Explorer Alternative</system:String>
<system:String x:Key="plugin_explorer_directoryinfosearch_error">Error occurred during search: {0}</system:String> <system:String x:Key="plugin_explorer_directoryinfosearch_error">Error occurred during search: {0}</system:String>
<system:String x:Key="plugin_explorer_opendir_error">Could not open folder</system:String>
<system:String x:Key="plugin_explorer_openfile_error">Could not open file</system:String>
<!-- Controls --> <!-- Controls -->
<system:String x:Key="plugin_explorer_delete">Delete</system:String> <system:String x:Key="plugin_explorer_delete">Delete</system:String>
@ -34,6 +36,7 @@
<system:String x:Key="plugin_explorer_shell_path">Shell Path</system:String> <system:String x:Key="plugin_explorer_shell_path">Shell Path</system:String>
<system:String x:Key="plugin_explorer_indexsearchexcludedpaths_header">Index Search Excluded Paths</system:String> <system:String x:Key="plugin_explorer_indexsearchexcludedpaths_header">Index Search Excluded Paths</system:String>
<system:String x:Key="plugin_explorer_use_location_as_working_dir">Use search result's location as the working directory of the executable</system:String> <system:String x:Key="plugin_explorer_use_location_as_working_dir">Use search result's location as the working directory of the executable</system:String>
<system:String x:Key="plugin_explorer_default_open_in_file_manager">Hit Enter to open folder in Default File Manager</system:String>
<system:String x:Key="plugin_explorer_usewindowsindexfordirectorysearch">Use Index Search For Path Search</system:String> <system:String x:Key="plugin_explorer_usewindowsindexfordirectorysearch">Use Index Search For Path Search</system:String>
<system:String x:Key="plugin_explorer_manageindexoptions">Indexing Options</system:String> <system:String x:Key="plugin_explorer_manageindexoptions">Indexing Options</system:String>
<system:String x:Key="plugin_explorer_actionkeywordview_search">Search:</system:String> <system:String x:Key="plugin_explorer_actionkeywordview_search">Search:</system:String>

View file

@ -8,6 +8,7 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using Flow.Launcher.Plugin.Explorer.Search.Everything; using Flow.Launcher.Plugin.Explorer.Search.Everything;
using System.Windows.Input;
namespace Flow.Launcher.Plugin.Explorer.Search namespace Flow.Launcher.Plugin.Explorer.Search
{ {
@ -79,7 +80,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
Action = c => Action = c =>
{ {
// open folder // open folder
if (c.SpecialKeyState.CtrlPressed || (!Settings.PathSearchKeywordEnabled && !Settings.SearchActionKeywordEnabled)) if (c.SpecialKeyState.ToModifierKeys() == (ModifierKeys.Control | ModifierKeys.Shift) || (!Settings.PathSearchKeywordEnabled && !Settings.SearchActionKeywordEnabled))
{ {
try try
{ {
@ -88,13 +89,43 @@ namespace Flow.Launcher.Plugin.Explorer.Search
} }
catch (Exception ex) 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; 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 // or make this folder the current query
Context.API.ChangeQuery(GetPathWithActionKeyword(path, ResultType.Folder, query.ActionKeyword)); Context.API.ChangeQuery(GetPathWithActionKeyword(path, ResultType.Folder, query.ActionKeyword));
}
return false; return false;
}, },
@ -222,11 +253,11 @@ namespace Flow.Launcher.Plugin.Explorer.Search
{ {
try try
{ {
if (c.SpecialKeyState.CtrlPressed && c.SpecialKeyState.ShiftPressed) if (c.SpecialKeyState.ToModifierKeys() == (ModifierKeys.Control | ModifierKeys.Shift))
{ {
OpenFileAsAdmin(filePath); OpenFileAsAdmin(filePath);
} }
else if (c.SpecialKeyState.CtrlPressed) else if (c.SpecialKeyState.ToModifierKeys() == ModifierKeys.Control)
{ {
OpenFolder(filePath, filePath); OpenFolder(filePath, filePath);
} }
@ -237,7 +268,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
} }
catch (Exception ex) catch (Exception ex)
{ {
MessageBox.Show(ex.Message, "Could not start " + filePath); MessageBox.Show(ex.Message, Context.API.GetTranslation("plugin_explorer_openfile_error"));
} }
return true; return true;
@ -265,7 +296,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
private static void OpenFolder(string folderPath, string fileNameOrFilePath = null) private static void OpenFolder(string folderPath, string fileNameOrFilePath = null)
{ {
IncrementEverythingRunCounterIfNeeded(folderPath); IncrementEverythingRunCounterIfNeeded(folderPath);
Context.API.OpenDirectory(Path.GetDirectoryName(folderPath), fileNameOrFilePath); Context.API.OpenDirectory(folderPath, fileNameOrFilePath);
} }
private static void OpenFileAsAdmin(string filePath) private static void OpenFileAsAdmin(string filePath)

View file

@ -32,6 +32,7 @@ namespace Flow.Launcher.Plugin.Explorer
public bool ShowWindowsContextMenu { get; set; } = true; public bool ShowWindowsContextMenu { get; set; } = true;
public bool DefaultOpenInFileManager { get; set; } = false;
public string SearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign; public string SearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign;

View file

@ -168,6 +168,11 @@
HorizontalAlignment="Left" HorizontalAlignment="Left"
Content="{DynamicResource plugin_explorer_use_location_as_working_dir}" Content="{DynamicResource plugin_explorer_use_location_as_working_dir}"
IsChecked="{Binding Settings.UseLocationAsWorkingDir}" /> IsChecked="{Binding Settings.UseLocationAsWorkingDir}" />
<CheckBox
Margin="0,10,0,0"
HorizontalAlignment="Left"
Content="{DynamicResource plugin_explorer_default_open_in_file_manager}"
IsChecked="{Binding Settings.DefaultOpenInFileManager}" />
<StackPanel Margin="0,10,0,10" Orientation="Horizontal"> <StackPanel Margin="0,10,0,10" Orientation="Horizontal">
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
@ -348,11 +353,11 @@
Header="{DynamicResource plugin_explorer_everything_setting_header}" Header="{DynamicResource plugin_explorer_everything_setting_header}"
Style="{DynamicResource ExplorerTabItem}"> Style="{DynamicResource ExplorerTabItem}">
<StackPanel Margin="10" Orientation="Vertical"> <StackPanel Margin="10" Orientation="Vertical">
<CheckBox <CheckBox
Margin="20,10,0,0" Margin="20,10,0,0"
HorizontalAlignment="Left" HorizontalAlignment="Left"
Content="{DynamicResource flowlauncher_plugin_everything_search_fullpath}" Content="{DynamicResource flowlauncher_plugin_everything_search_fullpath}"
IsChecked="{Binding Settings.EverythingSearchFullPath}" /> IsChecked="{Binding Settings.EverythingSearchFullPath}" />
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<Grid Margin="20,10,0,10"> <Grid Margin="20,10,0,10">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>