Skip to content

Commit 9d7ff08

Browse files
authored
Merge pull request #457 from Flow-Launcher/add_explorer_path
update to ExplorerPathActionkeyword branch
2 parents e4a15b4 + 5966ddc commit 9d7ff08

File tree

10 files changed

+221
-113
lines changed

10 files changed

+221
-113
lines changed

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ public static void AddActionKeyword(string id, string newActionKeyword)
274274
}
275275

276276
/// <summary>
277-
/// used to add action keyword for multiple action keyword plugin
277+
/// used to remove action keyword for multiple action keyword plugin
278278
/// e.g. web search
279279
/// </summary>
280280
public static void RemoveActionKeyword(string id, string oldActionkeyword)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
<system:String x:Key="plugin_explorer_actionkeywordview_search">Index Search Activation:</system:String>
2323
<system:String x:Key="plugin_explorer_actionkeywordview_path">Path Explore Activation:</system:String>
2424
<system:String x:Key="plugin_explorer_actionkeywordview_filecontentsearch">File Content Search:</system:String>
25+
<system:String x:Key="plugin_explorer_actionkeywordview_indexonlysearch">Index Only Search:</system:String>
26+
<system:String x:Key="plugin_explorer_actionkeywordview_brackets_disabled">(Disabled)</system:String>
2527

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

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

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ private class PathEqualityComparator : IEqualityComparer<Result>
2626
{
2727
private static PathEqualityComparator instance;
2828
public static PathEqualityComparator Instance => instance ??= new PathEqualityComparator();
29+
2930
public bool Equals(Result x, Result y)
3031
{
3132
return x.SubTitle == y.SubTitle;
@@ -46,25 +47,39 @@ internal async Task<List<Result>> SearchAsync(Query query, CancellationToken tok
4647

4748
var result = new HashSet<Result>(PathEqualityComparator.Instance);
4849

49-
if (ActionKeywordMatch(query, settings.PathSearchActionKeyword))
50+
if (ActionKeywordMatch(query, Settings.ActionKeyword.PathSearchActionKeyword) ||
51+
ActionKeywordMatch(query, Settings.ActionKeyword.SearchActionKeyword))
5052
{
5153
result.UnionWith(await PathSearchAsync(query, token).ConfigureAwait(false));
5254
}
5355

54-
if (ActionKeywordMatch(query, settings.SearchActionKeyword) &&
55-
querySearch.Length > 0 &&
56-
!querySearch.IsLocationPathString())
56+
if ((ActionKeywordMatch(query, Settings.ActionKeyword.IndexOnlySearchActionKeyword) ||
57+
ActionKeywordMatch(query, Settings.ActionKeyword.SearchActionKeyword)) &&
58+
querySearch.Length > 0 &&
59+
!querySearch.IsLocationPathString())
5760
{
58-
result.UnionWith(await WindowsIndexFilesAndFoldersSearchAsync(query, querySearch, token).ConfigureAwait(false));
61+
result.UnionWith(await WindowsIndexFilesAndFoldersSearchAsync(query, querySearch, token)
62+
.ConfigureAwait(false));
5963
}
6064

6165
return result.ToList();
6266
}
6367

64-
private bool ActionKeywordMatch(Query query, string actionKeyword)
68+
private bool ActionKeywordMatch(Query query, Settings.ActionKeyword allowedActionKeyword)
6569
{
66-
return query.ActionKeyword == actionKeyword ||
67-
query.ActionKeyword.Length == 0 && actionKeyword == Query.GlobalPluginWildcardSign;
70+
var keyword = query.ActionKeyword.Length == 0 ? "*" : query.ActionKeyword;
71+
72+
return allowedActionKeyword switch
73+
{
74+
Settings.ActionKeyword.SearchActionKeyword => settings.EnableSearchActionKeyword &&
75+
keyword == settings.SearchActionKeyword,
76+
Settings.ActionKeyword.PathSearchActionKeyword => settings.EnabledPathSearchKeyword &&
77+
keyword == settings.PathSearchActionKeyword,
78+
Settings.ActionKeyword.FileContentSearchActionKeyword => keyword ==
79+
settings.FileContentSearchActionKeyword,
80+
Settings.ActionKeyword.IndexOnlySearchActionKeyword => settings.EnabledIndexOnlySearchKeyword &&
81+
keyword == settings.IndexOnlySearchActionKeyword
82+
};
6883
}
6984

7085
public async Task<List<Result>> PathSearchAsync(Query query, CancellationToken token = default)
@@ -118,19 +133,20 @@ public async Task<List<Result>> PathSearchAsync(Query query, CancellationToken t
118133
return results.ToList();
119134
}
120135

121-
private async Task<List<Result>> WindowsIndexFileContentSearchAsync(Query query, string querySearchString, CancellationToken token)
136+
private async Task<List<Result>> WindowsIndexFileContentSearchAsync(Query query, string querySearchString,
137+
CancellationToken token)
122138
{
123139
var queryConstructor = new QueryConstructor(settings);
124140

125141
if (string.IsNullOrEmpty(querySearchString))
126142
return new List<Result>();
127143

128144
return await IndexSearch.WindowsIndexSearchAsync(querySearchString,
129-
queryConstructor.CreateQueryHelper().ConnectionString,
130-
queryConstructor.QueryForFileContentSearch,
131-
settings.IndexSearchExcludedSubdirectoryPaths,
132-
query,
133-
token).ConfigureAwait(false);
145+
queryConstructor.CreateQueryHelper().ConnectionString,
146+
queryConstructor.QueryForFileContentSearch,
147+
settings.IndexSearchExcludedSubdirectoryPaths,
148+
query,
149+
token).ConfigureAwait(false);
134150
}
135151

136152
public bool IsFileContentSearch(string actionKeyword)
@@ -157,28 +173,30 @@ public async Task<List<Result>> TopLevelDirectorySearchBehaviourAsync(
157173
return await windowsIndexSearch(query, querySearchString, token);
158174
}
159175

160-
private async Task<List<Result>> WindowsIndexFilesAndFoldersSearchAsync(Query query, string querySearchString, CancellationToken token)
176+
private async Task<List<Result>> WindowsIndexFilesAndFoldersSearchAsync(Query query, string querySearchString,
177+
CancellationToken token)
161178
{
162179
var queryConstructor = new QueryConstructor(settings);
163180

164181
return await IndexSearch.WindowsIndexSearchAsync(querySearchString,
165-
queryConstructor.CreateQueryHelper().ConnectionString,
166-
queryConstructor.QueryForAllFilesAndFolders,
167-
settings.IndexSearchExcludedSubdirectoryPaths,
168-
query,
169-
token).ConfigureAwait(false);
182+
queryConstructor.CreateQueryHelper().ConnectionString,
183+
queryConstructor.QueryForAllFilesAndFolders,
184+
settings.IndexSearchExcludedSubdirectoryPaths,
185+
query,
186+
token).ConfigureAwait(false);
170187
}
171188

