Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Flow.Launcher.Core/Plugin/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public static void AddActionKeyword(string id, string newActionKeyword)
}

/// <summary>
/// used to add action keyword for multiple action keyword plugin
/// used to remove action keyword for multiple action keyword plugin
/// e.g. web search
/// </summary>
public static void RemoveActionKeyword(string id, string oldActionkeyword)
Expand Down
2 changes: 2 additions & 0 deletions Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<system:String x:Key="plugin_explorer_actionkeywordview_search">Index Search Activation:</system:String>
<system:String x:Key="plugin_explorer_actionkeywordview_path">Path Explore Activation:</system:String>
<system:String x:Key="plugin_explorer_actionkeywordview_filecontentsearch">File Content Search:</system:String>
<system:String x:Key="plugin_explorer_actionkeywordview_indexonlysearch">Index Only Search:</system:String>
<system:String x:Key="plugin_explorer_actionkeywordview_brackets_disabled">(Disabled)</system:String>

<!--Plugin Infos-->
<system:String x:Key="plugin_explorer_plugin_name">Explorer</system:String>
Expand Down
76 changes: 47 additions & 29 deletions Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ private class PathEqualityComparator : IEqualityComparer<Result>
{
private static PathEqualityComparator instance;
public static PathEqualityComparator Instance => instance ??= new PathEqualityComparator();

public bool Equals(Result x, Result y)
{
return x.SubTitle == y.SubTitle;
Expand All @@ -46,25 +47,39 @@ internal async Task<List<Result>> SearchAsync(Query query, CancellationToken tok

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

if (ActionKeywordMatch(query, settings.PathSearchActionKeyword))
if (ActionKeywordMatch(query, Settings.ActionKeyword.PathSearchActionKeyword) ||
ActionKeywordMatch(query, Settings.ActionKeyword.SearchActionKeyword))
{
result.UnionWith(await PathSearchAsync(query, token).ConfigureAwait(false));
}

if (ActionKeywordMatch(query, settings.SearchActionKeyword) &&
querySearch.Length > 0 &&
!querySearch.IsLocationPathString())
if ((ActionKeywordMatch(query, Settings.ActionKeyword.IndexOnlySearchActionKeyword) ||
ActionKeywordMatch(query, Settings.ActionKeyword.SearchActionKeyword)) &&
querySearch.Length > 0 &&
!querySearch.IsLocationPathString())
{
result.UnionWith(await WindowsIndexFilesAndFoldersSearchAsync(query, querySearch, token).ConfigureAwait(false));
result.UnionWith(await WindowsIndexFilesAndFoldersSearchAsync(query, querySearch, token)
.ConfigureAwait(false));
}

return result.ToList();
}

private bool ActionKeywordMatch(Query query, string actionKeyword)
private bool ActionKeywordMatch(Query query, Settings.ActionKeyword allowedActionKeyword)
{
return query.ActionKeyword == actionKeyword ||
query.ActionKeyword.Length == 0 && actionKeyword == Query.GlobalPluginWildcardSign;
var keyword = query.ActionKeyword.Length == 0 ? "*" : query.ActionKeyword;

return allowedActionKeyword switch
{
Settings.ActionKeyword.SearchActionKeyword => settings.EnableSearchActionKeyword &&
keyword == settings.SearchActionKeyword,
Settings.ActionKeyword.PathSearchActionKeyword => settings.EnabledPathSearchKeyword &&
keyword == settings.PathSearchActionKeyword,
Settings.ActionKeyword.FileContentSearchActionKeyword => keyword ==
settings.FileContentSearchActionKeyword,
Settings.ActionKeyword.IndexOnlySearchActionKeyword => settings.EnabledIndexOnlySearchKeyword &&
keyword == settings.IndexOnlySearchActionKeyword
};
}

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

private async Task<List<Result>> WindowsIndexFileContentSearchAsync(Query query, string querySearchString, CancellationToken token)
private async Task<List<Result>> WindowsIndexFileContentSearchAsync(Query query, string querySearchString,
CancellationToken token)
{
var queryConstructor = new QueryConstructor(settings);

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

return await IndexSearch.WindowsIndexSearchAsync(querySearchString,
queryConstructor.CreateQueryHelper().ConnectionString,
queryConstructor.QueryForFileContentSearch,
settings.IndexSearchExcludedSubdirectoryPaths,
query,
token).ConfigureAwait(false);
queryConstructor.CreateQueryHelper().ConnectionString,
queryConstructor.QueryForFileContentSearch,
settings.IndexSearchExcludedSubdirectoryPaths,
query,
token).ConfigureAwait(false);
}

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

private async Task<List<Result>> WindowsIndexFilesAndFoldersSearchAsync(Query query, string querySearchString, CancellationToken token)
private async Task<List<Result>> WindowsIndexFilesAndFoldersSearchAsync(Query query, string querySearchString,
CancellationToken token)
{
var queryConstructor = new QueryConstructor(settings);

return await IndexSearch.WindowsIndexSearchAsync(querySearchString,
queryConstructor.CreateQueryHelper().ConnectionString,
queryConstructor.QueryForAllFilesAndFolders,
settings.IndexSearchExcludedSubdirectoryPaths,
query,
token).ConfigureAwait(false);
queryConstructor.CreateQueryHelper().ConnectionString,
queryConstructor.QueryForAllFilesAndFolders,
settings.IndexSearchExcludedSubdirectoryPaths,
query,
token).ConfigureAwait(false);
}

