Skip to content

Commit a220284

Browse files
Add option to open in default file manager
1 parent 2d13d56 commit a220284

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed

Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
<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>
1919
<system:String x:Key="plugin_explorer_alternative_title">Explorer Alternative</system:String>
2020
<system:String x:Key="plugin_explorer_directoryinfosearch_error">Error occurred during search: {0}</system:String>
21+
<system:String x:Key="plugin_explorer_opendir_error">Could not open folder</system:String>
22+
<system:String x:Key="plugin_explorer_openfile_error">Could not open file</system:String>
2123

2224
<!-- Controls -->
2325
<system:String x:Key="plugin_explorer_delete">Delete</system:String>
@@ -34,6 +36,7 @@
3436
<system:String x:Key="plugin_explorer_shell_path">Shell Path</system:String>
3537
<system:String x:Key="plugin_explorer_indexsearchexcludedpaths_header">Index Search Excluded Paths</system:String>
3638
<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>
39+
<system:String x:Key="plugin_explorer_default_open_in_file_manager">Hit Enter to open folder in Default File Manager</system:String>
3740
<system:String x:Key="plugin_explorer_usewindowsindexfordirectorysearch">Use Index Search For Path Search</system:String>
3841
<system:String x:Key="plugin_explorer_manageindexoptions">Indexing Options</system:String>
3942
<system:String x:Key="plugin_explorer_actionkeywordview_search">Search:</system:String>

Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Threading.Tasks;
99
using System.Windows;
1010
using Flow.Launcher.Plugin.Explorer.Search.Everything;
11+
using System.Windows.Input;
1112

1213
namespace Flow.Launcher.Plugin.Explorer.Search
1314
{
@@ -79,7 +80,7 @@ internal static Result CreateFolderResult(string title, string subtitle, string
7980
Action = c =>
8081
{
8182
// open folder
82-
if (c.SpecialKeyState.CtrlPressed || (!Settings.PathSearchKeywordEnabled && !Settings.SearchActionKeywordEnabled))
83+
if (c.SpecialKeyState.ToModifierKeys() == (ModifierKeys.Control | ModifierKeys.Shift) || (!Settings.PathSearchKeywordEnabled && !Settings.SearchActionKeywordEnabled))
8384
{
8485
try
8586
{
@@ -88,13 +89,43 @@ internal static Result CreateFolderResult(string title, string subtitle, string
8889
}
8990
catch (Exception ex)
9091
{
91-
MessageBox.Show(ex.Message, "Could not start " + path);
92+
MessageBox.Show(ex.Message, Context.API.GetTranslation("plugin_explorer_opendir_error"));
93+
return false;
94+
}
95+
}
96+
// Open containing folder
97+
if (c.SpecialKeyState.ToModifierKeys() == ModifierKeys.Control || (!Settings.PathSearchKeywordEnabled && !Settings.SearchActionKeywordEnabled))
98+
{
99+
try
100+
{
101+
Context.API.OpenDirectory(Path.GetDirectoryName(path), path);
102+
return true;
103+
}
104+
catch (Exception ex)
105+
{
106+
MessageBox.Show(ex.Message, Context.API.GetTranslation("plugin_explorer_opendir_error"));
92107
return false;
93108
}
94109
}
95110

111+
if (Settings.DefaultOpenInFileManager)
112+
{
113+
try
114+
{
115+
OpenFolder(path);
116+
return true;
117+
}
118+
catch (Exception ex)
119+
{
120+
MessageBox.Show(ex.Message, Context.API.GetTranslation("plugin_explorer_opendir_error"));
121+
return false;
122+
}
123+
}
124+
else
125+
{
96126
// or make this folder the current query
97127
Context.API.ChangeQuery(GetPathWithActionKeyword(path, ResultType.Folder, query.ActionKeyword));
128+
}
98129

99130
return false;
100131
},
@@ -222,11 +253,11 @@ internal static Result CreateFileResult(string filePath, Query query, int score
222253
{
223254
try
224255
{
225-
if (c.SpecialKeyState.CtrlPressed && c.SpecialKeyState.ShiftPressed)
256+
if (c.SpecialKeyState.ToModifierKeys() == (ModifierKeys.Control | ModifierKeys.Shift))
226257
{
227258
OpenFileAsAdmin(filePath);
228259
}
229-
else if (c.SpecialKeyState.CtrlPressed)
260+
else if (c.SpecialKeyState.ToModifierKeys() == ModifierKeys.Control)
230261
{
231262
OpenFolder(filePath, filePath);
232263
}
@@ -237,7 +268,7 @@ internal static Result CreateFileResult(string filePath, Query query, int score
237268
}
238269
catch (Exception ex)
239270
{
240-
MessageBox.Show(ex.Message, "Could not start " + filePath);
271+
MessageBox.Show(ex.Message, Context.API.GetTranslation("plugin_explorer_openfile_error"));
241272
}
242273

243274
return true;
@@ -265,7 +296,7 @@ private static void OpenFile(string filePath)
265296
private static void OpenFolder(string folderPath, string fileNameOrFilePath = null)
266297
{
267298
IncrementEverythingRunCounterIfNeeded(folderPath);
268-
Context.API.OpenDirectory(Path.GetDirectoryName(folderPath), fileNameOrFilePath);
299+
Context.API.OpenDirectory(folderPath, fileNameOrFilePath);
269300
}
270301

271302
private static void OpenFileAsAdmin(string filePath)

Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class Settings
3232

3333
public bool ShowWindowsContextMenu { get; set; } = true;
3434

35+
public bool DefaultOpenInFileManager { get; set; } = false;
3536

3637
public string SearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign;
3738

Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@
168168
HorizontalAlignment="Left"
169169
Content="{DynamicResource plugin_explorer_use_location_as_working_dir}"
170170
IsChecked="{Binding Settings.UseLocationAsWorkingDir}" />
171+
<CheckBox
172+
Margin="0,10,0,0"
173+
HorizontalAlignment="Left"
174+
Content="{DynamicResource plugin_explorer_default_open_in_file_manager}"
175+
IsChecked="{Binding Settings.DefaultOpenInFileManager}" />
171176
<StackPanel Margin="0,10,0,10" Orientation="Horizontal">
172177
<Grid>
173178
<Grid.ColumnDefinitions>
@@ -348,11 +353,11 @@
348353
Header="{DynamicResource plugin_explorer_everything_setting_header}"
349354
Style="{DynamicResource ExplorerTabItem}">
350355
<StackPanel Margin="10" Orientation="Vertical">
351-
<CheckBox
356+
<CheckBox
352357
Margin="20,10,0,0"
353358
HorizontalAlignment="Left"
354359
Content="{DynamicResource flowlauncher_plugin_everything_search_fullpath}"
355-
IsChecked="{Binding Settings.EverythingSearchFullPath}" />
360+
IsChecked="{Binding Settings.EverythingSearchFullPath}" />
356361
<StackPanel Orientation="Horizontal">
357362
<Grid Margin="20,10,0,10">
358363
<Grid.ColumnDefinitions>

0 commit comments

Comments
 (0)