Skip to content

Commit 78daf0b

Browse files
authored
Merge pull request #2763 from Flow-Launcher/explorer-plugin-add-context-menu-hotkey
Explorer plugin: open native context menu on Alt+Enter press
2 parents 188068d + 67f4f94 commit 78daf0b

File tree

4 files changed

+61
-48
lines changed

4 files changed

+61
-48
lines changed

Flow.Launcher/Languages/en.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@
204204
<system:String x:Key="CycleHistoryUpHotkey">Cycle Previous Query</system:String>
205205
<system:String x:Key="CycleHistoryDownHotkey">Cycle Next Query</system:String>
206206
<system:String x:Key="OpenContextMenuHotkey">Open Context Menu</system:String>
207+
<system:String x:Key="OpenNativeContextMenuHotkey">Open Native Context Menu</system:String>
207208
<system:String x:Key="SettingWindowHotkey">Open Setting Window</system:String>
208209
<system:String x:Key="CopyFilePathHotkey">Copy File Path</system:String>
209210
<system:String x:Key="ToggleGameModeHotkey">Toggle Game Mode</system:String>

Flow.Launcher/SettingPages/Views/SettingsPaneHotkey.xaml

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
xmlns:cc="clr-namespace:Flow.Launcher.Resources.Controls"
66
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
77
xmlns:flowlauncher="clr-namespace:Flow.Launcher"
8-
xmlns:userSettings="clr-namespace:Flow.Launcher.Infrastructure.UserSettings;assembly=Flow.Launcher.Infrastructure"
98
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
109
xmlns:ui="http://schemas.modernwpf.com/2019"
10+
xmlns:userSettings="clr-namespace:Flow.Launcher.Infrastructure.UserSettings;assembly=Flow.Launcher.Infrastructure"
1111
xmlns:viewModels="clr-namespace:Flow.Launcher.SettingPages.ViewModels"
1212
Title="Hotkey"
1313
d:DataContext="{d:DesignInstance viewModels:SettingsPaneHotkeyViewModel}"
@@ -33,9 +33,9 @@
3333
Sub="{DynamicResource flowlauncherHotkeyToolTip}">
3434
<flowlauncher:HotkeyControl
3535
ChangeHotkey="{Binding SetTogglingHotkeyCommand}"
36-
HotkeySettings="{Binding Settings}"
3736
DefaultHotkey="Alt+Space"
3837
Hotkey="{Binding Settings.Hotkey}"
38+
HotkeySettings="{Binding Settings}"
3939
ValidateKeyGesture="True"
4040
WindowTitle="{DynamicResource flowlauncherHotkey}" />
4141
</cc:Card>
@@ -45,17 +45,15 @@
4545
Icon="&#xe8a1;"
4646
Sub="{DynamicResource previewHotkeyToolTip}">
4747
<flowlauncher:HotkeyControl
48-
HotkeySettings="{Binding Settings}"
4948
DefaultHotkey="F1"
5049
Hotkey="{Binding Settings.PreviewHotkey}"
50+
HotkeySettings="{Binding Settings}"
5151
ValidateKeyGesture="False"
5252
WindowTitle="{DynamicResource previewHotkey}" />
5353
</cc:Card>
5454

5555
<cc:CardGroup Margin="0 12 0 0">
56-
<cc:Card
57-
Title="{DynamicResource openResultModifiers}"
58-
Sub="{DynamicResource openResultModifiersToolTip}">
56+
<cc:Card Title="{DynamicResource openResultModifiers}" Sub="{DynamicResource openResultModifiersToolTip}">
5957
<ComboBox
6058
Width="120"
6159
FontSize="14"
@@ -106,9 +104,9 @@
106104
Icon="&#xede3;"
107105
Type="Inside">
108106
<flowlauncher:HotkeyControl
109-
HotkeySettings="{Binding Settings}"
110107
DefaultHotkey="Ctrl+I"
111108
Hotkey="{Binding Settings.OpenContextMenuHotkey}"
109+
HotkeySettings="{Binding Settings}"
112110
ValidateKeyGesture="False" />
113111
</cc:Card>
114112
<cc:Card
@@ -117,15 +115,20 @@
117115
Type="Inside">
118116
<cc:HotkeyDisplay Keys="Shift+Enter" />
119117
</cc:Card>
120-
118+
<cc:Card
119+
Title="{DynamicResource OpenNativeContextMenuHotkey}"
120+
Icon="&#xede3;"
121+
Type="Inside">
122+
<cc:HotkeyDisplay Keys="Alt+Enter" />
123+
</cc:Card>
121124
<cc:Card
122125
Title="{DynamicResource SettingWindowHotkey}"
123126
Icon="&#xe713;"
124127
Type="Inside">
125128
<flowlauncher:HotkeyControl
126-
HotkeySettings="{Binding Settings}"
127129
DefaultHotkey="Ctrl+I"
128130
Hotkey="{Binding Settings.SettingWindowHotkey}"
131+
HotkeySettings="{Binding Settings}"
129132
ValidateKeyGesture="False" />
130133
</cc:Card>
131134
<cc:Card
@@ -172,19 +175,19 @@
172175
Icon="&#xf0ad;"
173176
Type="Inside">
174177
<flowlauncher:HotkeyControl
175-
HotkeySettings="{Binding Settings}"
176178
DefaultHotkey=""
177179
Hotkey="{Binding Settings.SelectPrevPageHotkey}"
180+
HotkeySettings="{Binding Settings}"
178181
ValidateKeyGesture="False" />
179182
</cc:Card>
180183
<cc:Card
181184
Title="{DynamicResource SelectNextPageHotkey}"
182185
Icon="&#xf0ae;"
183186
Type="Inside">
184187
<flowlauncher:HotkeyControl
185-
HotkeySettings="{Binding Settings}"
186188
DefaultHotkey=""
187189
Hotkey="{Binding Settings.SelectNextPageHotkey}"
190+
HotkeySettings="{Binding Settings}"
188191
ValidateKeyGesture="False" />
189192
</cc:Card>
190193