private async Task<List<Result>> WindowsIndexTopLevelFolderSearchAsync(Query query, string path, CancellationToken token)
private async Task<List<Result>> WindowsIndexTopLevelFolderSearchAsync(Query query, string path,
CancellationToken token)
{
var queryConstructor = new QueryConstructor(settings);

return await IndexSearch.WindowsIndexSearchAsync(path,
queryConstructor.CreateQueryHelper().ConnectionString,
queryConstructor.QueryForTopLevelDirectorySearch,
settings.IndexSearchExcludedSubdirectoryPaths,
query,
token).ConfigureAwait(false);
queryConstructor.CreateQueryHelper().ConnectionString,
queryConstructor.QueryForTopLevelDirectorySearch,
settings.IndexSearchExcludedSubdirectoryPaths,
query,
token).ConfigureAwait(false);
}

private bool UseWindowsIndexForDirectorySearch(string locationPath)
Expand All @@ -189,11 +207,11 @@ private bool UseWindowsIndexForDirectorySearch(string locationPath)
return false;

if (settings.IndexSearchExcludedSubdirectoryPaths
.Any(x => FilesFolders.ReturnPreviousDirectoryIfIncompleteString(pathToDirectory)
.StartsWith(x.Path, StringComparison.OrdinalIgnoreCase)))
.Any(x => FilesFolders.ReturnPreviousDirectoryIfIncompleteString(pathToDirectory)
.StartsWith(x.Path, StringComparison.OrdinalIgnoreCase)))
return false;

return IndexSearch.PathIsIndexed(pathToDirectory);
}
}
}
}
51 changes: 51 additions & 0 deletions Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using Flow.Launcher.Plugin.Explorer.Search;
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;
using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption;
using System;
using System.Collections.Generic;
using System.IO;

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

public string SearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign;
public bool EnableSearchActionKeyword { get; set; } = true;

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

public string PathSearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign;

public bool EnabledPathSearchKeyword { get; set; }

public string IndexOnlySearchActionKeyword { get; set; } = Query.GlobalPluginWildcardSign;

public bool EnabledIndexOnlySearchKeyword { get; set; }

internal enum ActionKeyword
{
SearchActionKeyword,
PathSearchActionKeyword,
FileContentSearchActionKeyword,
IndexOnlySearchActionKeyword
}

internal string GetActionKeyword(ActionKeyword actionKeyword) => actionKeyword switch
{
ActionKeyword.SearchActionKeyword => SearchActionKeyword,
ActionKeyword.PathSearchActionKeyword => PathSearchActionKeyword,
ActionKeyword.FileContentSearchActionKeyword => FileContentSearchActionKeyword,
ActionKeyword.IndexOnlySearchActionKeyword => IndexOnlySearchActionKeyword
};

internal void SetActionKeyword(ActionKeyword actionKeyword, string keyword) => _ = actionKeyword switch
{
ActionKeyword.SearchActionKeyword => SearchActionKeyword = keyword,
ActionKeyword.PathSearchActionKeyword => PathSearchActionKeyword = keyword,
ActionKeyword.FileContentSearchActionKeyword => FileContentSearchActionKeyword = keyword,
ActionKeyword.IndexOnlySearchActionKeyword => IndexOnlySearchActionKeyword = keyword,
_ => throw new ArgumentOutOfRangeException(nameof(actionKeyword), actionKeyword, "Unexpected property")
};

