Skip to content

Commit acba2dd

Browse files
committed
Add specific keyword for path explore in explorer plugin
1 parent d813a47 commit acba2dd

File tree

12 files changed

+106
-47
lines changed

12 files changed

+106
-47
lines changed

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[*.cs]
2+
3+
# IDE0011: 添加大括号
4+
csharp_prefer_braces = when_multiline

Flow.Launcher.Test/Flow.Launcher.Test.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
<Compile Include="..\SolutionAssemblyInfo.cs" Link="Properties\SolutionAssemblyInfo.cs" />
3939
</ItemGroup>
4040

41+
<ItemGroup>
42+
<None Include="..\.editorconfig" Link=".editorconfig" />
43+
</ItemGroup>
44+
4145
<ItemGroup>
4246
<ProjectReference Include="..\Plugins\Flow.Launcher.Plugin.Explorer\Flow.Launcher.Plugin.Explorer.csproj" />
4347
<ProjectReference Include="..\Plugins\Flow.Launcher.Plugin.Program\Flow.Launcher.Plugin.Program.csproj" />

Flow.Launcher.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Flow.Launcher.Plugin.Url",
4545
EndProject
4646
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{FFD651C7-0546-441F-BC8C-D4EE8FD01EA7}"
4747
ProjectSection(SolutionItems) = preProject
48+
.editorconfig = .editorconfig
4849
.gitattributes = .gitattributes
4950
.gitignore = .gitignore
5051
appveyor.yml = appveyor.yml

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
<system:String x:Key="plugin_explorer_quickaccesslinks_header">Quick Access Links</system:String>
2020
<system:String x:Key="plugin_explorer_indexsearchexcludedpaths_header">Index Search Excluded Paths</system:String>
2121
<system:String x:Key="plugin_explorer_manageindexoptions">Indexing Options</system:String>
22-
<system:String x:Key="plugin_explorer_actionkeywordview_search">Search Activation:</system:String>
22+
<system:String x:Key="plugin_explorer_actionkeywordview_search">Index Search Activation:</system:String>
23+
<system:String x:Key="plugin_explorer_actionkeywordview_path">Path Explore Activation:</system:String>
2324
<system:String x:Key="plugin_explorer_actionkeywordview_filecontentsearch">File Content Search:</system:String>
2425

2526
<!--Plugin Infos-->

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public Control CreateSettingPanel()
2828
return new ExplorerSettings(viewModel);
2929
}
3030

31-
public async Task InitAsync(PluginInitContext context)
31+
public Task InitAsync(PluginInitContext context)
3232
{
3333
Context = context;
3434

@@ -47,6 +47,8 @@ public async Task InitAsync(PluginInitContext context)
4747
contextMenu = new ContextMenu(Context, Settings, viewModel);
4848
searchManager = new SearchManager(Settings, Context);
4949
ResultManager.Init(Context);
50+
51+
return Task.CompletedTask;
5052
}
5153

5254
public List<Result> LoadContextMenus(Result selectedResult)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ public static class EnvironmentVariables
1010
{
1111
internal static bool IsEnvironmentVariableSearch(string search)
1212
{
13-
return LoadEnvironmentStringPaths().Count > 0
14-
&& search.StartsWith("%")
13+
return search.StartsWith("%")
1514
&& search != "%%"
16-
&& !search.Contains("\\");
15+
&& !search.Contains("\\") &&
16+
LoadEnvironmentStringPaths().Count > 0;
1717
}
1818

1919
internal static Dictionary<string, string> LoadEnvironmentStringPaths()

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

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,47 @@ public int GetHashCode(Result obj)
3939

4040
internal async Task<List<Result>> SearchAsync(Query query, CancellationToken token)
4141
{
42-
var results = new HashSet<Result>(PathEqualityComparator.Instance);
43-
4442
var querySearch = query.Search;
4543

4644
if (IsFileContentSearch(query.ActionKeyword))
4745
return await WindowsIndexFileContentSearchAsync(query, querySearch, token).ConfigureAwait(false);
4846

47+
var result = new HashSet<Result>(PathEqualityComparator.Instance);
48+
49+
if (ActionKeywordMatch(query, settings.PathSearchActionKeyword))
50+
{
51+
result.UnionWith(await PathSearchAsync(query, token).ConfigureAwait(false));
52+
}
53+
54+
if (ActionKeywordMatch(query, settings.SearchActionKeyword) &&
55+
querySearch.Length > 0 &&
56+
!querySearch.IsLocationPathString())
57+
{
58+
result.UnionWith(await WindowsIndexFilesAndFoldersSearchAsync(query, querySearch, token).ConfigureAwait(false));
59+
}
60+
61+
return result.ToList();
62+
}
63+
64+
private bool ActionKeywordMatch(Query query, string actionKeyword)
65+
{
66+
return query.ActionKeyword == actionKeyword ||
67+
query.ActionKeyword.Length == 0 && actionKeyword == Query.GlobalPluginWildcardSign;
68+
}
69+
70+
public async Task<List<Result>> PathSearchAsync(Query query, CancellationToken token = default)
71+
{
72+
var querySearch = query.Search;
73+
4974
// This allows the user to type the assigned action keyword and only see the list of quick folder links
5075
if (string.IsNullOrEmpty(query.Search))
5176
return QuickAccess.AccessLinkListAll(query, settings.QuickAccessLinks);
5277

78+
var results = new HashSet<Result>(PathEqualityComparator.Instance);
79+
5380
var quickaccessLinks = QuickAccess.AccessLinkListMatched(query, settings.QuickAccessLinks);
5481

55-
if (quickaccessLinks.Count > 0)
56-
results.UnionWith(quickaccessLinks);
82+
results.UnionWith(quickaccessLinks);
5783

5884
var isEnvironmentVariable = EnvironmentVariables.IsEnvironmentVariableSearch(querySearch);
5985

@@ -63,13 +89,6 @@ internal async Task<List<Result>> SearchAsync(Query query, CancellationToken tok
6389
// Query is a location path with a full environment variable, eg. %appdata%\somefolder\
6490
var isEnvironmentVariablePath = querySearch[1..].Contains("%\\");
6591

66-
if (!querySearch.IsLocationPathString() && !isEnvironmentVariablePath)
67-
{
68-
results.UnionWith(await WindowsIndexFilesAndFoldersSearchAsync(query, querySearch, token).ConfigureAwait(false));
69-
70-
return results.ToList();
71-
}
72-
7392
var locationPath = querySearch;
7493

7594
if (isEnvironmentVariablePath)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@ public class Settings
2020
public string SearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign;
2121

2222
public string FileContentSearchActionKeyword { get; set; } = Constants.DefaultContentSearchActionKeyword;
23+
24+
public string PathSearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign;
2325
}
2426
}

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

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,36 @@ internal void OpenWindowsIndexingOptions()
4141
Process.Start(psi);
4242
}
4343

