Skip to content

Commit 5e59892

Browse files
authored
Merge pull request #2842 from z1nc0r3/explorer-feat-exclude-file-types
feat: Exclude certain File Types from the Index search result
2 parents 39f6cd6 + 0f7bdee commit 5e59892

File tree

5 files changed

+45
-1
lines changed

5 files changed

+45
-1
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
<system:String x:Key="plugin_explorer_Directory_Recursive_Search_Engine">Directory Recursive Search Engine</system:String>
6565
<system:String x:Key="plugin_explorer_Index_Search_Engine">Index Search Engine</system:String>
6666
<system:String x:Key="plugin_explorer_Open_Window_Index_Option">Open Windows Index Option</system:String>
67+
<system:String x:Key="plugin_explorer_Excluded_File_Types">Excluded File Types (comma seperated)</system:String>
68+
<system:String x:Key="plugin_explorer_Excluded_File_Types_Tooltip">For example: exe,jpg,png</system:String>
6769

6870
<!-- Plugin Infos -->
6971
<system:String x:Key="plugin_explorer_plugin_name">Explorer</system:String>

Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs

+14-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Threading;
99
using System.Threading.Tasks;
1010
using Flow.Launcher.Plugin.Explorer.Exceptions;
11+
using Path = System.IO.Path;
1112

1213
namespace Flow.Launcher.Plugin.Explorer.Search
1314
{
@@ -109,7 +110,11 @@ when ActionKeywordMatch(query, Settings.ActionKeyword.IndexSearchActionKeyword)
109110
try
110111
{
111112
await foreach (var search in searchResults.WithCancellation(token).ConfigureAwait(false))
112-
results.Add(ResultManager.CreateResult(query, search));
113+
if (search.Type == ResultType.File && IsExcludedFile(search)) {
114+
continue;
115+
} else {
116+
results.Add(ResultManager.CreateResult(query, search));
117+
}
113118
}
114119
catch (OperationCanceledException)
115120
{
@@ -247,5 +252,13 @@ private bool UseWindowsIndexForDirectorySearch(string locationPath)
247252
x => FilesFolders.ReturnPreviousDirectoryIfIncompleteString(pathToDirectory).StartsWith(x.Path, StringComparison.OrdinalIgnoreCase))
248253
&& WindowsIndex.WindowsIndex.PathIsIndexed(pathToDirectory);
249254
}
255+
256+
private bool IsExcludedFile(SearchResult result)
257+
{
258+
string[] excludedFileTypes = Settings.ExcludedFileTypes.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
259+
string fileExtension = Path.GetExtension(result.FullPath).TrimStart('.');
260+
261+
return excludedFileTypes.Contains(fileExtension, StringComparer.OrdinalIgnoreCase);
262+
}
250263
}
251264
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public class Settings
2525

2626
public string ShellPath { get; set; } = "cmd";
2727

28+
public string ExcludedFileTypes { get; set; } = "";
29+
2830

2931
public bool UseLocationAsWorkingDir { get; set; } = false;
3032

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

+12
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,18 @@ public string ShellPath
513513
}
514514
}
515515

516+
public string ExcludedFileTypes
517+
{
518+
get => Settings.ExcludedFileTypes;
519+
set
520+
{
521+
// remove spaces and dots from the string before saving
522+
string sanitized = string.IsNullOrEmpty(value) ? "" : value.Replace(" ", "").Replace(".", "");
523+
Settings.ExcludedFileTypes = sanitized;
524+
OnPropertyChanged();
525+
}
526+
}
527+
516528

517529
#region Everything FastSortWarning
518530

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

+15
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@
281281
<RowDefinition />
282282
<RowDefinition />
283283
<RowDefinition />
284+
<RowDefinition />
284285
</Grid.RowDefinitions>
285286
<TextBlock
286287
Grid.Row="0"
@@ -333,6 +334,20 @@
333334
DisplayMemberPath="Description"
334335
ItemsSource="{Binding PathEnumerationEngines}"
335336
SelectedItem="{Binding SelectedPathEnumerationEngine}" />
337+
<TextBlock
338+
Grid.Row="3"
339+
Grid.Column="0"
340+
Margin="0 15 20 0"
341+
VerticalAlignment="Center"
342+
Text="{DynamicResource plugin_explorer_Excluded_File_Types}"
343+
TextBlock.Foreground="{DynamicResource Color05B}" />
344+
<TextBox
345+
Grid.Row="3"
346+
Grid.Column="1"
347+
MinWidth="350"
348+
Margin="0,9,0,6"
349+
ToolTip="{DynamicResource plugin_explorer_Excluded_File_Types_Tooltip}"
350+
Text="{Binding ExcludedFileTypes}" />
336351
</Grid>
337352
</StackPanel>
338353
<StackPanel Orientation="Horizontal">

0 commit comments

Comments
 (0)