Skip to content

Commit

Permalink
Implement additional context menu filters in Explore plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Yusyuriv committed Jun 12, 2024
1 parent 7515695 commit e79f2d7
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 19 deletions.
17 changes: 13 additions & 4 deletions Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,18 +283,27 @@ public List<Result> LoadContextMenus(Result selectedResult)

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))
.ToArray();
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)
{
Expand Down
3 changes: 2 additions & 1 deletion Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
4 changes: 3 additions & 1 deletion Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public class Settings

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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,22 @@ public bool ShowWindowsContextMenu
}
}

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();
}
}
Expand Down
53 changes: 43 additions & 10 deletions Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e79f2d7

Please sign in to comment.