mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #2004 from VictoriousRaptor/ExplorerDefaultAction
Explorer default enter keypress action: open in file manager option
This commit is contained in:
commit
77e966ed3a
7 changed files with 102 additions and 49 deletions
|
|
@ -1,4 +1,6 @@
|
|||
namespace Flow.Launcher.Plugin
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Flow.Launcher.Plugin
|
||||
{
|
||||
public class ActionContext
|
||||
{
|
||||
|
|
@ -11,5 +13,13 @@
|
|||
public bool ShiftPressed { get; set; }
|
||||
public bool AltPressed { get; set; }
|
||||
public bool WinPressed { get; set; }
|
||||
|
||||
public ModifierKeys ToModifierKeys()
|
||||
{
|
||||
return (CtrlPressed ? ModifierKeys.Control : ModifierKeys.None) |
|
||||
(ShiftPressed ? ModifierKeys.Shift : ModifierKeys.None) |
|
||||
(AltPressed ? ModifierKeys.Alt : ModifierKeys.None) |
|
||||
(WinPressed ? ModifierKeys.Windows : ModifierKeys.None);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -170,6 +170,36 @@ namespace Flow.Launcher.Plugin.SharedCommands
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Open a file with associated application
|
||||
/// </summary>
|
||||
/// <param name="filePath">File path</param>
|
||||
/// <param name="workingDir">Working directory</param>
|
||||
/// <param name="asAdmin">Open as Administrator</param>
|
||||
public static void OpenFile(string filePath, string workingDir = "", bool asAdmin = false)
|
||||
{
|
||||
var psi = new ProcessStartInfo
|
||||
{
|
||||
FileName = filePath,
|
||||
UseShellExecute = true,
|
||||
WorkingDirectory = workingDir,
|
||||
Verb = asAdmin ? "runas" : string.Empty
|
||||
};
|
||||
try
|
||||
{
|
||||
if (FileExists(filePath))
|
||||
Process.Start(psi);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
#if DEBUG
|
||||
throw;
|
||||
#else
|
||||
MessageBox.Show(string.Format("Unable to open the path {0}, please check if it exists", filePath));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
///<summary>
|
||||
/// This checks whether a given string is a directory path or network location string.
|
||||
/// It does not check if location actually exists.
|
||||
|
|
|
|||
|
|
@ -348,8 +348,8 @@
|
|||
<system:String x:Key="HotkeyUpDownDesc">Back / Context Menu</system:String>
|
||||
<system:String x:Key="HotkeyLeftRightDesc">Item Navigation</system:String>
|
||||
<system:String x:Key="HotkeyShiftEnterDesc">Open Context Menu</system:String>
|
||||
<system:String x:Key="HotkeyCtrlEnterDesc">Open Containing Folder</system:String>
|
||||
<system:String x:Key="HotkeyCtrlShiftEnterDesc">Run as Admin</system:String>
|
||||
<system:String x:Key="HotkeyCtrlEnterDesc">Open A File/Folder's Containing Folder</system:String>
|
||||
<system:String x:Key="HotkeyCtrlShiftEnterDesc">Run as Admin / Open Folder in Default File Manager</system:String>
|
||||
<system:String x:Key="HotkeyCtrlHDesc">Query History</system:String>
|
||||
<system:String x:Key="HotkeyESCDesc">Back to Result in Context Menu</system:String>
|
||||
<system:String x:Key="HotkeyTabDesc">Autocomplete</system:String>
|
||||
|
|
|
|||
|
|
@ -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_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_opendir_error">Could not open folder</system:String>
|
||||
<system:String x:Key="plugin_explorer_openfile_error">Could not open file</system:String>
|
||||
|
||||
<!-- Controls -->
|
||||
<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_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_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_manageindexoptions">Indexing Options</system:String>
|
||||
<system:String x:Key="plugin_explorer_actionkeywordview_search">Search:</system:String>
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -88,13 +89,44 @@ 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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// or make this folder the current query
|
||||
Context.API.ChangeQuery(GetPathWithActionKeyword(path, ResultType.Folder, query.ActionKeyword));
|
||||
// If path search is disabled just open it in file manager
|
||||
if (Settings.DefaultOpenFolderInFileManager || (!Settings.PathSearchKeywordEnabled && !Settings.SearchActionKeywordEnabled))
|
||||
{
|
||||
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,22 +254,22 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
{
|
||||
try
|
||||
{
|
||||
if (c.SpecialKeyState.CtrlPressed && c.SpecialKeyState.ShiftPressed)
|
||||
if (c.SpecialKeyState.ToModifierKeys() == (ModifierKeys.Control | ModifierKeys.Shift))
|
||||
{
|
||||
OpenFileAsAdmin(filePath);
|
||||
OpenFile(filePath, Settings.UseLocationAsWorkingDir ? Path.GetDirectoryName(filePath) : string.Empty, true);
|
||||
}
|
||||
else if (c.SpecialKeyState.CtrlPressed)
|
||||
else if (c.SpecialKeyState.ToModifierKeys() == ModifierKeys.Control)
|
||||
{
|
||||
OpenFolder(filePath, filePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
OpenFile(filePath);
|
||||
OpenFile(filePath, Settings.UseLocationAsWorkingDir ? Path.GetDirectoryName(filePath) : string.Empty);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Could not start " + filePath);
|
||||
MessageBox.Show(ex.Message, Context.API.GetTranslation("plugin_explorer_openfile_error"));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
@ -256,38 +288,16 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
return MediaExtensions.Contains(extension.ToLowerInvariant());
|
||||
}
|
||||
|
||||
private static void OpenFile(string filePath)
|
||||
private static void OpenFile(string filePath, string workingDir = "", bool asAdmin = false)
|
||||
{
|
||||
IncrementEverythingRunCounterIfNeeded(filePath);
|
||||
FilesFolders.OpenPath(filePath);
|
||||
FilesFolders.OpenFile(filePath, workingDir, asAdmin);
|
||||
}
|
||||
|
||||
private static void OpenFolder(string folderPath, string fileNameOrFilePath = null)
|
||||
{
|
||||
IncrementEverythingRunCounterIfNeeded(folderPath);
|
||||
Context.API.OpenDirectory(Path.GetDirectoryName(folderPath), fileNameOrFilePath);
|
||||
}
|
||||
|
||||
private static void OpenFileAsAdmin(string filePath)
|
||||
{
|
||||
_ = Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
IncrementEverythingRunCounterIfNeeded(filePath);
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = filePath,
|
||||
UseShellExecute = true,
|
||||
WorkingDirectory = Settings.UseLocationAsWorkingDir ? Path.GetDirectoryName(filePath) : string.Empty,
|
||||
Verb = "runas",
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MessageBox.Show(e.Message, "Could not start " + filePath);
|
||||
}
|
||||
});
|
||||
Context.API.OpenDirectory(folderPath, fileNameOrFilePath);
|
||||
}
|
||||
|
||||
private static void IncrementEverythingRunCounterIfNeeded(string fileOrFolder)
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ namespace Flow.Launcher.Plugin.Explorer
|
|||
|
||||
public bool ShowWindowsContextMenu { get; set; } = true;
|
||||
|
||||
public bool DefaultOpenFolderInFileManager { get; set; } = false;
|
||||
|
||||
public string SearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign;
|
||||
|
||||
|
|
|
|||
|
|
@ -168,6 +168,11 @@
|
|||
HorizontalAlignment="Left"
|
||||
Content="{DynamicResource plugin_explorer_use_location_as_working_dir}"
|
||||
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">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
|
|
@ -348,17 +353,11 @@
|
|||
Header="{DynamicResource plugin_explorer_everything_setting_header}"
|
||||
Style="{DynamicResource ExplorerTabItem}">
|
||||
<StackPanel Margin="10" Orientation="Vertical">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock
|
||||
Margin="10"
|
||||
VerticalAlignment="Center"
|
||||
Text="{DynamicResource flowlauncher_plugin_everything_search_fullpath}"
|
||||
TextBlock.Foreground="{DynamicResource Color05B}" />
|
||||
<CheckBox
|
||||
Margin="10"
|
||||
VerticalAlignment="Center"
|
||||
IsChecked="{Binding Settings.EverythingSearchFullPath}" />
|
||||
</StackPanel>
|
||||
<CheckBox
|
||||
Margin="20,10,0,0"
|
||||
HorizontalAlignment="Left"
|
||||
Content="{DynamicResource flowlauncher_plugin_everything_search_fullpath}"
|
||||
IsChecked="{Binding Settings.EverythingSearchFullPath}" />
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Grid Margin="20,10,0,10">
|
||||
<Grid.ColumnDefinitions>
|
||||
|
|
|
|||
Loading…
Reference in a new issue