Merge pull request #2842 from z1nc0r3/explorer-feat-exclude-file-types

feat: Exclude certain File Types from the Index search result
This commit is contained in:
Jeremy Wu 2024-07-23 13:24:43 +10:00 committed by GitHub
commit 5e59892a5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 45 additions and 1 deletions

View file

@ -64,6 +64,8 @@
<system:String x:Key="plugin_explorer_Directory_Recursive_Search_Engine">Directory Recursive Search Engine</system:String>
<system:String x:Key="plugin_explorer_Index_Search_Engine">Index Search Engine</system:String>
<system:String x:Key="plugin_explorer_Open_Window_Index_Option">Open Windows Index Option</system:String>
<system:String x:Key="plugin_explorer_Excluded_File_Types">Excluded File Types (comma seperated)</system:String>
<system:String x:Key="plugin_explorer_Excluded_File_Types_Tooltip">For example: exe,jpg,png</system:String>
<!-- Plugin Infos -->
<system:String x:Key="plugin_explorer_plugin_name">Explorer</system:String>

View file

@ -8,6 +8,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Flow.Launcher.Plugin.Explorer.Exceptions;
using Path = System.IO.Path;
namespace Flow.Launcher.Plugin.Explorer.Search
{
@ -109,7 +110,11 @@ namespace Flow.Launcher.Plugin.Explorer.Search
try
{
await foreach (var search in searchResults.WithCancellation(token).ConfigureAwait(false))
results.Add(ResultManager.CreateResult(query, search));
if (search.Type == ResultType.File && IsExcludedFile(search)) {
continue;
} else {
results.Add(ResultManager.CreateResult(query, search));
}
}
catch (OperationCanceledException)
{
@ -247,5 +252,13 @@ namespace Flow.Launcher.Plugin.Explorer.Search
x => FilesFolders.ReturnPreviousDirectoryIfIncompleteString(pathToDirectory).StartsWith(x.Path, StringComparison.OrdinalIgnoreCase))
&& WindowsIndex.WindowsIndex.PathIsIndexed(pathToDirectory);
}
private bool IsExcludedFile(SearchResult result)
{
string[] excludedFileTypes = Settings.ExcludedFileTypes.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
string fileExtension = Path.GetExtension(result.FullPath).TrimStart('.');
return excludedFileTypes.Contains(fileExtension, StringComparer.OrdinalIgnoreCase);
}
}
}

View file

@ -25,6 +25,8 @@ namespace Flow.Launcher.Plugin.Explorer
public string ShellPath { get; set; } = "cmd";
public string ExcludedFileTypes { get; set; } = "";
public bool UseLocationAsWorkingDir { get; set; } = false;

View file

@ -513,6 +513,18 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
}
}
public string ExcludedFileTypes
{
get => Settings.ExcludedFileTypes;
set
{
// remove spaces and dots from the string before saving
string sanitized = string.IsNullOrEmpty(value) ? "" : value.Replace(" ", "").Replace(".", "");
Settings.ExcludedFileTypes = sanitized;
OnPropertyChanged();
}
}
#region Everything FastSortWarning

View file

@ -281,6 +281,7 @@
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock
Grid.Row="0"
@ -333,6 +334,20 @@
DisplayMemberPath="Description"
ItemsSource="{Binding PathEnumerationEngines}"
SelectedItem="{Binding SelectedPathEnumerationEngine}" />
<TextBlock
Grid.Row="3"
Grid.Column="0"
Margin="0 15 20 0"
VerticalAlignment="Center"
Text="{DynamicResource plugin_explorer_Excluded_File_Types}"
TextBlock.Foreground="{DynamicResource Color05B}" />
<TextBox
Grid.Row="3"
Grid.Column="1"
MinWidth="350"
Margin="0,9,0,6"
ToolTip="{DynamicResource plugin_explorer_Excluded_File_Types_Tooltip}"
Text="{Binding ExcludedFileTypes}" />
</Grid>
</StackPanel>
<StackPanel Orientation="Horizontal">