172-
private async Task<List<Result>> WindowsIndexTopLevelFolderSearchAsync(Query query, string path, CancellationToken token)
189+
private async Task<List<Result>> WindowsIndexTopLevelFolderSearchAsync(Query query, string path,
190+
CancellationToken token)
173191
{
174192
var queryConstructor = new QueryConstructor(settings);
175193

176194
return await IndexSearch.WindowsIndexSearchAsync(path,
177-
queryConstructor.CreateQueryHelper().ConnectionString,
178-
queryConstructor.QueryForTopLevelDirectorySearch,
179-
settings.IndexSearchExcludedSubdirectoryPaths,
180-
query,
181-
token).ConfigureAwait(false);
195+
queryConstructor.CreateQueryHelper().ConnectionString,
196+
queryConstructor.QueryForTopLevelDirectorySearch,
197+
settings.IndexSearchExcludedSubdirectoryPaths,
198+
query,
199+
token).ConfigureAwait(false);
182200
}
183201

184202
private bool UseWindowsIndexForDirectorySearch(string locationPath)
@@ -189,11 +207,11 @@ private bool UseWindowsIndexForDirectorySearch(string locationPath)
189207
return false;
190208

191209
if (settings.IndexSearchExcludedSubdirectoryPaths
192-
.Any(x => FilesFolders.ReturnPreviousDirectoryIfIncompleteString(pathToDirectory)
193-
.StartsWith(x.Path, StringComparison.OrdinalIgnoreCase)))
210+
.Any(x => FilesFolders.ReturnPreviousDirectoryIfIncompleteString(pathToDirectory)
211+
.StartsWith(x.Path, StringComparison.OrdinalIgnoreCase)))
194212
return false;
195213

