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
62 changes: 59 additions & 3 deletions Plugins/Flow.Launcher.Plugin.Explorer/ContextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
using Flow.Launcher.Infrastructure.Logger;
using Flow.Launcher.Plugin.SharedCommands;
using Flow.Launcher.Plugin.Explorer.Search;
using Flow.Launcher.Plugin.Explorer.Search.FolderLinks;
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;
using System.Linq;
using MessageBox = System.Windows.Forms.MessageBox;
using MessageBoxIcon = System.Windows.Forms.MessageBoxIcon;
using MessageBoxButton = System.Windows.Forms.MessageBoxButtons;
using DialogResult = System.Windows.Forms.DialogResult;
using Flow.Launcher.Plugin.Explorer.ViewModels;

namespace Flow.Launcher.Plugin.Explorer
{
Expand All @@ -22,10 +23,13 @@ internal class ContextMenu : IContextMenu

private Settings Settings { get; set; }

public ContextMenu(PluginInitContext context, Settings settings)
private SettingsViewModel ViewModel { get; set; }

public ContextMenu(PluginInitContext context, Settings settings, SettingsViewModel vm)
{
Context = context;
Settings = settings;
ViewModel = vm;
}

public List<Result> LoadContextMenus(Result selectedResult)
Expand All @@ -50,6 +54,58 @@ public List<Result> LoadContextMenus(Result selectedResult)

var icoPath = (record.Type == ResultType.File) ? Constants.FileImagePath : Constants.FolderImagePath;
var fileOrFolder = (record.Type == ResultType.File) ? "file" : "folder";

if (!Settings.QuickAccessLinks.Any(x => x.Path == record.FullPath))
{
contextMenus.Add(new Result
{
Title = Context.API.GetTranslation("plugin_explorer_add_to_quickaccess_title"),
SubTitle = string.Format(Context.API.GetTranslation("plugin_explorer_add_to_quickaccess_subtitle"), fileOrFolder),
Action = (context) =>
{
Settings.QuickAccessLinks.Add(new AccessLink { Path = record.FullPath, Type = record.Type });

Context.API.ShowMsg(Context.API.GetTranslation("plugin_explorer_addfilefoldersuccess"),
string.Format(
Context.API.GetTranslation("plugin_explorer_addfilefoldersuccess_detail"),
fileOrFolder),
Constants.ExplorerIconImageFullPath);

ViewModel.Save();

return true;
},
SubTitleToolTip = Context.API.GetTranslation("plugin_explorer_contextmenu_titletooltip"),
TitleToolTip = Context.API.GetTranslation("plugin_explorer_contextmenu_titletooltip"),
IcoPath = Constants.QuickAccessImagePath
});
}
else
{
contextMenus.Add(new Result
{
Title = Context.API.GetTranslation("plugin_explorer_remove_from_quickaccess_title"),
SubTitle = string.Format(Context.API.GetTranslation("plugin_explorer_remove_from_quickaccess_subtitle"), fileOrFolder),
Action = (context) =>
{
Settings.QuickAccessLinks.Remove(Settings.QuickAccessLinks.FirstOrDefault(x => x.Path == record.FullPath));

Context.API.ShowMsg(Context.API.GetTranslation("plugin_explorer_removefilefoldersuccess"),
string.Format(
Context.API.GetTranslation("plugin_explorer_removefilefoldersuccess_detail"),
fileOrFolder),
Constants.ExplorerIconImageFullPath);

ViewModel.Save();

return true;
},
SubTitleToolTip = Context.API.GetTranslation("plugin_explorer_contextmenu_remove_titletooltip"),
TitleToolTip = Context.API.GetTranslation("plugin_explorer_contextmenu_remove_titletooltip"),
IcoPath = Constants.RemoveQuickAccessImagePath
});
}

contextMenus.Add(new Result
{
Title = Context.API.GetTranslation("plugin_explorer_copypath"),
Expand Down Expand Up @@ -228,7 +284,7 @@ private Result CreateAddToIndexSearchExclusionListResult(SearchResult record)
Action = _ =>
{
if(!Settings.IndexSearchExcludedSubdirectoryPaths.Any(x => x.Path == record.FullPath))
Settings.IndexSearchExcludedSubdirectoryPaths.Add(new FolderLink { Path = record.FullPath });
Settings.IndexSearchExcludedSubdirectoryPaths.Add(new AccessLink { Path = record.FullPath });

Task.Run(() =>
{
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 11 additions & 1 deletion Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<system:String x:Key="plugin_explorer_edit">Edit</system:String>
<system:String x:Key="plugin_explorer_add">Add</system:String>
<system:String x:Key="plugin_explorer_manageactionkeywords_header">Customise Action Keywords</system:String>
<system:String x:Key="plugin_explorer_quickfolderaccess_header">Quick Folder Access Paths</system:String>
<system:String x:Key="plugin_explorer_quickaccesslinks_header">Quick Access Links</system:String>
<system:String x:Key="plugin_explorer_indexsearchexcludedpaths_header">Index Search Excluded Paths</system:String>
<system:String x:Key="plugin_explorer_manageindexoptions">Indexing Options</system:String>
<system:String x:Key="plugin_explorer_actionkeywordview_search">Search Activation:</system:String>
Expand All @@ -42,5 +42,15 @@
<system:String x:Key="plugin_explorer_openindexingoptions">Open Windows Indexing Options</system:String>
<system:String x:Key="plugin_explorer_openindexingoptions_subtitle">Manage indexed files and folders</system:String>
<system:String x:Key="plugin_explorer_openindexingoptions_errormsg">Failed to open Windows Indexing Options</system:String>
<system:String x:Key="plugin_explorer_add_to_quickaccess_title">Add to Quick Access</system:String>
<system:String x:Key="plugin_explorer_add_to_quickaccess_subtitle">Add the current {0} to Quick Access</system:String>
<system:String x:Key="plugin_explorer_addfilefoldersuccess">Successfully Added</system:String>
<system:String x:Key="plugin_explorer_addfilefoldersuccess_detail">Successfully added to Quick Access</system:String>
<system:String x:Key="plugin_explorer_removefilefoldersuccess">Successfully Removed</system:String>
<system:String x:Key="plugin_explorer_removefilefoldersuccess_detail">Successfully removed from Quick Access</system:String>
<system:String x:Key="plugin_explorer_contextmenu_titletooltip">Add to Quick Access so it can be opened with Explorer's Search Activation action keyword</system:String>
<system:String x:Key="plugin_explorer_contextmenu_remove_titletooltip">Remove from Quick Access</system:String>
<system:String x:Key="plugin_explorer_remove_from_quickaccess_title">Remove from Quick Access</system:String>
<system:String x:Key="plugin_explorer_remove_from_quickaccess_subtitle">Remove the current {0} from Quick Access</system:String>

</ResourceDictionary>
12 changes: 11 additions & 1 deletion Plugins/Flow.Launcher.Plugin.Explorer/Main.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Flow.Launcher.Infrastructure.Storage;
using Flow.Launcher.Plugin.Explorer.Search;
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;
using Flow.Launcher.Plugin.Explorer.ViewModels;
using Flow.Launcher.Plugin.Explorer.Views;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Controls;
Expand Down Expand Up @@ -32,7 +34,15 @@ public async Task InitAsync(PluginInitContext context)
viewModel = new SettingsViewModel(context);
await viewModel.LoadStorage();
Settings = viewModel.Settings;
contextMenu = new ContextMenu(Context, Settings);

// as at v1.7.0 this is to maintain backwards compatibility, need to be removed afterwards.
if (Settings.QuickFolderAccessLinks.Any())
{
Settings.QuickAccessLinks = Settings.QuickFolderAccessLinks;
Copy link
Member

Choose a reason for hiding this comment

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

Please also remove QuickFolderAccessLinks so that it won't be saved via json.

Copy link
Member Author

@jjw24 jjw24 Jan 26, 2021

Choose a reason for hiding this comment

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

Good pick up 👍
It needs to be loaded once, so I dont know how I can make it so it gets loaded but ignored when saving. Changed it so it's saved as empty list.

Settings.QuickFolderAccessLinks = new List<AccessLink>();
}

contextMenu = new ContextMenu(Context, Settings, viewModel);
searchManager = new SearchManager(Settings, Context);
}

Expand Down
2 changes: 2 additions & 0 deletions Plugins/Flow.Launcher.Plugin.Explorer/Search/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ internal static class Constants
internal const string ExplorerIconImagePath = "Images\\explorer.png";
internal const string DifferentUserIconImagePath = "Images\\user.png";
internal const string IndexingOptionsIconImagePath = "Images\\windowsindexingoptions.png";
internal const string QuickAccessImagePath = "Images\\quickaccess.png";
internal const string RemoveQuickAccessImagePath = "Images\\removequickaccess.png";

internal const string ToolTipOpenDirectory = "Ctrl + Enter to open the directory";

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using System;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Flow.Launcher.Plugin.Explorer.Search.FolderLinks
namespace Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks
{
public class FolderLink
public class AccessLink
{
public string Path { get; set; }

public ResultType Type { get; set; } = ResultType.Folder;

[JsonIgnore]
public string Nickname
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks
{
public class QuickAccess
{
private readonly ResultManager resultManager;

public QuickAccess(PluginInitContext context)
{
resultManager = new ResultManager(context);
}

internal List<Result> AccessLinkListMatched(Query query, List<AccessLink> accessLinks)
{
if (string.IsNullOrEmpty(query.Search))
return new List<Result>();

string search = query.Search.ToLower();

var queriedAccessLinks =
accessLinks
.Where(x => x.Nickname.StartsWith(search, StringComparison.OrdinalIgnoreCase))
.OrderBy(x => x.Type)
.ThenBy(x => x.Nickname);

return queriedAccessLinks.Select(l => l.Type switch
{
ResultType.Folder => resultManager.CreateFolderResult(l.Nickname, l.Path, l.Path, query),
ResultType.File => resultManager.CreateFileResult(l.Path, query),
_ => throw new ArgumentOutOfRangeException()

}).ToList();
}

internal List<Result> AccessLinkListAll(Query query, List<AccessLink> accessLinks)
Copy link
Member

Choose a reason for hiding this comment

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

Similar to last one.

Copy link
Member

Choose a reason for hiding this comment

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

Please use select with switch or if instead where twice and concat. I can do it for you if you want.

=> accessLinks
.OrderBy(x => x.Type)
.ThenBy(x => x.Nickname)
.Select(l => l.Type switch
{
ResultType.Folder => resultManager.CreateFolderResult(l.Nickname, l.Path, l.Path, query),
ResultType.File => resultManager.CreateFileResult(l.Path, query),
_ => throw new ArgumentOutOfRangeException()

}).ToList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ internal class SearchResult
public bool ShowIndexState { get; set; }
}

internal enum ResultType
public enum ResultType
{
Volume,
Folder,
Expand Down
14 changes: 7 additions & 7 deletions Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Flow.Launcher.Plugin.Explorer.Search.DirectoryInfo;
using Flow.Launcher.Plugin.Explorer.Search.FolderLinks;
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;
using Flow.Launcher.Plugin.Explorer.Search.WindowsIndex;
using Flow.Launcher.Plugin.SharedCommands;
using System;
Expand All @@ -16,7 +16,7 @@ public class SearchManager

private readonly IndexSearch indexSearch;

private readonly QuickFolderAccess quickFolderAccess;
private readonly QuickAccess quickAccess;

private readonly ResultManager resultManager;

Expand All @@ -28,7 +28,7 @@ public SearchManager(Settings settings, PluginInitContext context)
indexSearch = new IndexSearch(context);
resultManager = new ResultManager(context);
this.settings = settings;
quickFolderAccess = new QuickFolderAccess(context);
quickAccess = new QuickAccess(context);
}

internal async Task<List<Result>> SearchAsync(Query query, CancellationToken token)
Expand All @@ -42,12 +42,12 @@ internal async Task<List<Result>> SearchAsync(Query query, CancellationToken tok

// This allows the user to type the assigned action keyword and only see the list of quick folder links
if (string.IsNullOrEmpty(query.Search))
return quickFolderAccess.FolderListAll(query, settings.QuickFolderAccessLinks);
return quickAccess.AccessLinkListAll(query, settings.QuickAccessLinks);

var quickFolderLinks = quickFolderAccess.FolderListMatched(query, settings.QuickFolderAccessLinks);
var quickaccessLinks = quickAccess.AccessLinkListMatched(query, settings.QuickAccessLinks);

if (quickFolderLinks.Count > 0)
results.AddRange(quickFolderLinks);
if (quickaccessLinks.Count > 0)
results.AddRange(quickaccessLinks);

var isEnvironmentVariable = EnvironmentVariables.IsEnvironmentVariableSearch(querySearch);

Expand Down
9 changes: 6 additions & 3 deletions Plugins/Flow.Launcher.Plugin.Explorer/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Flow.Launcher.Plugin.Explorer.Search;
using Flow.Launcher.Plugin.Explorer.Search.FolderLinks;
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;
using System.Collections.Generic;

namespace Flow.Launcher.Plugin.Explorer
Expand All @@ -8,11 +8,14 @@ public class Settings
{
public int MaxResult { get; set; } = 100;

public List<FolderLink> QuickFolderAccessLinks { get; set; } = new List<FolderLink>();
public List<AccessLink> QuickAccessLinks { get; set; } = new List<AccessLink>();

// as at v1.7.0 this is to maintain backwards compatibility, need to be removed afterwards.
public List<AccessLink> QuickFolderAccessLinks { get; set; } = new List<AccessLink>();

public bool UseWindowsIndexForDirectorySearch { get; set; } = true;

public List<FolderLink> IndexSearchExcludedSubdirectoryPaths { get; set; } = new List<FolderLink>();
public List<AccessLink> IndexSearchExcludedSubdirectoryPaths { get; set; } = new List<AccessLink>();

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Flow.Launcher.Core.Plugin;
using Flow.Launcher.Infrastructure.Storage;
using Flow.Launcher.Plugin.Explorer.Search;
using Flow.Launcher.Plugin.Explorer.Search.FolderLinks;
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;
using System.Diagnostics;
using System.Threading.Tasks;

Expand Down Expand Up @@ -32,9 +32,9 @@ public void Save()
storage.Save();
}

internal void RemoveFolderLinkFromQuickFolders(FolderLink selectedRow) => Settings.QuickFolderAccessLinks.Remove(selectedRow);
internal void RemoveLinkFromQuickAccess(AccessLink selectedRow) => Settings.QuickAccessLinks.Remove(selectedRow);

internal void RemoveFolderLinkFromExcludedIndexPaths(FolderLink selectedRow) => Settings.IndexSearchExcludedSubdirectoryPaths.Remove(selectedRow);
internal void RemoveAccessLinkFromExcludedIndexPaths(AccessLink selectedRow) => Settings.IndexSearchExcludedSubdirectoryPaths.Remove(selectedRow);

internal void OpenWindowsIndexingOptions()
{
Expand Down
Loading