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 Plugins/Flow.Launcher.Plugin.Explorer/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Task InitAsync(PluginInitContext context)

contextMenu = new ContextMenu(Context, Settings, viewModel);
searchManager = new SearchManager(Settings, Context);
ResultManager.Init(Context);
ResultManager.Init(Context, Settings);

return Task.CompletedTask;
}
Expand Down
47 changes: 36 additions & 11 deletions Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ namespace Flow.Launcher.Plugin.Explorer.Search
public static class ResultManager
{
private static PluginInitContext Context;
private static Settings Settings { get; set; }

public static void Init(PluginInitContext context)
public static void Init(PluginInitContext context, Settings settings)
{
Context = context;
Settings = settings;
}

internal static Result CreateFolderResult(string title, string subtitle, string path, Query query, int score = 0, bool showIndexState = false, bool windowsIndexed = false)
Expand All @@ -26,7 +28,7 @@ internal static Result CreateFolderResult(string title, string subtitle, string
TitleHighlightData = StringMatcher.FuzzySearch(query.Search, title).MatchData,
Action = c =>
{
if (c.SpecialKeyState.CtrlPressed)
if (c.SpecialKeyState.CtrlPressed || (!Settings.PathSearchKeywordEnabled && !Settings.SearchActionKeywordEnabled))
{
try
{
Expand All @@ -39,25 +41,36 @@ internal static Result CreateFolderResult(string title, string subtitle, string
return false;
}
}
// one of it is enabled
var keyword = Settings.SearchActionKeywordEnabled ? Settings.SearchActionKeyword : Settings.PathSearchActionKeyword;

keyword = keyword == Query.GlobalPluginWildcardSign ? string.Empty : keyword + " ";

string changeTo = path.EndsWith(Constants.DirectorySeperator) ? path : path + Constants.DirectorySeperator;
Context.API.ChangeQuery(string.IsNullOrEmpty(query.ActionKeyword) ?
changeTo :
query.ActionKeyword + " " + changeTo);
Context.API.ChangeQuery($"{keyword}{changeTo}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You removed the space here, is it meant to be added to line 47?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is supposed to be a space instead of empty string. Will fix it soom.

return false;
},
Score = score,
TitleToolTip = Constants.ToolTipOpenDirectory,
SubTitleToolTip = Constants.ToolTipOpenDirectory,
ContextData = new SearchResult { Type = ResultType.Folder, FullPath = path, ShowIndexState = showIndexState, WindowsIndexed = windowsIndexed }
ContextData = new SearchResult
{
Type = ResultType.Folder,
FullPath = path,
ShowIndexState = showIndexState,
WindowsIndexed = windowsIndexed
}
};
}

internal static Result CreateOpenCurrentFolderResult(string path, bool windowsIndexed = false)
{
var retrievedDirectoryPath = FilesFolders.ReturnPreviousDirectoryIfIncompleteString(path);

var folderName = retrievedDirectoryPath.TrimEnd(Constants.DirectorySeperator).Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None).Last();
var folderName = retrievedDirectoryPath.TrimEnd(Constants.DirectorySeperator).Split(new[]
{
Path.DirectorySeparatorChar
}, StringSplitOptions.None).Last();

if (retrievedDirectoryPath.EndsWith(":\\"))
{
Expand All @@ -81,7 +94,7 @@ internal static Result CreateOpenCurrentFolderResult(string path, bool windowsIn
{
Title = title,
SubTitle = $"Use > to search within {subtitleFolderName}, " +
$"* to search for file extensions or >* to combine both searches.",
$"* to search for file extensions or >* to combine both searches.",
IcoPath = retrievedDirectoryPath,
Score = 500,
Action = c =>
Expand All @@ -91,7 +104,13 @@ internal static Result CreateOpenCurrentFolderResult(string path, bool windowsIn
},
TitleToolTip = retrievedDirectoryPath,
SubTitleToolTip = retrievedDirectoryPath,
ContextData = new SearchResult { Type = ResultType.Folder, FullPath = retrievedDirectoryPath, ShowIndexState = true, WindowsIndexed = windowsIndexed }
ContextData = new SearchResult
{
Type = ResultType.Folder,
FullPath = retrievedDirectoryPath,
ShowIndexState = true,
WindowsIndexed = windowsIndexed
}
};
}

Expand Down Expand Up @@ -126,7 +145,13 @@ internal static Result CreateFileResult(string filePath, Query query, int score
},
TitleToolTip = Constants.ToolTipOpenContainingFolder,
SubTitleToolTip = Constants.ToolTipOpenContainingFolder,
ContextData = new SearchResult { Type = ResultType.File, FullPath = filePath, ShowIndexState = showIndexState, WindowsIndexed = windowsIndexed }
ContextData = new SearchResult
{
Type = ResultType.File,
FullPath = filePath,
ShowIndexState = showIndexState,
WindowsIndexed = windowsIndexed
}
};
return result;
}
Expand All @@ -148,4 +173,4 @@ public enum ResultType
Folder,
File
}
}
}
6 changes: 3 additions & 3 deletions Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ private bool ActionKeywordMatch(Query query, Settings.ActionKeyword allowedActio

return allowedActionKeyword switch
{
Settings.ActionKeyword.SearchActionKeyword => settings.EnableSearchActionKeyword &&
Settings.ActionKeyword.SearchActionKeyword => settings.SearchActionKeywordEnabled &&
keyword == settings.SearchActionKeyword,
Settings.ActionKeyword.PathSearchActionKeyword => settings.EnabledPathSearchKeyword &&
Settings.ActionKeyword.PathSearchActionKeyword => settings.PathSearchKeywordEnabled &&
keyword == settings.PathSearchActionKeyword,
Settings.ActionKeyword.FileContentSearchActionKeyword => keyword ==
settings.FileContentSearchActionKeyword,
Settings.ActionKeyword.IndexSearchActionKeyword => settings.EnabledIndexOnlySearchKeyword &&
Settings.ActionKeyword.IndexSearchActionKeyword => settings.IndexOnlySearchKeywordEnabled &&
keyword == settings.IndexSearchActionKeyword
};
}
Expand Down
22 changes: 11 additions & 11 deletions Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ 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 bool SearchActionKeywordEnabled { get; set; } = true;

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

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