@@ -217,19 +220,19 @@
217220
Sub="{DynamicResource autoCompleteHotkeyToolTip}">
218221
<cc:ExCard.SideContent>
219222
<flowlauncher:HotkeyControl
220-
HotkeySettings="{Binding Settings}"
221223
DefaultHotkey="Ctrl+Tab"
222224
Hotkey="{Binding Settings.AutoCompleteHotkey}"
225+
HotkeySettings="{Binding Settings}"
223226
ValidateKeyGesture="False" />
224227
</cc:ExCard.SideContent>
225228
<cc:Card
226229
Title="{DynamicResource autoCompleteHotkey}"
227230
Sub="{DynamicResource AdditionalHotkeyToolTip}"
228231
Type="InsideFit">
229232
<flowlauncher:HotkeyControl
230-
HotkeySettings="{Binding Settings}"
231233
DefaultHotkey=""
232234
Hotkey="{Binding Settings.AutoCompleteHotkey2}"
235+
HotkeySettings="{Binding Settings}"
233236
ValidateKeyGesture="False" />
234237
</cc:Card>
235238
</cc:ExCard>
@@ -240,19 +243,19 @@
240243
Icon="&#xe74a;">
241244
<cc:ExCard.SideContent>
242245
<flowlauncher:HotkeyControl
243-
HotkeySettings="{Binding Settings}"
244246
DefaultHotkey="Shift+Tab"
245247
Hotkey="{Binding Settings.SelectPrevItemHotkey}"
248+
HotkeySettings="{Binding Settings}"
246249
ValidateKeyGesture="False" />
247250
</cc:ExCard.SideContent>
248251
<cc:Card
249252
Title="{DynamicResource SelectPrevItemHotkey}"
250253
Sub="{DynamicResource AdditionalHotkeyToolTip}"
251254
Type="InsideFit">
252255
<flowlauncher:HotkeyControl
253-
HotkeySettings="{Binding Settings}"
254256
DefaultHotkey=""
255257
Hotkey="{Binding Settings.SelectPrevItemHotkey2}"
258+
HotkeySettings="{Binding Settings}"
256259
ValidateKeyGesture="False" />
257260
</cc:Card>
258261
</cc:ExCard>
@@ -263,19 +266,19 @@
263266
Icon="&#xe74b;">
264267
<cc:ExCard.SideContent>
265268
<flowlauncher:HotkeyControl
266-
HotkeySettings="{Binding Settings}"
267269
DefaultHotkey="Tab"
268270
Hotkey="{Binding Settings.SelectNextItemHotkey}"
271+
HotkeySettings="{Binding Settings}"
269272
ValidateKeyGesture="False" />
270273
</cc:ExCard.SideContent>
271274
<cc:Card
272275
Title="{DynamicResource SelectNextItemHotkey}"
273276
Sub="{DynamicResource AdditionalHotkeyToolTip}"
274277
Type="InsideFit">
275278
<flowlauncher:HotkeyControl
276-
HotkeySettings="{Binding Settings}"
277279
DefaultHotkey=""
278280
Hotkey="{Binding Settings.SelectNextItemHotkey2}"
281+
HotkeySettings="{Binding Settings}"
279282
ValidateKeyGesture="False" />
280283
</cc:Card>
281284
</cc:ExCard>
@@ -435,8 +438,7 @@
435438
<GridViewColumn Width="430" Header="{DynamicResource builtinShortcutDescription}">
436439
<GridViewColumn.CellTemplate>
437440
<DataTemplate DataType="{x:Type userSettings:BuiltinShortcutModel}">
438-
<TextBlock
439-
Text="{Binding Description, Converter={StaticResource TranslationConverter}}" />
441+
<TextBlock Text="{Binding Description, Converter={StaticResource TranslationConverter}}" />
440442
</DataTemplate>
441443
</GridViewColumn.CellTemplate>
442444
</GridViewColumn>

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

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -222,34 +222,7 @@ public List<Result> LoadContextMenus(Result selectedResult)
222222
if (record.Type is ResultType.Volume)
223223
return false;
224224