internal bool? GetActionKeywordEnable(ActionKeyword actionKeyword) => actionKeyword switch
{
ActionKeyword.SearchActionKeyword => EnableSearchActionKeyword,
ActionKeyword.PathSearchActionKeyword => EnabledPathSearchKeyword,
ActionKeyword.IndexOnlySearchActionKeyword => EnabledIndexOnlySearchKeyword,
_ => null
};

internal void SetActionKeywordEnable(ActionKeyword actionKeyword, bool enable) => _ = actionKeyword switch
{
ActionKeyword.SearchActionKeyword => EnableSearchActionKeyword = enable,
ActionKeyword.PathSearchActionKeyword => EnabledPathSearchKeyword = enable,
ActionKeyword.IndexOnlySearchActionKeyword => EnabledIndexOnlySearchKeyword = enable,
_ => throw new ArgumentOutOfRangeException(nameof(actionKeyword), actionKeyword, "Unexpected property")
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,36 +41,29 @@ internal void OpenWindowsIndexingOptions()
Process.Start(psi);
}

internal void UpdateActionKeyword(ActionKeywordProperty modifiedActionKeyword, string newActionKeyword, string oldActionKeyword)
internal void UpdateActionKeyword(Settings.ActionKeyword modifiedActionKeyword, string newActionKeyword, string oldActionKeyword)
{
if (Settings.SearchActionKeyword == Settings.PathSearchActionKeyword)
PluginManager.AddActionKeyword(Context.CurrentPluginMetadata.ID, newActionKeyword);
else
PluginManager.ReplaceActionKeyword(Context.CurrentPluginMetadata.ID, oldActionKeyword, newActionKeyword);
PluginManager.ReplaceActionKeyword(Context.CurrentPluginMetadata.ID, oldActionKeyword, newActionKeyword);

switch (modifiedActionKeyword)
{
case ActionKeywordProperty.SearchActionKeyword:
case Settings.ActionKeyword.SearchActionKeyword:
Settings.SearchActionKeyword = newActionKeyword;
break;
case ActionKeywordProperty.PathSearchActionKeyword:
case Settings.ActionKeyword.PathSearchActionKeyword:
Settings.PathSearchActionKeyword = newActionKeyword;
break;
case ActionKeywordProperty.FileContentSearchActionKeyword:
case Settings.ActionKeyword.FileContentSearchActionKeyword:
Settings.FileContentSearchActionKeyword = newActionKeyword;
break;
case Settings.ActionKeyword.IndexOnlySearchActionKeyword:
Settings.IndexOnlySearchActionKeyword = newActionKeyword;
break;
}
}

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

internal bool IsNewActionKeywordGlobal(string newActionKeyword) => newActionKeyword == Query.GlobalPluginWildcardSign;
}

public enum ActionKeywordProperty
{
SearchActionKeyword,
PathSearchActionKeyword,
FileContentSearchActionKeyword
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
mc:Ignorable="d"
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
Title="Action Keyword Setting" Height="200" Width="500">
<Grid>
<Grid.RowDefinitions>
Expand All @@ -16,15 +17,20 @@
<Grid.ColumnDefinitions>
<ColumnDefinition Width="180" />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Margin="20 10 10 10" FontSize="14" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center"
HorizontalAlignment="Left" Text="Current Action Keyword:" />
<TextBox Name="txtCurrentActionKeyword"
<TextBox Name="TxtCurrentActionKeyword"
Margin="10" Grid.Row="0" Width="105" Grid.Column="1"
VerticalAlignment="Center"
HorizontalAlignment="Left" />

<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="1" Grid.Column="1">
HorizontalAlignment="Left"
Text="{Binding CurrentActionKeyword.Keyword}" />
<CheckBox Name="ChkActionKeywordEnabled" Margin="10" Grid.Row="0" Grid.Column="2" Content="Enabled"
Width="auto"
VerticalAlignment="Center" IsChecked="{Binding CurrentActionKeyword.Enabled}"
Visibility="{Binding Visible}"/>
<StackPanel Orientation="Horizontal" Grid.Column="1" Grid.ColumnSpan="2" Margin="100 92 0 0" Grid.RowSpan="2">
<Button Click="OnConfirmButtonClick"
Margin="10 0 10 0" Width="80" Height="35"
Content="OK" />
Expand All @@ -33,4 +39,4 @@
Content="Cancel" />
</StackPanel>
</Grid>
</Window>
</Window>
Loading