Skip to content

Commit d509b11

Browse files
authored
Merge pull request #315 from Flow-Launcher/add_file_quick_access
Add save file with Explorer for quick access
2 parents f848e68 + e615ad8 commit d509b11

File tree

16 files changed

+207
-111
lines changed

16 files changed

+207
-111
lines changed

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

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
using Flow.Launcher.Infrastructure.Logger;
88
using Flow.Launcher.Plugin.SharedCommands;
99
using Flow.Launcher.Plugin.Explorer.Search;
10-
using Flow.Launcher.Plugin.Explorer.Search.FolderLinks;
10+
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;
1111
using System.Linq;
1212
using MessageBox = System.Windows.Forms.MessageBox;
1313
using MessageBoxIcon = System.Windows.Forms.MessageBoxIcon;
1414
using MessageBoxButton = System.Windows.Forms.MessageBoxButtons;
1515
using DialogResult = System.Windows.Forms.DialogResult;
16+
using Flow.Launcher.Plugin.Explorer.ViewModels;
1617

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

2324
private Settings Settings { get; set; }
2425

25-
public ContextMenu(PluginInitContext context, Settings settings)
26+
private SettingsViewModel ViewModel { get; set; }
27+
28+
public ContextMenu(PluginInitContext context, Settings settings, SettingsViewModel vm)
2629
{
2730
Context = context;
2831
Settings = settings;
32+
ViewModel = vm;
2933
}
3034

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

