add context menu to exclude indexed path from using index search

This commit is contained in:
Jeremy Wu 2020-06-02 20:58:22 +10:00
parent 2225cbff92
commit 6330a784e8
7 changed files with 32 additions and 10 deletions

View file

@ -7,6 +7,7 @@ using System.Windows;
using Flow.Launcher.Infrastructure.Logger;
using Flow.Launcher.Plugin.SharedCommands;
using Flow.Launcher.Plugin.Explorer.Search;
using System.Windows.Media;
namespace Flow.Launcher.Plugin.Explorer
{
@ -18,9 +19,10 @@ namespace Flow.Launcher.Plugin.Explorer
if (selectedResult.ContextData is SearchResult record)
{
if (record.Type == ResultType.File)
{
contextMenus.Add(CreateOpenWithEditorResult(record));
}
if (record.Type == ResultType.Folder && record.WindowsIndexed)
contextMenus.Add(CreateAddToIndexSearchExclusionListResult(record));
contextMenus.Add(CreateOpenContainingFolderResult(record));
@ -154,7 +156,6 @@ namespace Flow.Launcher.Plugin.Explorer
};
}
private Result CreateOpenWithEditorResult(SearchResult record)
{
string editorPath = "notepad.exe"; // TODO add the ability to create a custom editor
@ -182,6 +183,22 @@ namespace Flow.Launcher.Plugin.Explorer
};
}
private Result CreateAddToIndexSearchExclusionListResult(SearchResult record)
{
return new Result
{
Title = "Exclude path from index search",
SubTitle = record.FullPath,
Action = _ =>
{
Main.Settings.IndexSearchExcludedDirectories.Add(record.FullPath);
return false;
},
IcoPath = Constants.ExcludeFromIndexImagePath
};
}
public void LogException(string message, Exception e)
{
Log.Exception($"|Flow.Launcher.Plugin.Folder.ContextMenu|{message}", e);

View file

@ -31,6 +31,10 @@
<None Include="Images\index.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Images\excludeindexpath.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Images\copy.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View file

@ -1,4 +1,4 @@
using Flow.Launcher.Infrastructure.Storage;
using Flow.Launcher.Infrastructure.Storage;
using Flow.Launcher.Plugin.Explorer.Search;
using Flow.Launcher.Plugin.Explorer.ViewModels;
using Flow.Launcher.Plugin.Explorer.Views;
@ -12,7 +12,7 @@ namespace Flow.Launcher.Plugin.Explorer
{
internal static PluginInitContext Context { get; set; }
private Settings _settings;
internal static Settings Settings;
private SettingsViewModel _viewModel;
@ -27,7 +27,7 @@ namespace Flow.Launcher.Plugin.Explorer
{
Context = context;
_viewModel = new SettingsViewModel();
_settings = _viewModel.Settings;
Settings = _viewModel.Settings;
_contextMenu = new ContextMenu();
}
@ -43,7 +43,7 @@ namespace Flow.Launcher.Plugin.Explorer
if (string.IsNullOrEmpty(query.Search))
return results;
return new SearchManager(_settings, Context).Search(query);
return new SearchManager(Settings, Context).Search(query);
}
public void Save()

View file

@ -11,6 +11,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
internal const string DeleteFileFolderImagePath = "Images\\deletefilefolder.png";
internal const string CopyImagePath = "Images\\copy.png";
internal const string IndexImagePath = "Images\\index.png";
internal const string ExcludeFromIndexImagePath = "Images\\excludeindexpath.png";
internal const string DefaultFolderSubtitleString = "Ctrl + Enter to open the directory";

View file

@ -112,8 +112,8 @@ namespace Flow.Launcher.Plugin.Explorer.Search
if (!_settings.UseWindowsIndexForDirectorySearch)
return false;
if (_settings.WindowsIndexExcludedDirectories
.Any(x => x.Path == FilesFolders.ReturnPreviousDirectoryIfIncompleteString(locationPath)))
if (_settings.IndexSearchExcludedDirectories
.Any(x => x == FilesFolders.ReturnPreviousDirectoryIfIncompleteString(locationPath)))
return false;
return _indexSearch.PathIsIndexed(locationPath);

View file

@ -17,6 +17,6 @@ namespace Flow.Launcher.Plugin.Explorer
public bool UseWindowsIndexForDirectorySearch { get; set; } = true;
[JsonProperty]
public List<FolderLink> WindowsIndexExcludedDirectories { get; set; } = new List<FolderLink>();
public List<string> IndexSearchExcludedDirectories { get; set; } = new List<string>();
}
}