196214
return IndexSearch.PathIsIndexed(pathToDirectory);
197215
}
198216
}
199-
}
217+
}

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using Flow.Launcher.Plugin.Explorer.Search;
22
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;
3+
using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption;
4+
using System;
35
using System.Collections.Generic;
6+
using System.IO;
47

58
namespace Flow.Launcher.Plugin.Explorer
69
{
@@ -18,9 +21,57 @@ public class Settings
1821
public List<AccessLink> IndexSearchExcludedSubdirectoryPaths { get; set; } = new List<AccessLink>();
1922

2023
public string SearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign;
24+
public bool EnableSearchActionKeyword { get; set; } = true;
2125

2226
public string FileContentSearchActionKeyword { get; set; } = Constants.DefaultContentSearchActionKeyword;
2327

2428
public string PathSearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign;
29+
30+
public bool EnabledPathSearchKeyword { get; set; }
31+
32+
public string IndexOnlySearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign;
33+
34+
public bool EnabledIndexOnlySearchKeyword { get; set; }
35+
36+
internal enum ActionKeyword
37+
{
38+
SearchActionKeyword,
39+
PathSearchActionKeyword,
40+
FileContentSearchActionKeyword,
41+
IndexOnlySearchActionKeyword
42+
}
43+
44+
internal string GetActionKeyword(ActionKeyword actionKeyword) => actionKeyword switch
45+
{
46+
ActionKeyword.SearchActionKeyword => SearchActionKeyword,
47+
ActionKeyword.PathSearchActionKeyword => PathSearchActionKeyword,
48+
ActionKeyword.FileContentSearchActionKeyword => FileContentSearchActionKeyword,
49+
ActionKeyword.IndexOnlySearchActionKeyword => IndexOnlySearchActionKeyword
50+
};
51+
52+
internal void SetActionKeyword(ActionKeyword actionKeyword, string keyword) => _ = actionKeyword switch
53+
{
54+
ActionKeyword.SearchActionKeyword => SearchActionKeyword = keyword,
55+
ActionKeyword.PathSearchActionKeyword => PathSearchActionKeyword = keyword,
56+
ActionKeyword.FileContentSearchActionKeyword => FileContentSearchActionKeyword = keyword,
57+
ActionKeyword.IndexOnlySearchActionKeyword => IndexOnlySearchActionKeyword = keyword,
58+
_ => throw new ArgumentOutOfRangeException(nameof(actionKeyword), actionKeyword, "Unexpected property")
59+
};
60+
61+
internal bool? GetActionKeywordEnable(ActionKeyword actionKeyword) => actionKeyword switch
62+
{
63+
ActionKeyword.SearchActionKeyword => EnableSearchActionKeyword,
64+
ActionKeyword.PathSearchActionKeyword => EnabledPathSearchKeyword,
65+
ActionKeyword.IndexOnlySearchActionKeyword => EnabledIndexOnlySearchKeyword,
66+
_ => null
67+
};
68+
69+
internal void SetActionKeywordEnable(ActionKeyword actionKeyword, bool enable) => _ = actionKeyword switch
70+
{
71+
ActionKeyword.SearchActionKeyword => EnableSearchActionKeyword = enable,
72+
ActionKeyword.PathSearchActionKeyword => EnabledPathSearchKeyword = enable,
73+
ActionKeyword.IndexOnlySearchActionKeyword => EnabledIndexOnlySearchKeyword = enable,
74+
_ => throw new ArgumentOutOfRangeException(nameof(actionKeyword), actionKeyword, "Unexpected property")
75+
};
2576
}
2677
}

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

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

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

