From 35bad615f36f1bd7a6717be4dd6fff19939cefa1 Mon Sep 17 00:00:00 2001 From: Lasith Manujitha Date: Wed, 17 Jul 2024 04:14:18 +0530 Subject: [PATCH 1/4] Add file exclude related settings --- Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs | 2 ++ .../ViewModels/SettingsViewModel.cs | 11 +++++++++++ .../Views/ExplorerSettings.xaml | 15 +++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs index 8a7daf5859d..3d30bcf29e5 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs @@ -25,6 +25,8 @@ public class Settings public string ShellPath { get; set; } = "cmd"; + public string ExcludedFileTypes { get; set; } = ""; + public bool UseLocationAsWorkingDir { get; set; } = false; diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs b/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs index 4185104607c..b0f0c6c7574 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs @@ -513,6 +513,17 @@ public string ShellPath } } + public string ExcludedFileTypes + { + get => Settings.ExcludedFileTypes; + set + { + string sanitized = string.IsNullOrEmpty(value) ? value : value.Replace(" ", "").Replace(".", ""); + Settings.ExcludedFileTypes = sanitized; + OnPropertyChanged(); + } + } + #region Everything FastSortWarning diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml b/Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml index 59d8efc7321..caad341c80b 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml @@ -281,6 +281,7 @@ + + + From b690123a19f3914fe145dd396a9216866853ad4c Mon Sep 17 00:00:00 2001 From: Lasith Manujitha Date: Wed, 17 Jul 2024 04:16:01 +0530 Subject: [PATCH 2/4] Results filter implementation --- .../Languages/en.xaml | 2 ++ .../Search/SearchManager.cs | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml b/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml index 60a15ca3392..bf953582079 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml @@ -64,6 +64,8 @@ Directory Recursive Search Engine Index Search Engine Open Windows Index Option + Ignored File Types (comma seperated) + For example: exe,jpg,png Explorer diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs index f53623ac0c3..41a98b929e6 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs @@ -8,6 +8,7 @@ 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 @@ when ActionKeywordMatch(query, Settings.ActionKeyword.IndexSearchActionKeyword) 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 @@ private bool UseWindowsIndexForDirectorySearch(string locationPath) 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); + } } } From ce489586caaf95bfd71a8e55328a4ef5d9fe2e47 Mon Sep 17 00:00:00 2001 From: Lasith Manujitha Date: Wed, 17 Jul 2024 04:29:30 +0530 Subject: [PATCH 3/4] Add Minor fixes --- Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml | 2 +- .../ViewModels/SettingsViewModel.cs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml b/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml index bf953582079..18fc336758c 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml @@ -64,7 +64,7 @@ Directory Recursive Search Engine Index Search Engine Open Windows Index Option - Ignored File Types (comma seperated) + Excluded File Types (comma seperated) For example: exe,jpg,png diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs b/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs index b0f0c6c7574..729e05ba0f4 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs @@ -518,7 +518,8 @@ public string ExcludedFileTypes get => Settings.ExcludedFileTypes; set { - string sanitized = string.IsNullOrEmpty(value) ? value : value.Replace(" ", "").Replace(".", ""); + // remove spaces and dots from the string before saving + string sanitized = string.IsNullOrEmpty(value) ? "" : value.Replace(" ", "").Replace(".", ""); Settings.ExcludedFileTypes = sanitized; OnPropertyChanged(); } From 0f7bdeec88ac4f2304d54ee095607e897d01b753 Mon Sep 17 00:00:00 2001 From: Lasith Manujitha <64279853+z1nc0r3@users.noreply.github.com> Date: Wed, 17 Jul 2024 11:32:09 +0530 Subject: [PATCH 4/4] Using a case-insensitive comparison Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs index 41a98b929e6..8fd1674765f 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs @@ -258,7 +258,7 @@ private bool IsExcludedFile(SearchResult result) string[] excludedFileTypes = Settings.ExcludedFileTypes.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); string fileExtension = Path.GetExtension(result.FullPath).TrimStart('.'); - return excludedFileTypes.Contains(fileExtension); + return excludedFileTypes.Contains(fileExtension, StringComparer.OrdinalIgnoreCase); } } }