44-
internal void UpdateActionKeyword(string newActionKeyword, string oldActionKeyword)
44+
internal void UpdateActionKeyword(ActionKeywordProperty modifiedActionKeyword, string newActionKeyword, string oldActionKeyword)
4545
{
46-
PluginManager.ReplaceActionKeyword(Context.CurrentPluginMetadata.ID, oldActionKeyword, newActionKeyword);
46+
if (Settings.SearchActionKeyword == Settings.PathSearchActionKeyword)
47+
PluginManager.AddActionKeyword(Context.CurrentPluginMetadata.ID, newActionKeyword);
48+
else
49+
PluginManager.ReplaceActionKeyword(Context.CurrentPluginMetadata.ID, oldActionKeyword, newActionKeyword);
4750

48-
if (Settings.FileContentSearchActionKeyword == oldActionKeyword)
49-
Settings.FileContentSearchActionKeyword = newActionKeyword;
50-
51-
if (Settings.SearchActionKeyword == oldActionKeyword)
52-
Settings.SearchActionKeyword = newActionKeyword;
51+
switch (modifiedActionKeyword)
52+
{
53+
case ActionKeywordProperty.SearchActionKeyword:
54+
Settings.SearchActionKeyword = newActionKeyword;
55+
break;
56+
case ActionKeywordProperty.PathSearchActionKeyword:
57+
Settings.PathSearchActionKeyword = newActionKeyword;
58+
break;
59+
case ActionKeywordProperty.FileContentSearchActionKeyword:
60+
Settings.FileContentSearchActionKeyword = newActionKeyword;
61+
break;
62+
}
5363
}
5464

5565
internal bool IsActionKeywordAlreadyAssigned(string newActionKeyword) => PluginManager.ActionKeywordRegistered(newActionKeyword);
5666

5767
internal bool IsNewActionKeywordGlobal(string newActionKeyword) => newActionKeyword == Query.GlobalPluginWildcardSign;
5868
}
69+
70+
public enum ActionKeywordProperty
71+
{
72+
SearchActionKeyword,
73+
PathSearchActionKeyword,
74+
FileContentSearchActionKeyword
75+
}
5976
}

Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public partial class ActionKeywordSetting : Window
2323

2424
private ActionKeywordView currentActionKeyword;
2525

26+
2627
private List<ActionKeywordView> actionKeywordListView;
2728

2829
public ActionKeywordSetting(SettingsViewModel settingsViewModel, List<ActionKeywordView> actionKeywordListView, ActionKeywordView selectedActionKeyword)
@@ -35,7 +36,7 @@ public ActionKeywordSetting(SettingsViewModel settingsViewModel, List<ActionKeyw
3536

3637
txtCurrentActionKeyword.Text = selectedActionKeyword.Keyword;
3738

38-
this.actionKeywordListView = actionKeywordListView;
39+
this.actionKeywordListView = actionKeywordListView;
3940
}
4041

4142
private void OnConfirmButtonClick(object sender, RoutedEventArgs e)
@@ -52,20 +53,19 @@ private void OnConfirmButtonClick(object sender, RoutedEventArgs e)
5253
return;
5354
}
5455

55-
if (settingsViewModel.IsNewActionKeywordGlobal(newActionKeyword)
56-
&& currentActionKeyword.Description
57-
== settingsViewModel.Context.API.GetTranslation("plugin_explorer_actionkeywordview_filecontentsearch"))
56+
if (settingsViewModel.IsNewActionKeywordGlobal(newActionKeyword)
57+
&& currentActionKeyword.KeywordProperty == ActionKeywordProperty.FileContentSearchActionKeyword)
5858
{
5959
MessageBox.Show(settingsViewModel.Context.API.GetTranslation("plugin_explorer_globalActionKeywordInvalid"));
6060

6161
return;
6262
}
63-
63+
6464
if (!settingsViewModel.IsActionKeywordAlreadyAssigned(newActionKeyword))
6565
{
66-
settingsViewModel.UpdateActionKeyword(newActionKeyword, currentActionKeyword.Keyword);
66+
settingsViewModel.UpdateActionKeyword(currentActionKeyword.KeywordProperty, newActionKeyword, currentActionKeyword.Keyword);
6767

68-
actionKeywordListView.Where(x => x.Description == currentActionKeyword.Description).FirstOrDefault().Keyword = newActionKeyword;
68+
actionKeywordListView.FirstOrDefault(x => x.Description == currentActionKeyword.Description).Keyword = newActionKeyword;
6969

7070
Close();
7171

0 commit comments

Comments
 (0)