5155
var icoPath = (record.Type == ResultType.File) ? Constants.FileImagePath : Constants.FolderImagePath;
5256
var fileOrFolder = (record.Type == ResultType.File) ? "file" : "folder";
57+
58+
if (!Settings.QuickAccessLinks.Any(x => x.Path == record.FullPath))
59+
{
60+
contextMenus.Add(new Result
61+
{
62+
Title = Context.API.GetTranslation("plugin_explorer_add_to_quickaccess_title"),
63+
SubTitle = string.Format(Context.API.GetTranslation("plugin_explorer_add_to_quickaccess_subtitle"), fileOrFolder),
64+
Action = (context) =>
65+
{
66+
Settings.QuickAccessLinks.Add(new AccessLink { Path = record.FullPath, Type = record.Type });
67+
68+
Context.API.ShowMsg(Context.API.GetTranslation("plugin_explorer_addfilefoldersuccess"),
69+
string.Format(
70+
Context.API.GetTranslation("plugin_explorer_addfilefoldersuccess_detail"),
71+
fileOrFolder),
72+
Constants.ExplorerIconImageFullPath);
73+
74+
ViewModel.Save();
75+
76+
return true;
77+
},
78+
SubTitleToolTip = Context.API.GetTranslation("plugin_explorer_contextmenu_titletooltip"),
79+
TitleToolTip = Context.API.GetTranslation("plugin_explorer_contextmenu_titletooltip"),
80+
IcoPath = Constants.QuickAccessImagePath
81+
});
82+
}
83+
else
84+
{
85+
contextMenus.Add(new Result
86+
{
87+
Title = Context.API.GetTranslation("plugin_explorer_remove_from_quickaccess_title"),
88+
SubTitle = string.Format(Context.API.GetTranslation("plugin_explorer_remove_from_quickaccess_subtitle"), fileOrFolder),
89+
Action = (context) =>
90+
{
91+
Settings.QuickAccessLinks.Remove(Settings.QuickAccessLinks.FirstOrDefault(x => x.Path == record.FullPath));
92+
93+
Context.API.ShowMsg(Context.API.GetTranslation("plugin_explorer_removefilefoldersuccess"),
94+
string.Format(
95+
Context.API.GetTranslation("plugin_explorer_removefilefoldersuccess_detail"),
96+
fileOrFolder),
97+
Constants.ExplorerIconImageFullPath);
98+
99+
ViewModel.Save();
100+
101+
return true;
102+
},
103+
SubTitleToolTip = Context.API.GetTranslation("plugin_explorer_contextmenu_remove_titletooltip"),
104+
TitleToolTip = Context.API.GetTranslation("plugin_explorer_contextmenu_remove_titletooltip"),
105+
IcoPath = Constants.RemoveQuickAccessImagePath
106+
});
107+
}
108+
53109
contextMenus.Add(new Result
54110
{
55111
Title = Context.API.GetTranslation("plugin_explorer_copypath"),
@@ -228,7 +284,7 @@ private Result CreateAddToIndexSearchExclusionListResult(SearchResult record)
228284
Action = _ =>
229285
{
230286
if(!Settings.IndexSearchExcludedSubdirectoryPaths.Any(x => x.Path == record.FullPath))
231-
Settings.IndexSearchExcludedSubdirectoryPaths.Add(new FolderLink { Path = record.FullPath });
287+
Settings.IndexSearchExcludedSubdirectoryPaths.Add(new AccessLink { Path = record.FullPath });
232288

233289
Task.Run(() =>
234290
{
42.8 KB
Loading
11.3 KB
Loading

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<system:String x:Key="plugin_explorer_edit">Edit</system:String>
1717
<system:String x:Key="plugin_explorer_add">Add</system:String>
1818
<system:String x:Key="plugin_explorer_manageactionkeywords_header">Customise Action Keywords</system:String>
19-
<system:String x:Key="plugin_explorer_quickfolderaccess_header">Quick Folder Access Paths</system:String>
19+
<system:String x:Key="plugin_explorer_quickaccesslinks_header">Quick Access Links</system:String>
2020
<system:String x:Key="plugin_explorer_indexsearchexcludedpaths_header">Index Search Excluded Paths</system:String>
2121
<system:String x:Key="plugin_explorer_manageindexoptions">Indexing Options</system:String>
2222
<system:String x:Key="plugin_explorer_actionkeywordview_search">Search Activation:</system:String>
@@ -42,5 +42,15 @@
4242
<system:String x:Key="plugin_explorer_openindexingoptions">Open Windows Indexing Options</system:String>
4343
<system:String x:Key="plugin_explorer_openindexingoptions_subtitle">Manage indexed files and folders</system:String>
4444
<system:String x:Key="plugin_explorer_openindexingoptions_errormsg">Failed to open Windows Indexing Options</system:String>
45+
<system:String x:Key="plugin_explorer_add_to_quickaccess_title">Add to Quick Access</system:String>
46+
<system:String x:Key="plugin_explorer_add_to_quickaccess_subtitle">Add the current {0} to Quick Access</system:String>
47+
<system:String x:Key="plugin_explorer_addfilefoldersuccess">Successfully Added</system:String>
48+
<system:String x:Key="plugin_explorer_addfilefoldersuccess_detail">Successfully added to Quick Access</system:String>
49+
<system:String x:Key="plugin_explorer_removefilefoldersuccess">Successfully Removed</system:String>
50+
<system:String x:Key="plugin_explorer_removefilefoldersuccess_detail">Successfully removed from Quick Access</system:String>
51+
<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>
52+
<system:String x:Key="plugin_explorer_contextmenu_remove_titletooltip">Remove from Quick Access</system:String>
53+
<system:String x:Key="plugin_explorer_remove_from_quickaccess_title">Remove from Quick Access</system:String>
54+
<system:String x:Key="plugin_explorer_remove_from_quickaccess_subtitle">Remove the current {0} from Quick Access</system:String>
4555

4656
</ResourceDictionary>

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using Flow.Launcher.Infrastructure.Storage;
22
using Flow.Launcher.Plugin.Explorer.Search;
3+
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;
34
using Flow.Launcher.Plugin.Explorer.ViewModels;
45
using Flow.Launcher.Plugin.Explorer.Views;
56
using System.Collections.Generic;
7+
using System.Linq;
68
using System.Threading;
79
using System.Threading.Tasks;
810
using System.Windows.Controls;
@@ -32,7 +34,15 @@ public async Task InitAsync(PluginInitContext context)
3234
viewModel = new SettingsViewModel(context);
3335
await viewModel.LoadStorage();
3436
Settings = viewModel.Settings;
35-
contextMenu = new ContextMenu(Context, Settings);
37+
38+
// as at v1.7.0 this is to maintain backwards compatibility, need to be removed afterwards.
39+
if (Settings.QuickFolderAccessLinks.Any())
40+
{
41+
Settings.QuickAccessLinks = Settings.QuickFolderAccessLinks;
42+
Settings.QuickFolderAccessLinks = new List<AccessLink>();
43+
}
44+
45+
contextMenu = new ContextMenu(Context, Settings, viewModel);
3646
searchManager = new SearchManager(Settings, Context);
3747
}
3848

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ internal static class Constants
1515
internal const string ExplorerIconImagePath = "Images\\explorer.png";
1616
internal const string DifferentUserIconImagePath = "Images\\user.png";
1717
internal const string IndexingOptionsIconImagePath = "Images\\windowsindexingoptions.png";
18+
internal const string QuickAccessImagePath = "Images\\quickaccess.png";
19+
internal const string RemoveQuickAccessImagePath = "Images\\removequickaccess.png";
1820

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

Plugins/Flow.Launcher.Plugin.Explorer/Search/FolderLinks/QuickFolderAccess.cs

Lines changed: 0 additions & 36 deletions
This file was deleted.

Plugins/Flow.Launcher.Plugin.Explorer/Search/FolderLinks/FolderLink.cs renamed to Plugins/Flow.Launcher.Plugin.Explorer/Search/QuickAccessLinks/AccessLink.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
using System;
22
using System.Linq;
3-
using System.Text.Json;
43
using System.Text.Json.Serialization;
54

6-
namespace Flow.Launcher.Plugin.Explorer.Search.FolderLinks
5+
namespace Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks
76
{
8-
public class FolderLink
7+
public class AccessLink
98
{
109
public string Path { get; set; }
1110

11+
public ResultType Type { get; set; } = ResultType.Folder;
12+
1213
[JsonIgnore]
1314
public string Nickname
1415
{
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks
6+
{
7+
public class QuickAccess
8+
{
9+
private readonly ResultManager resultManager;
10+
11+
public QuickAccess(PluginInitContext context)
12+
{
13+
resultManager = new ResultManager(context);
14+
}
15+
16+
internal List<Result> AccessLinkListMatched(Query query, List<AccessLink> accessLinks)
17+
{
18+
if (string.IsNullOrEmpty(query.Search))
19+
return new List<Result>();
20+
21+
string search = query.Search.ToLower();
22+
23+
var queriedAccessLinks =
24+
accessLinks
25+
.Where(x => x.Nickname.StartsWith(search, StringComparison.OrdinalIgnoreCase))
26+
.OrderBy(x => x.Type)
27+
.ThenBy(x => x.Nickname);
28+
29+
return queriedAccessLinks.Select(l => l.Type switch
30+
{
31+
ResultType.Folder => resultManager.CreateFolderResult(l.Nickname, l.Path, l.Path, query),
32+
ResultType.File => resultManager.CreateFileResult(l.Path, query),
33+
_ => throw new ArgumentOutOfRangeException()
34+
35+
}).ToList();
36+
}
37+
38+
internal List<Result> AccessLinkListAll(Query query, List<AccessLink> accessLinks)
39+
=> accessLinks
40+
.OrderBy(x => x.Type)
41+
.ThenBy(x => x.Nickname)
42+
.Select(l => l.Type switch
43+
{
44+
ResultType.Folder => resultManager.CreateFolderResult(l.Nickname, l.Path, l.Path, query),
45+
ResultType.File => resultManager.CreateFileResult(l.Path, query),
46+
_ => throw new ArgumentOutOfRangeException()
47+
48+
}).ToList();
49+
}
50+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ internal class SearchResult
140140
public bool ShowIndexState { get; set; }
141141
}
142142

143-
internal enum ResultType
143+
public enum ResultType
144144
{
145145
Volume,
146146
Folder,

0 commit comments

Comments
 (0)