Add hotkey to open program's parent folder

This commit is contained in:
Vic 2023-04-10 00:26:55 +08:00
parent 8f58d53b8a
commit 2616b70db5
3 changed files with 23 additions and 13 deletions

View file

@ -348,7 +348,7 @@
<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 A File/Folder's Containing Folder</system:String>
<system:String x:Key="HotkeyCtrlEnterDesc">Open 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>

View file

@ -14,6 +14,7 @@ using Flow.Launcher.Plugin.SharedModels;
using System.Threading.Channels;
using System.Xml;
using Windows.ApplicationModel.Core;
using System.Windows.Input;
namespace Flow.Launcher.Plugin.Program.Programs
{
@ -422,12 +423,16 @@ namespace Flow.Launcher.Plugin.Program.Programs
ContextData = this,
Action = e =>
{
var elevated = (
e.SpecialKeyState.CtrlPressed &&
e.SpecialKeyState.ShiftPressed &&
!e.SpecialKeyState.AltPressed &&
!e.SpecialKeyState.WinPressed
);
// Ctrl + Enter to open containing folder
bool openFolder = e.SpecialKeyState.ToModifierKeys() == ModifierKeys.Control;
if (openFolder)
{
Main.Context.API.OpenDirectory(Location);
return true;
}
// Ctrl + Shift + Enter to run elevated
bool elevated = e.SpecialKeyState.ToModifierKeys() == (ModifierKeys.Control | ModifierKeys.Shift);
bool shouldRunElevated = elevated && CanRunElevated;
_ = Task.Run(() => Launch(shouldRunElevated)).ConfigureAwait(false);

View file

@ -16,6 +16,7 @@ using System.Diagnostics.CodeAnalysis;
using System.Threading.Channels;
using Flow.Launcher.Plugin.Program.Views.Models;
using IniParser;
using System.Windows.Input;
namespace Flow.Launcher.Plugin.Program.Programs
{
@ -169,12 +170,16 @@ namespace Flow.Launcher.Plugin.Program.Programs
ContextData = this,
Action = c =>
{
var runAsAdmin = (
c.SpecialKeyState.CtrlPressed &&
c.SpecialKeyState.ShiftPressed &&
!c.SpecialKeyState.AltPressed &&
!c.SpecialKeyState.WinPressed
);
// Ctrl + Enter to open containing folder
bool openFolder = c.SpecialKeyState.ToModifierKeys() == ModifierKeys.Control;
if (openFolder)
{
Main.Context.API.OpenDirectory(ParentDirectory, FullPath);
return true;
}
// Ctrl + Shift + Enter to run as admin
bool runAsAdmin = c.SpecialKeyState.ToModifierKeys() == (ModifierKeys.Control | ModifierKeys.Shift);
var info = new ProcessStartInfo
{