Skip to content

Commit d8a225f

Browse files
committed
Explorer plugin: open native context menu on Alt+Enter press
1 parent 44ad866 commit d8a225f

File tree

2 files changed

+39
-29
lines changed

2 files changed

+39
-29
lines changed

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)