-
-
Notifications
You must be signed in to change notification settings - Fork 463
[FEATURE] Folder and File Action Keywords #4093
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
01Dri
wants to merge
36
commits into
Flow-Launcher:dev
Choose a base branch
from
01Dri:feature/new_action_keywords
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+183
−81
Open
Changes from 33 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
c979609
new keywords in settings
01Dri 531e8c7
settings keywords
01Dri dbe7d52
ActionKeywordConfiguration
01Dri e0a99c5
adjust
01Dri 9209b93
up
01Dri d2dd16b
up
01Dri fbb26e9
switch case adjust
01Dri c90de6f
code quality
01Dri 20959dc
code quality
01Dri 4107b87
code quality
01Dri a4d3c80
Merge branch 'dev' into feature/new_action_keywords
01Dri 30dbdb8
Option to exclude quick access from results
01Dri 0a0cd3e
code quality
01Dri 4e5378b
code quality
01Dri dbf4491
Apply suggestion from @Copilot
Jack251970 945a3d6
Apply suggestion from @Copilot
Jack251970 b67a608
Apply suggestion from @Copilot
Jack251970 dcf4b46
Simplify logic
Jack251970 1d60cb7
Apply suggestion from @Copilot
Jack251970 558967d
Code cleanup
Jack251970 24d212f
Code cleanup
Jack251970 592f60a
Code cleanup
Jack251970 ed5debf
fix: path search trigger in general search
01Dri fc573bd
Merge branch 'dev' into feature/new_action_keywords
01Dri 1cdbdd0
refactor: option to exclude quick access result from action keywords …
01Dri 69e2031
Merge branch 'feature/new_action_keywords' of https://github.com/01Dr…
01Dri 8b7cbf7
up
01Dri 438e709
refactor: GetActiveActionKeywords method doc
01Dri bd8179d
Merge branch 'dev' into feature/new_action_keywords
01Dri 13dad55
refactor: fix search file and folder
01Dri 6da9b80
Merge branch 'feature/new_action_keywords' of https://github.com/01Dr…
01Dri 1150f19
up
01Dri 8e34897
fix PR comments
01Dri b601b00
formatting
jjw24 1f2f474
formatting
jjw24 bb490c0
formatting
jjw24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,15 @@ | ||
| using Flow.Launcher.Plugin.Explorer.Search.DirectoryInfo; | ||
| using Flow.Launcher.Plugin.Explorer.Search.Everything; | ||
| using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks; | ||
| using Flow.Launcher.Plugin.SharedCommands; | ||
| using System; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using System.Windows.Documents; | ||
| using Flow.Launcher.Plugin.Explorer.Exceptions; | ||
| using Flow.Launcher.Plugin.Explorer.Search.DirectoryInfo; | ||
| using Flow.Launcher.Plugin.Explorer.Search.Everything; | ||
| using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks; | ||
| using Flow.Launcher.Plugin.SharedCommands; | ||
| using static Flow.Launcher.Plugin.Explorer.Settings; | ||
| using Path = System.IO.Path; | ||
|
|
||
| namespace Flow.Launcher.Plugin.Explorer.Search | ||
|
|
@@ -18,6 +20,13 @@ | |
|
|
||
| internal Settings Settings; | ||
|
|
||
| private readonly Dictionary<ActionKeyword, List<ResultType>> _typesToFilterByActionKeyword = new() | ||
| { | ||
| { ActionKeyword.FileSearchActionKeyword, [ResultType.Folder, ResultType.Volume] }, | ||
| { ActionKeyword.FolderSearchActionKeyword, [ResultType.File] }, | ||
| }; | ||
|
|
||
|
|
||
| public SearchManager(Settings settings, PluginInitContext context) | ||
| { | ||
| Context = context; | ||
|
|
@@ -31,7 +40,7 @@ | |
| { | ||
| private static PathEqualityComparator instance; | ||
| public static PathEqualityComparator Instance => instance ??= new PathEqualityComparator(); | ||
|
|
||
| public bool Equals(Result x, Result y) | ||
| { | ||
| return x.Title.Equals(y.Title, StringComparison.OrdinalIgnoreCase) | ||
|
|
@@ -47,83 +56,92 @@ | |
| internal async Task<List<Result>> SearchAsync(Query query, CancellationToken token) | ||
| { | ||
| var results = new HashSet<Result>(PathEqualityComparator.Instance); | ||
| var keyword = query.ActionKeyword.Length == 0 ? Query.GlobalPluginWildcardSign : query.ActionKeyword; | ||
| // No action keyword matched - plugin should not handle this query, return empty results. | ||
jjw24 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| var activeActionKeywords = Settings.GetActiveActionKeywords(keyword); | ||
| if (activeActionKeywords.Count == 0) | ||
| { | ||
| return []; | ||
| } | ||
| var isPathSearch = query.Search.IsLocationPathString() | ||
jjw24 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| || EnvironmentVariables.IsEnvironmentVariableSearch(query.Search) | ||
| || EnvironmentVariables.HasEnvironmentVar(query.Search); | ||
|
|
||
| // This allows the user to type the below action keywords and see/search the list of quick folder links | ||
| if (ActionKeywordMatch(query, Settings.ActionKeyword.SearchActionKeyword) | ||
| || ActionKeywordMatch(query, Settings.ActionKeyword.QuickAccessActionKeyword) | ||
| || ActionKeywordMatch(query, Settings.ActionKeyword.PathSearchActionKeyword) | ||
| || ActionKeywordMatch(query, Settings.ActionKeyword.IndexSearchActionKeyword) | ||
| || ActionKeywordMatch(query, Settings.ActionKeyword.FileContentSearchActionKeyword)) | ||
| var queryIsEmpty = string.IsNullOrEmpty(query.Search); | ||
|
|
||
| if (queryIsEmpty && activeActionKeywords.ContainsKey(ActionKeyword.QuickAccessActionKeyword)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| { | ||
| if (string.IsNullOrEmpty(query.Search) && ActionKeywordMatch(query, Settings.ActionKeyword.QuickAccessActionKeyword)) | ||
| return QuickAccess.AccessLinkListAll(query, Settings.QuickAccessLinks); | ||
| return QuickAccess.AccessLinkListAll(query, Settings.QuickAccessLinks); | ||
| } | ||
| else | ||
|
|
||
| // If query is empty and active keyword is folder or search, return empty results. | ||
| if (queryIsEmpty && (activeActionKeywords.ContainsKey(ActionKeyword.FolderSearchActionKeyword) | ||
| || activeActionKeywords.ContainsKey(ActionKeyword.FileSearchActionKeyword))) | ||
| { | ||
| // No action keyword matched- plugin should not handle this query, return empty results. | ||
| return new List<Result>(); | ||
| return []; | ||
| } | ||
|
|
||
| IAsyncEnumerable<SearchResult> searchResults; | ||
| // When file search is active, do not include path search in the active keywords. | ||
| // This prevents unwanted PathSearch results (e.g., drives or raw volume paths). | ||
| if (isPathSearch && !activeActionKeywords.ContainsKey(ActionKeyword.PathSearchActionKeyword) | ||
| && !activeActionKeywords.ContainsKey(ActionKeyword.FileSearchActionKeyword)) | ||
| { | ||
| activeActionKeywords.Add(ActionKeyword.PathSearchActionKeyword, keyword); | ||
| } | ||
|
|
||
| bool isPathSearch = query.Search.IsLocationPathString() | ||
| || EnvironmentVariables.IsEnvironmentVariableSearch(query.Search) | ||
| || EnvironmentVariables.HasEnvironmentVar(query.Search); | ||
| IAsyncEnumerable<SearchResult> searchResults; | ||
|
|
||
| string engineName; | ||
|
|
||
| switch (isPathSearch) | ||
| { | ||
| case true | ||
| when ActionKeywordMatch(query, Settings.ActionKeyword.PathSearchActionKeyword) | ||
| || ActionKeywordMatch(query, Settings.ActionKeyword.SearchActionKeyword): | ||
|
|
||
| when activeActionKeywords.ContainsKey(ActionKeyword.PathSearchActionKeyword) | ||
| || activeActionKeywords.ContainsKey(ActionKeyword.SearchActionKeyword): | ||
| results.UnionWith(await PathSearchAsync(query, token).ConfigureAwait(false)); | ||
|
|
||
| return results.ToList(); | ||
| return [.. results]; | ||
|
|
||
| case false | ||
| when ActionKeywordMatch(query, Settings.ActionKeyword.FileContentSearchActionKeyword): | ||
|
|
||
| // Intentionally require enabling of Everything's content search due to its slowness | ||
| when activeActionKeywords.ContainsKey(ActionKeyword.FileContentSearchActionKeyword): | ||
| if (Settings.ContentIndexProvider is EverythingSearchManager && !Settings.EnableEverythingContentSearch) | ||
| return EverythingContentSearchResult(query); | ||
|
|
||
| searchResults = Settings.ContentIndexProvider.ContentSearchAsync("", query.Search, token); | ||
| engineName = Enum.GetName(Settings.ContentSearchEngine); | ||
| break; | ||
|
|
||
| case false | ||
| when ActionKeywordMatch(query, Settings.ActionKeyword.IndexSearchActionKeyword) | ||
| || ActionKeywordMatch(query, Settings.ActionKeyword.SearchActionKeyword): | ||
| case true or false | ||
| when activeActionKeywords.ContainsKey(ActionKeyword.QuickAccessActionKeyword): | ||
| return QuickAccess.AccessLinkListMatched(query, Settings.QuickAccessLinks); | ||
|
|
||
|
|
||
| case false | ||
| when CanUseIndexSearchByActionKeywords(activeActionKeywords): | ||
| searchResults = Settings.IndexProvider.SearchAsync(query.Search, token); | ||
| engineName = Enum.GetName(Settings.IndexSearchEngine); | ||
| break; | ||
|
|
||
| case true or false | ||
| when ActionKeywordMatch(query, Settings.ActionKeyword.QuickAccessActionKeyword): | ||
| return QuickAccess.AccessLinkListMatched(query, Settings.QuickAccessLinks); | ||
|
|
||
| default: | ||
| return results.ToList(); | ||
| } | ||
| return [..results]; | ||
|
|
||
| // Merge Quick Access Link results for non-path searches. | ||
| results.UnionWith(QuickAccess.AccessLinkListMatched(query, Settings.QuickAccessLinks)); | ||
| } | ||
|
|
||
| //Merge Quick Access Link results for non-path searches. | ||
| results.UnionWith(GetQuickAccessResultsFilteredByActionKeyword(query, activeActionKeywords)); | ||
| try | ||
| { | ||
| await foreach (var search in searchResults.WithCancellation(token).ConfigureAwait(false)) | ||
| if (search.Type == ResultType.File && IsExcludedFile(search)) { | ||
| { | ||
| if (ShouldSkipResultByTypeAndActionKeyword(activeActionKeywords, search)) | ||
| { | ||
| continue; | ||
| } else { | ||
| results.Add(ResultManager.CreateResult(query, search)); | ||
| } | ||
| results.Add(ResultManager.CreateResult(query, search)); | ||
| } | ||
| } | ||
| catch (OperationCanceledException) | ||
| { | ||
| return new List<Result>(); | ||
| return [.. results]; | ||
| } | ||
| catch (EngineNotAvailableException) | ||
| { | ||
|
|
@@ -137,33 +155,13 @@ | |
| results.RemoveWhere(r => Settings.IndexSearchExcludedSubdirectoryPaths.Any( | ||
| excludedPath => FilesFolders.PathContains(excludedPath.Path, r.SubTitle, allowEqual: true))); | ||
|
|
||
| return results.ToList(); | ||
| } | ||
|
|
||
| private bool ActionKeywordMatch(Query query, Settings.ActionKeyword allowedActionKeyword) | ||
| { | ||
| var keyword = query.ActionKeyword.Length == 0 ? Query.GlobalPluginWildcardSign : query.ActionKeyword; | ||
|
|
||
| return allowedActionKeyword switch | ||
| { | ||
| Settings.ActionKeyword.SearchActionKeyword => Settings.SearchActionKeywordEnabled && | ||
| keyword == Settings.SearchActionKeyword, | ||
| Settings.ActionKeyword.PathSearchActionKeyword => Settings.PathSearchKeywordEnabled && | ||
| keyword == Settings.PathSearchActionKeyword, | ||
| Settings.ActionKeyword.FileContentSearchActionKeyword => Settings.FileContentSearchKeywordEnabled && | ||
| keyword == Settings.FileContentSearchActionKeyword, | ||
| Settings.ActionKeyword.IndexSearchActionKeyword => Settings.IndexSearchKeywordEnabled && | ||
| keyword == Settings.IndexSearchActionKeyword, | ||
| Settings.ActionKeyword.QuickAccessActionKeyword => Settings.QuickAccessKeywordEnabled && | ||
| keyword == Settings.QuickAccessActionKeyword, | ||
| _ => throw new ArgumentOutOfRangeException(nameof(allowedActionKeyword), allowedActionKeyword, "actionKeyword out of range") | ||
| }; | ||
| return [.. results]; | ||
| } | ||
|
|
||
| private List<Result> EverythingContentSearchResult(Query query) | ||
| { | ||
| return new List<Result>() | ||
| { | ||
| return | ||
| [ | ||
| new() | ||
| { | ||
| Title = Localize.flowlauncher_plugin_everything_enable_content_search(), | ||
|
|
@@ -176,7 +174,7 @@ | |
| return false; | ||
| } | ||
| } | ||
| }; | ||
| ]; | ||
| } | ||
|
|
||
| private async Task<List<Result>> PathSearchAsync(Query query, CancellationToken token = default) | ||
|
|
@@ -188,7 +186,7 @@ | |
| if (EnvironmentVariables.IsEnvironmentVariableSearch(querySearch)) | ||
| return EnvironmentVariables.GetEnvironmentStringPathSuggestions(querySearch, query, Context); | ||
|
|
||
| // Query is a location path with a full environment variable, eg. %appdata%\somefolder\, c:\users\%USERNAME%\downloads | ||
| var needToExpand = EnvironmentVariables.HasEnvironmentVar(querySearch); | ||
| var path = needToExpand ? Environment.ExpandEnvironmentVariables(querySearch) : querySearch; | ||
|
|
||
|
|
@@ -197,7 +195,7 @@ | |
|
|
||
| // Check that actual location exists, otherwise directory search will throw directory not found exception | ||
| if (!FilesFolders.ReturnPreviousDirectoryIfIncompleteString(path).LocationExists()) | ||
| return results.ToList(); | ||
| return [.. results]; | ||
|
|
||
| var useIndexSearch = Settings.IndexSearchEngine is Settings.IndexSearchEngineOption.WindowsIndex | ||
| && UseWindowsIndexForDirectorySearch(path); | ||
|
|
@@ -209,7 +207,7 @@ | |
| : ResultManager.CreateOpenCurrentFolderResult(retrievedDirectoryPath, query.ActionKeyword, useIndexSearch)); | ||
|
|
||
| if (token.IsCancellationRequested) | ||
| return new List<Result>(); | ||
| return [.. results]; | ||
|
|
||
| IAsyncEnumerable<SearchResult> directoryResult; | ||
|
|
||
|
|
@@ -231,7 +229,7 @@ | |
| } | ||
|
|
||
| if (token.IsCancellationRequested) | ||
| return new List<Result>(); | ||
| return [.. results]; | ||
|
|
||
| try | ||
| { | ||
|
|
@@ -246,14 +244,14 @@ | |
| } | ||
|
|
||
|
|
||
| return results.ToList(); | ||
| return [.. results]; | ||
| } | ||
|
|
||
| public bool IsFileContentSearch(string actionKeyword) => actionKeyword == Settings.FileContentSearchActionKeyword; | ||
|
|
||
| public static bool UseIndexSearch(string path) | ||
| { | ||
| if (Main.Settings.IndexSearchEngine is not Settings.IndexSearchEngineOption.WindowsIndex) | ||
| if (Main.Settings.IndexSearchEngine is not IndexSearchEngineOption.WindowsIndex) | ||
| return false; | ||
|
|
||
| // Check if the path is using windows index search | ||
|
|
@@ -275,10 +273,67 @@ | |
|
|
||
| private bool IsExcludedFile(SearchResult result) | ||
| { | ||
| string[] excludedFileTypes = Settings.ExcludedFileTypes.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); | ||
| string[] excludedFileTypes = Settings.ExcludedFileTypes.Split([','], StringSplitOptions.RemoveEmptyEntries); | ||
| string fileExtension = Path.GetExtension(result.FullPath).TrimStart('.'); | ||
|
|
||
| return excludedFileTypes.Contains(fileExtension, StringComparer.OrdinalIgnoreCase); | ||
| } | ||
|
|
||
| private bool ShouldSkipResultByTypeAndActionKeyword(Dictionary<ActionKeyword, string> actions, SearchResult search) | ||
| { | ||
| // Is excluded file type | ||
| if (search.Type == ResultType.File && IsExcludedFile(search)) | ||
| { | ||
| return true; | ||
| } | ||
| return IsResultTypeFilteredByActionKeyword(search.Type, actions); | ||
|
|
||
| } | ||
|
|
||
| private List<Result> GetQuickAccessResultsFilteredByActionKeyword(Query query, Dictionary<ActionKeyword, string> actions) | ||
| { | ||
| var results = QuickAccess.AccessLinkListMatched(query, Settings.QuickAccessLinks) ?? []; | ||
| if (results.Count == 0) | ||
| { | ||
| return results; | ||
| } | ||
|
|
||
| return results | ||
| .Where(r => r.ContextData is SearchResult result | ||
| && !IsResultTypeFilteredByActionKeyword(result.Type, actions)) | ||
| .ToList(); | ||
| } | ||
| private bool IsResultTypeFilteredByActionKeyword(ResultType type, Dictionary<ActionKeyword, string> actions) | ||
| { | ||
| foreach (var action in actions.Keys) | ||
| { | ||
| if (_typesToFilterByActionKeyword.TryGetValue(action, out var typesToFilter)) | ||
| { | ||
| return typesToFilter.Contains(type); | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| private bool CanUseIndexSearchByActionKeywords(Dictionary<ActionKeyword, string> actions) | ||
| { | ||
| List<ActionKeyword> keysToUseSearch = | ||
| [ | ||
| ActionKeyword.FileSearchActionKeyword, | ||
| ActionKeyword.FolderSearchActionKeyword, | ||
| ActionKeyword.IndexSearchActionKeyword, | ||
| ActionKeyword.SearchActionKeyword | ||
| ]; | ||
| foreach (var key in keysToUseSearch) | ||
| { | ||
| var contains = actions.ContainsKey(key); | ||
| if (!contains) continue; | ||
| return contains; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.


Uh oh!
There was an error while loading. Please reload this page.