Merge pull request #2042 from VictoriousRaptor/ProgramOpenFolderHotkey

Add open parent folder hotkey for program plugin
This commit is contained in:
VictoriousRaptor 2023-04-19 04:07:31 +08:00 committed by GitHub
commit d8965c5823
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 15 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);
@ -459,7 +464,8 @@ namespace Flow.Launcher.Plugin.Program.Programs
return true;
},
IcoPath = "Images/folder.png"
IcoPath = "Images/folder.png",
Glyph = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\xe838"),
}
};
@ -473,7 +479,8 @@ namespace Flow.Launcher.Plugin.Program.Programs
Task.Run(() => Launch(true)).ConfigureAwait(false);
return true;
},
IcoPath = "Images/cmd.png"
IcoPath = "Images/cmd.png",
Glyph = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\xe7ef")
});
}

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
{