public bool EnabledPathSearchKeyword { get; set; }
public bool PathSearchKeywordEnabled { get; set; }

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

public bool EnabledIndexOnlySearchKeyword { get; set; }
public bool IndexOnlySearchKeywordEnabled { get; set; }

internal enum ActionKeyword
{
Expand All @@ -58,19 +58,19 @@ internal enum ActionKeyword
_ => throw new ArgumentOutOfRangeException(nameof(actionKeyword), actionKeyword, "Unexpected property")
};

internal bool? GetActionKeywordEnable(ActionKeyword actionKeyword) => actionKeyword switch
internal bool? GetActionKeywordEnabled(ActionKeyword actionKeyword) => actionKeyword switch
{
ActionKeyword.SearchActionKeyword => EnableSearchActionKeyword,
ActionKeyword.PathSearchActionKeyword => EnabledPathSearchKeyword,
ActionKeyword.IndexSearchActionKeyword => EnabledIndexOnlySearchKeyword,
ActionKeyword.SearchActionKeyword => SearchActionKeywordEnabled,
ActionKeyword.PathSearchActionKeyword => PathSearchKeywordEnabled,
ActionKeyword.IndexSearchActionKeyword => IndexOnlySearchKeywordEnabled,
_ => null
};

internal void SetActionKeywordEnable(ActionKeyword actionKeyword, bool enable) => _ = actionKeyword switch
internal void SetActionKeywordEnabled(ActionKeyword actionKeyword, bool enable) => _ = actionKeyword switch
{
ActionKeyword.SearchActionKeyword => EnableSearchActionKeyword = enable,
ActionKeyword.PathSearchActionKeyword => EnabledPathSearchKeyword = enable,
ActionKeyword.IndexSearchActionKeyword => EnabledIndexOnlySearchKeyword = enable,
ActionKeyword.SearchActionKeyword => SearchActionKeywordEnabled = enable,
ActionKeyword.PathSearchActionKeyword => PathSearchKeywordEnabled = enable,
ActionKeyword.IndexSearchActionKeyword => IndexOnlySearchKeywordEnabled = enable,
_ => throw new ArgumentOutOfRangeException(nameof(actionKeyword), actionKeyword, "Unexpected property")
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ public string Keyword

public bool? Enabled
{
get => _settings.GetActionKeywordEnable(KeywordProperty);
set => _settings.SetActionKeywordEnable(KeywordProperty,
get => _settings.GetActionKeywordEnabled(KeywordProperty);
set => _settings.SetActionKeywordEnabled(KeywordProperty,
value ?? throw new ArgumentException("Unexpected null value"));
}
}
Expand Down