Skip to content

Commit 42939ea

Browse files
authored
Merge pull request #2742 from Flow-Launcher/explorer-plugin-integrated-context-menu
Integrate native Windows context menu directly into the Explorer plugin
2 parents 2dd51c8 + f743288 commit 42939ea

File tree

7 files changed

+720
-55
lines changed

7 files changed

+720
-55
lines changed

Flow.Launcher/ResultListBox.xaml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@
6262
<StackPanel
6363
x:Name="HotkeyArea"
6464
Grid.Column="2"
65-
Margin="0,0,10,0"
65+
Margin="0 0 10 0"
6666
VerticalAlignment="Center"
6767
Visibility="{Binding ShowOpenResultHotkey}">
6868
<TextBlock
6969
x:Name="Hotkey"
70-
Margin="12,0,12,0"
71-
Padding="0,0,0,0"
70+
Margin="12 0 12 0"
71+
Padding="0 0 0 0"
7272
HorizontalAlignment="Right"
7373
VerticalAlignment="Center"
7474
Style="{DynamicResource ItemHotkeyStyle}">
@@ -97,17 +97,18 @@
9797

9898
<Border
9999
Grid.Column="1"
100-
Margin="9,0,0,0"
100+
Margin="9 0 0 0"
101101
BorderBrush="Transparent"
102102
BorderThickness="1">
103103
<Image
104104
x:Name="ImageIcon"
105-
Margin="0,0,0,0"
105+
Margin="0 0 0 0"
106106
HorizontalAlignment="Center"
107107
IsHitTestVisible="False"
108108
RenderOptions.BitmapScalingMode="Fant"
109109
Source="{Binding Image, TargetNullValue={x:Null}}"
110110
Stretch="Uniform"
111+
StretchDirection="DownOnly"
111112
Style="{DynamicResource ImageIconStyle}"
112113
Visibility="{Binding ShowIcon}">
113114
<Image.Clip>
@@ -130,7 +131,7 @@
130131
</Border>
131132
<Border
132133
Grid.Column="1"
133-
Margin="9,0,0,0"
134+
Margin="9 0 0 0"
134135
BorderBrush="Transparent"
135136
BorderThickness="0">
136137
<TextBlock
@@ -146,7 +147,7 @@
146147

147148
<Grid
148149
Grid.Column="1"
149-
Margin="6,0,10,0"
150+
Margin="6 0 10 0"
150151
HorizontalAlignment="Stretch"
151152
VerticalAlignment="Center">
152153
<Grid.RowDefinitions>
@@ -172,7 +173,7 @@
172173
<TextBlock
173174
x:Name="Title"
174175
Grid.Row="0"
175-
Margin="0,0,0,1"
176+
Margin="0 0 0 1"
176177
VerticalAlignment="Bottom"
177178
DockPanel.Dock="Left"
178179
FontSize="{Binding Settings.ResultItemFontSize, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
@@ -192,7 +193,7 @@
192193
<TextBlock
193194
x:Name="SubTitle"
194195
Grid.Row="1"
195-
Margin="0,1,0,0"
196+
Margin="0 1 0 0"
196197
VerticalAlignment="Top"
197198
FontSize="{Binding Settings.ResultSubItemFontSize, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
198199
IsEnabled="False"
@@ -221,9 +222,10 @@
221222
<!-- http://stackoverflow.com/questions/16819577/setting-background-color-or-wpf-4-0-listbox-windows-8/#16820062 -->
222223
<ListBox.ItemContainerStyle>
223224
<Style TargetType="{x:Type ListBoxItem}">
225+
<Setter Property="Height" Value="{Binding Settings.ItemHeightSize}" />
226+
<Setter Property="Visibility" Value="Visible" />
224227
<EventSetter Event="MouseEnter" Handler="OnMouseEnter" />
225228
<EventSetter Event="MouseMove" Handler="OnMouseMove" />
226-
<Setter Property="Height" Value="{Binding Settings.ItemHeightSize, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
227229
<Setter Property="Margin" Value="0" />
228230
<Setter Property="Padding" Value="0" />
229231
<Setter Property="BorderThickness" Value="0" />
@@ -256,4 +258,4 @@
256258
</Setter>
257259
</Style>
258260
</ListBox.ItemContainerStyle>
259-
</ListBox>
261+
</ListBox>

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Flow.Launcher.Plugin.Explorer.Search;
1010
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;
1111
using System.Linq;
12+
using Flow.Launcher.Plugin.Explorer.Helper;
1213
using MessageBox = System.Windows.Forms.MessageBox;
1314
using MessageBoxIcon = System.Windows.Forms.MessageBoxIcon;
1415
using MessageBoxButton = System.Windows.Forms.MessageBoxButtons;
@@ -252,6 +253,45 @@ public List<Result> LoadContextMenus(Result selectedResult)
252253
IcoPath = Constants.DifferentUserIconImagePath,
253254
Glyph = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\ue748"),
254255
});
256+
257+
if (record.Type is ResultType.File or ResultType.Folder && Settings.ShowInlinedWindowsContextMenu)
258+
{
259+
var includedItems = Settings
260+
.WindowsContextMenuIncludedItems
261+
.Replace("\r", "")
262+
.Split("\n")
263+
.Where(v => !string.IsNullOrWhiteSpace(v))
264+
.ToArray();
265+
var excludedItems = Settings
266+
.WindowsContextMenuExcludedItems
267+
.Replace("\r", "")
268+
.Split("\n")
269+
.Where(v => !string.IsNullOrWhiteSpace(v))
270+
.ToArray();
271+
var menuItems = ShellContextMenuDisplayHelper
272+
.GetContextMenuWithIcons(record.FullPath)
273+
.Where(contextMenuItem =>
274+
(includedItems.Length == 0 || includedItems.Any(filter =>
275+
contextMenuItem.Label.Contains(filter, StringComparison.OrdinalIgnoreCase)
276+
)) &&
277+
(excludedItems.Length == 0 || !excludedItems.Any(filter =>
278+
contextMenuItem.Label.Contains(filter, StringComparison.OrdinalIgnoreCase)
279+
))
280+
);
281+
foreach (var menuItem in menuItems)
282+
{
283+
contextMenus.Add(new Result
284+
{
285+
Title = menuItem.Label,
286+
Icon = () => menuItem.Icon,
287+
Action = _ =>
288+
{
289+
ShellContextMenuDisplayHelper.ExecuteContextMenuItem(record.FullPath, menuItem.CommandId);
290+
return true;
291+
}
292+
});
293+
}
294+
}
255295
}
256296

257297
return contextMenus;

0 commit comments

Comments
 (0)