5148
switch (modifiedActionKeyword)
5249
{
53-
case ActionKeywordProperty.SearchActionKeyword:
50+
case Settings.ActionKeyword.SearchActionKeyword:
5451
Settings.SearchActionKeyword = newActionKeyword;
5552
break;
56-
case ActionKeywordProperty.PathSearchActionKeyword:
53+
case Settings.ActionKeyword.PathSearchActionKeyword:
5754
Settings.PathSearchActionKeyword = newActionKeyword;
5855
break;
59-
case ActionKeywordProperty.FileContentSearchActionKeyword:
56+
case Settings.ActionKeyword.FileContentSearchActionKeyword:
6057
Settings.FileContentSearchActionKeyword = newActionKeyword;
6158
break;
59+
case Settings.ActionKeyword.IndexOnlySearchActionKeyword:
60+
Settings.IndexOnlySearchActionKeyword = newActionKeyword;
61+
break;
6262
}
6363
}
6464

6565
internal bool IsActionKeywordAlreadyAssigned(string newActionKeyword) => PluginManager.ActionKeywordRegistered(newActionKeyword);
6666

6767
internal bool IsNewActionKeywordGlobal(string newActionKeyword) => newActionKeyword == Query.GlobalPluginWildcardSign;
6868
}
69-
70-
public enum ActionKeywordProperty
71-
{
72-
SearchActionKeyword,
73-
PathSearchActionKeyword,
74-
FileContentSearchActionKeyword
75-
}
7669
}

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
mc:Ignorable="d"
88
ResizeMode="NoResize"
99
WindowStartupLocation="CenterScreen"
10+
DataContext="{Binding RelativeSource={RelativeSource Self}}"
1011
Title="Action Keyword Setting" Height="200" Width="500">
1112
<Grid>
1213
<Grid.RowDefinitions>
@@ -16,15 +17,20 @@
1617
<Grid.ColumnDefinitions>
1718
<ColumnDefinition Width="180" />
1819
<ColumnDefinition />
20+
<ColumnDefinition />
1921
</Grid.ColumnDefinitions>
2022
<TextBlock Margin="20 10 10 10" FontSize="14" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center"
2123
HorizontalAlignment="Left" Text="Current Action Keyword:" />
22-
<TextBox Name="txtCurrentActionKeyword"
24+
<TextBox Name="TxtCurrentActionKeyword"
2325
Margin="10" Grid.Row="0" Width="105" Grid.Column="1"
2426
VerticalAlignment="Center"
25-
HorizontalAlignment="Left" />
26-
27-
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="1" Grid.Column="1">
27+
HorizontalAlignment="Left"
28+
Text="{Binding CurrentActionKeyword.Keyword}" />
29+
<CheckBox Name="ChkActionKeywordEnabled" Margin="10" Grid.Row="0" Grid.Column="2" Content="Enabled"
30+
Width="auto"
31+
VerticalAlignment="Center" IsChecked="{Binding CurrentActionKeyword.Enabled}"
32+
Visibility="{Binding Visible}"/>
33+
<StackPanel Orientation="Horizontal" Grid.Column="1" Grid.ColumnSpan="2" Margin="100 92 0 0" Grid.RowSpan="2">
2834
<Button Click="OnConfirmButtonClick"
2935
Margin="10 0 10 0" Width="80" Height="35"
3036
Content="OK" />
@@ -33,4 +39,4 @@
3339
Content="Cancel" />
3440
</StackPanel>
3541
</Grid>
36-
</Window>
42+
</Window>

0 commit comments

Comments
 (0)