Skip to content

Commit e79f2d7

Browse files
committed
Implement additional context menu filters in Explore plugin
1 parent 7515695 commit e79f2d7

File tree

5 files changed

+74
-19
lines changed

5 files changed

+74
-19
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,18 +283,27 @@ public List<Result> LoadContextMenus(Result selectedResult)
283283

284284
if (record.Type is ResultType.File or ResultType.Folder && Settings.ShowInlinedWindowsContextMenu)
285285
{
286-
var filters = Settings
287-
.WindowsContextMenuIgnoredItems
286+
var includedItems = Settings
287+
.WindowsContextMenuIncludedItems
288+
.Replace("\r", "")
289+
.Split("\n")
290+
.Where(v => !string.IsNullOrWhiteSpace(v))
291+
.ToArray();
292+
var excludedItems = Settings
293+
.WindowsContextMenuExcludedItems
288294
.Replace("\r", "")
289295
.Split("\n")
290296
.Where(v => !string.IsNullOrWhiteSpace(v))
291297
.ToArray();
292298
var menuItems = ShellContextMenuDisplayHelper
293299
.GetContextMenuWithIcons(record.FullPath)
294300
.Where(contextMenuItem =>
295-
filters.Length == 0 || !filters.Any(filter =>
301+
(includedItems.Length == 0 || includedItems.Any(filter =>
302+
contextMenuItem.Label.Contains(filter, StringComparison.OrdinalIgnoreCase)
303+
)) &&
304+
(excludedItems.Length == 0 || !excludedItems.Any(filter =>
296305
contextMenuItem.Label.Contains(filter, StringComparison.OrdinalIgnoreCase)
297-
)
306+
))
298307
);
299308
foreach (var menuItem in menuItems)
300309
{

Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,5 +155,6 @@
155155
<!-- Native Context Menu -->
156156
<system:String x:Key="plugin_explorer_native_context_menu_header">Native Context Menu</system:String>
157157
<system:String x:Key="plugin_explorer_native_context_menu_display_context_menu">Display native context menu</system:String>
158-
<system:String x:Key="plugin_explorer_native_context_menu_guide">Below you can specify items you want to exclude from context menu, they can be partial (e.g. 'pen wit') or complete ('Open with')</system:String>
158+
<system:String x:Key="plugin_explorer_native_context_menu_include_patterns_guide">Below you can specify items you want to include in the context menu, they can be partial (e.g. 'pen wit') or complete ('Open with').</system:String>
159+
<system:String x:Key="plugin_explorer_native_context_menu_exclude_patterns_guide">Below you can specify items you want to exclude from context menu, they can be partial (e.g. 'pen wit') or complete ('Open with')</system:String>
159160
</ResourceDictionary>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ public class Settings
3030

3131
public bool ShowInlinedWindowsContextMenu { get; set; } = false;
3232

33-
public string WindowsContextMenuIgnoredItems { get; set; } = string.Empty;
33+
public string WindowsContextMenuIncludedItems { get; set; } = string.Empty;
34+
35+
public string WindowsContextMenuExcludedItems { get; set; } = string.Empty;
3436

3537
public bool DefaultOpenFolderInFileManager { get; set; } = false;
3638

Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,22 @@ public bool ShowWindowsContextMenu
114114
}
115115
}
116116

117-
public string WindowsContextMenuIgnoredItems
117+
public string WindowsContextMenuIncludedItems
118118
{
119-
get => Settings.WindowsContextMenuIgnoredItems;
119+
get => Settings.WindowsContextMenuIncludedItems;
120120
set
121121
{
122-
Settings.WindowsContextMenuIgnoredItems = value;
122+
Settings.WindowsContextMenuIncludedItems = value;
123+
OnPropertyChanged();
124+
}
125+
}
126+
127+
public string WindowsContextMenuExcludedItems
128+
{
129+
get => Settings.WindowsContextMenuExcludedItems;
130+
set
131+
{
132+
Settings.WindowsContextMenuExcludedItems = value;
123133
OnPropertyChanged();
124134
}
125135
}

Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -358,17 +358,50 @@
358358
Content="{DynamicResource plugin_explorer_native_context_menu_display_context_menu}"
359359
IsChecked="{Binding ShowWindowsContextMenu}" />
360360

361-
<TextBlock
362-
Margin=" 0 10 20 10"
363-
Foreground="{DynamicResource Color05B}"
364-
Text="{DynamicResource plugin_explorer_native_context_menu_guide}"
365-
TextWrapping="Wrap" />
361+
<Grid Margin="0 10 20 10">
362+
<Grid.ColumnDefinitions>
363+
<ColumnDefinition Width="*" />
364+
<ColumnDefinition Width="*" />
365+
</Grid.ColumnDefinitions>
366+
<Grid.RowDefinitions>
367+
<RowDefinition Height="Auto" />
368+
<RowDefinition Height="Auto" />
369+
</Grid.RowDefinitions>
366370

367-
<TextBox
368-
Height="300"
369-
AcceptsReturn="True"
370-
Text="{Binding WindowsContextMenuIgnoredItems}"
371-
TextWrapping="Wrap" />
371+
<TextBlock
372+
Grid.Row="0"
373+
Grid.Column="0"
374+
Margin="0 0 6 6"
375+
Foreground="{DynamicResource Color05B}"
376+
Text="{DynamicResource plugin_explorer_native_context_menu_include_patterns_guide}"
377+
TextWrapping="Wrap" />
378+
379+
<TextBox
380+
Grid.Row="1"
381+
Grid.Column="0"
382+
Height="300"
383+
Margin="0 6 6 0"
384+
AcceptsReturn="True"
385+
Text="{Binding WindowsContextMenuIncludedItems}"
386+
TextWrapping="Wrap" />
387+
388+
<TextBlock
389+
Grid.Row="0"
390+
Grid.Column="1"
391+
Margin="6 0 0 6"
392+
Foreground="{DynamicResource Color05B}"
393+
Text="{DynamicResource plugin_explorer_native_context_menu_exclude_patterns_guide}"
394+
TextWrapping="Wrap" />
395+
396+
<TextBox
397+
Grid.Row="1"
398+
Grid.Column="1"
399+
Height="300"
400+
Margin="6 6 0 0"
401+
AcceptsReturn="True"
402+
Text="{Binding WindowsContextMenuExcludedItems}"
403+
TextWrapping="Wrap" />
404+
</Grid>
372405
</StackPanel>
373406
</TabItem>
374407
<TabItem

0 commit comments

Comments
 (0)