225-
var screenWithMouseCursor = System.Windows.Forms.Screen.FromPoint(System.Windows.Forms.Cursor.Position);
226-
var xOfScreenCenter = screenWithMouseCursor.WorkingArea.Left + screenWithMouseCursor.WorkingArea.Width / 2;
227-
var yOfScreenCenter = screenWithMouseCursor.WorkingArea.Top + screenWithMouseCursor.WorkingArea.Height / 2;
228-
var showPosition = new System.Drawing.Point(xOfScreenCenter, yOfScreenCenter);
229-
230-
switch (record.Type)
231-
{
232-
case ResultType.File:
233-
{
234-
var fileInfos = new FileInfo[]
235-
{
236-
new(record.FullPath)
237-
};
238-
239-
new Peter.ShellContextMenu().ShowContextMenu(fileInfos, showPosition);
240-
break;
241-
}
242-
case ResultType.Folder:
243-
{
244-
var directoryInfos = new DirectoryInfo[]
245-
{
246-
new(record.FullPath)
247-
};
248-
249-
new Peter.ShellContextMenu().ShowContextMenu(directoryInfos, showPosition);
250-
break;
251-
}
252-
}
225+
ResultManager.ShowNativeContextMenu(record.FullPath, record.Type);
253226

254227
return false;
255228
},

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

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Path = System.IO.Path;
1212
using System.Windows.Controls;
1313
using Flow.Launcher.Plugin.Explorer.Views;
14+
using Peter;
1415

1516
namespace Flow.Launcher.Plugin.Explorer.Search
1617
{
@@ -70,6 +71,27 @@ public static Result CreateResult(Query query, SearchResult result)
7071
};
7172
}
7273

74+
internal static void ShowNativeContextMenu(string path, ResultType type)
75+
{
76+
var screenWithMouseCursor = System.Windows.Forms.Screen.FromPoint(System.Windows.Forms.Cursor.Position);
77+
var xOfScreenCenter = screenWithMouseCursor.WorkingArea.Left + screenWithMouseCursor.WorkingArea.Width / 2;
78+
var yOfScreenCenter = screenWithMouseCursor.WorkingArea.Top + screenWithMouseCursor.WorkingArea.Height / 2;
79+
var showPosition = new System.Drawing.Point(xOfScreenCenter, yOfScreenCenter);
80+
81+
switch (type)
82+
{
83+
case ResultType.File:
84+
var fileInfo = new FileInfo[] { new(path) };
85+
new ShellContextMenu().ShowContextMenu(fileInfo, showPosition);
86+
break;
87+
88+
case ResultType.Folder:
89+
var folderInfo = new System.IO.DirectoryInfo[] { new(path) };
90+
new ShellContextMenu().ShowContextMenu(folderInfo, showPosition);
91+
break;
92+
}
93+
}
94+
7395
internal static Result CreateFolderResult(string title, string subtitle, string path, Query query, int score = 0, bool windowsIndexed = false)
7496
{
7597
return new Result
@@ -82,6 +104,11 @@ internal static Result CreateFolderResult(string title, string subtitle, string
82104
CopyText = path,
83105
Action = c =>
84106
{
107+
if (c.SpecialKeyState.ToModifierKeys() == ModifierKeys.Alt)
108+
{
109+
ShowNativeContextMenu(path, ResultType.Folder);
110+
return false;
111+
}
85112
// open folder
86113
if (c.SpecialKeyState.ToModifierKeys() == (ModifierKeys.Control | ModifierKeys.Shift))
87114
{
@@ -218,8 +245,13 @@ internal static Result CreateOpenCurrentFolderResult(string path, string actionK
218245
IcoPath = folderPath,
219246
Score = 500,
220247
CopyText = folderPath,
221-
Action = _ =>
248+
Action = c =>
222249
{
250+
if (c.SpecialKeyState.ToModifierKeys() == ModifierKeys.Alt)
251+
{
252+
ShowNativeContextMenu(folderPath, ResultType.Folder);
253+
return false;
254+
}
223255
OpenFolder(folderPath);
224256
return true;
225257
},
@@ -251,6 +283,11 @@ internal static Result CreateFileResult(string filePath, Query query, int score
251283
PreviewPanel = new Lazy<UserControl>(() => new PreviewPanel(Settings, filePath)),
252284
Action = c =>
253285
{
286+
if (c.SpecialKeyState.ToModifierKeys() == ModifierKeys.Alt)
287+
{
288+
ShowNativeContextMenu(filePath, ResultType.File);
289+
return false;
290+
}
254291
try
255292
{
256293
if (c.SpecialKeyState.ToModifierKeys() == (ModifierKeys.Control | ModifierKeys.Shift))

0 commit comments

Comments
 (0)