Implement additional context menu filters in Explore plugin

This commit is contained in:
Yusyuriv 2024-06-12 18:36:36 +06:00
parent 75156959e5
commit e79f2d7958
No known key found for this signature in database
GPG key ID: A91C52E6F73148E0
5 changed files with 74 additions and 19 deletions

View file

@ -283,8 +283,14 @@ namespace Flow.Launcher.Plugin.Explorer
if (record.Type is ResultType.File or ResultType.Folder && Settings.ShowInlinedWindowsContextMenu)
{
var filters = Settings
.WindowsContextMenuIgnoredItems
var includedItems = Settings
.WindowsContextMenuIncludedItems
.Replace("\r", "")
.Split("\n")
.Where(v => !string.IsNullOrWhiteSpace(v))
.ToArray();
var excludedItems = Settings
.WindowsContextMenuExcludedItems
.Replace("\r", "")
.Split("\n")
.Where(v => !string.IsNullOrWhiteSpace(v))
@ -292,9 +298,12 @@ namespace Flow.Launcher.Plugin.Explorer
var menuItems = ShellContextMenuDisplayHelper
.GetContextMenuWithIcons(record.FullPath)
.Where(contextMenuItem =>
filters.Length == 0 || !filters.Any(filter =>
(includedItems.Length == 0 || includedItems.Any(filter =>
contextMenuItem.Label.Contains(filter, StringComparison.OrdinalIgnoreCase)
)
)) &&
(excludedItems.Length == 0 || !excludedItems.Any(filter =>
contextMenuItem.Label.Contains(filter, StringComparison.OrdinalIgnoreCase)
))
);
foreach (var menuItem in menuItems)
{

View file

@ -155,5 +155,6 @@
<!-- Native Context Menu -->
<system:String x:Key="plugin_explorer_native_context_menu_header">Native Context Menu</system:String>
<system:String x:Key="plugin_explorer_native_context_menu_display_context_menu">Display native context menu</system:String>
<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>
<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>
<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>
</ResourceDictionary>

View file

@ -30,7 +30,9 @@ namespace Flow.Launcher.Plugin.Explorer
public bool ShowInlinedWindowsContextMenu { get; set; } = false;
public string WindowsContextMenuIgnoredItems { get; set; } = string.Empty;
public string WindowsContextMenuIncludedItems { get; set; } = string.Empty;
public string WindowsContextMenuExcludedItems { get; set; } = string.Empty;
public bool DefaultOpenFolderInFileManager { get; set; } = false;

View file

@ -114,12 +114,22 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
}
}
public string WindowsContextMenuIgnoredItems
public string WindowsContextMenuIncludedItems
{
get => Settings.WindowsContextMenuIgnoredItems;
get => Settings.WindowsContextMenuIncludedItems;
set
{
Settings.WindowsContextMenuIgnoredItems = value;
Settings.WindowsContextMenuIncludedItems = value;
OnPropertyChanged();
}
}
public string WindowsContextMenuExcludedItems
{
get => Settings.WindowsContextMenuExcludedItems;
set
{
Settings.WindowsContextMenuExcludedItems = value;
OnPropertyChanged();
}
}

View file

@ -358,17 +358,50 @@
Content="{DynamicResource plugin_explorer_native_context_menu_display_context_menu}"
IsChecked="{Binding ShowWindowsContextMenu}" />
<TextBlock
Margin=" 0 10 20 10"
Foreground="{DynamicResource Color05B}"
Text="{DynamicResource plugin_explorer_native_context_menu_guide}"
TextWrapping="Wrap" />
<Grid Margin="0 10 20 10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBox
Height="300"
AcceptsReturn="True"
Text="{Binding WindowsContextMenuIgnoredItems}"
TextWrapping="Wrap" />
<TextBlock
Grid.Row="0"
Grid.Column="0"
Margin="0 0 6 6"
Foreground="{DynamicResource Color05B}"
Text="{DynamicResource plugin_explorer_native_context_menu_include_patterns_guide}"
TextWrapping="Wrap" />
<TextBox
Grid.Row="1"
Grid.Column="0"
Height="300"
Margin="0 6 6 0"
AcceptsReturn="True"
Text="{Binding WindowsContextMenuIncludedItems}"
TextWrapping="Wrap" />
<TextBlock
Grid.Row="0"
Grid.Column="1"
Margin="6 0 0 6"
Foreground="{DynamicResource Color05B}"
Text="{DynamicResource plugin_explorer_native_context_menu_exclude_patterns_guide}"
TextWrapping="Wrap" />
<TextBox
Grid.Row="1"
Grid.Column="1"
Height="300"
Margin="6 6 0 0"
AcceptsReturn="True"
Text="{Binding WindowsContextMenuExcludedItems}"
TextWrapping="Wrap" />
</Grid>
</StackPanel>
</TabItem>
<TabItem