Skip to content

Commit 5d696bd

Browse files
committed
explorer general touch ups- no logic change
1 parent 0ee0fb8 commit 5d696bd

File tree

12 files changed

+131
-95
lines changed

12 files changed

+131
-95
lines changed

Flow.Launcher.Test/Plugins/ExplorerTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ public void GivenWindowsIndexSearch_WhenSearchPatternHotKeyIsSearchAll_ThenQuery
261261
public void GivenDirectoryInfoSearch_WhenSearchPatternHotKeyIsSearchAll_ThenSearchCriteriaShouldUseCriteriaString(string path, string expectedString)
262262
{
263263
// Given
264-
var criteriaConstructor = new DirectoryInfoSearch(new Settings());
264+
var criteriaConstructor = new DirectoryInfoSearch(new PluginInitContext());
265265

266266
//When
267267
var resultString = criteriaConstructor.ConstructSearchCriteria(path);

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

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ namespace Flow.Launcher.Plugin.Explorer
1515
{
1616
internal class ContextMenu : IContextMenu
1717
{
18+
private PluginInitContext Context { get; set; }
19+
20+
private Settings Settings { get; set; }
21+
22+
public ContextMenu(PluginInitContext context, Settings settings)
23+
{
24+
Context = context;
25+
Settings = settings;
26+
}
27+
1828
public List<Result> LoadContextMenus(Result selectedResult)
1929
{
2030
var contextMenus = new List<Result>();
@@ -50,7 +60,7 @@ public List<Result> LoadContextMenus(Result selectedResult)
5060
{
5161
var message = "Fail to set text in clipboard";
5262
LogException(message, e);
53-
Main.Context.API.ShowMsg(message);
63+
Context.API.ShowMsg(message);
5464
return false;
5565
}
5666
},
@@ -72,7 +82,7 @@ public List<Result> LoadContextMenus(Result selectedResult)
7282
{
7383
var message = $"Fail to set {fileOrFolder} in clipboard";
7484
LogException(message, e);
75-
Main.Context.API.ShowMsg(message);
85+
Context.API.ShowMsg(message);
7686
return false;
7787
}
7888

@@ -98,7 +108,7 @@ public List<Result> LoadContextMenus(Result selectedResult)
98108
{
99109
var message = $"Fail to delete {fileOrFolder} at {record.FullPath}";
100110
LogException(message, e);
101-
Main.Context.API.ShowMsg(message);
111+
Context.API.ShowMsg(message);
102112
return false;
103113
}
104114

@@ -121,7 +131,7 @@ public List<Result> LoadContextMenus(Result selectedResult)
121131
{
122132
var name = "Plugin: Folder";
123133
var message = $"File not found: {e.Message}";
124-
Main.Context.API.ShowMsg(name, message);
134+
Context.API.ShowMsg(name, message);
125135
}
126136

127137
return true;
@@ -148,7 +158,7 @@ private Result CreateOpenContainingFolderResult(SearchResult record)
148158
{
149159
var message = $"Fail to open file at {record.FullPath}";
150160
LogException(message, e);
151-
Main.Context.API.ShowMsg(message);
161+
Context.API.ShowMsg(message);
152162
return false;
153163
}
154164

@@ -177,7 +187,7 @@ private Result CreateOpenWithEditorResult(SearchResult record)
177187
{
178188
var message = $"Fail to editor for file at {record.FullPath}";
179189
LogException(message, e);
180-
Main.Context.API.ShowMsg(message);
190+
Context.API.ShowMsg(message);
181191
return false;
182192
}
183193
},
@@ -193,19 +203,19 @@ private Result CreateAddToIndexSearchExclusionListResult(SearchResult record)
193203
SubTitle = "Path: " + record.FullPath,
194204
Action = _ =>
195205
{
196-
if(!Main.Settings.IndexSearchExcludedSubdirectoryPaths.Any(x => x.Path == record.FullPath))
197-
Main.Settings.IndexSearchExcludedSubdirectoryPaths.Add(new FolderLink { Path = record.FullPath });
206+
if(!Settings.IndexSearchExcludedSubdirectoryPaths.Any(x => x.Path == record.FullPath))
207+
Settings.IndexSearchExcludedSubdirectoryPaths.Add(new FolderLink { Path = record.FullPath });
198208

199209
var pluginDirectory = Directory.GetParent(Assembly.GetExecutingAssembly().Location.ToString());
200210

201211
var iconPath = pluginDirectory + "\\" + Constants.ExplorerIconImagePath;
202212

203213
Task.Run(() =>
204214
{
205-
Main.Context.API.ShowMsg("Excluded from Index Search", "Path: " + record.FullPath, iconPath);
215+
Context.API.ShowMsg("Excluded from Index Search", "Path: " + record.FullPath, iconPath);
206216

207217
// so the new path can be persisted to storage and not wait till next ViewModel save.
208-
Main.Context.API.SaveAppAllSettings();
218+
Context.API.SaveAppAllSettings();
209219
});
210220

211221
return false;

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,36 @@
33
using Flow.Launcher.Plugin.Explorer.ViewModels;
44
using Flow.Launcher.Plugin.Explorer.Views;
55
using System.Collections.Generic;
6-
using System.Text.RegularExpressions;
76
using System.Windows.Controls;
87

98
namespace Flow.Launcher.Plugin.Explorer
109
{
1110
public class Main : ISettingProvider, IPlugin, ISavable, IContextMenu //, IPluginI18n <=== do later
1211
{
13-
internal static PluginInitContext Context { get; set; }
12+
internal PluginInitContext Context { get; set; }
1413

15-
internal static Settings Settings;
14+
internal Settings Settings;
1615

17-
private SettingsViewModel _viewModel;
16+
private SettingsViewModel viewModel;
1817

19-
private IContextMenu _contextMenu;
18+
private IContextMenu contextMenu;
2019

2120
public Control CreateSettingPanel()
2221
{
23-
return new ExplorerSettings();
22+
return new ExplorerSettings(viewModel);
2423
}
2524

2625
public void Init(PluginInitContext context)
2726
{
2827
Context = context;
29-
_viewModel = new SettingsViewModel();
30-
Settings = _viewModel.Settings;
31-
_contextMenu = new ContextMenu();
28+
viewModel = new SettingsViewModel(context);
29+
Settings = viewModel.Settings;
30+
contextMenu = new ContextMenu(Context, Settings);
3231
}
3332

3433
public List<Result> LoadContextMenus(Result selectedResult)
3534
{
36-
return _contextMenu.LoadContextMenus(selectedResult);
35+
return contextMenu.LoadContextMenus(selectedResult);
3736
}
3837

3938
public List<Result> Query(Query query)
@@ -48,7 +47,7 @@ public List<Result> Query(Query query)
4847

4948
public void Save()
5049
{
51-
_viewModel.Save();
50+
viewModel.Save();
5251
}
5352
}
5453
}

Plugins/Flow.Launcher.Plugin.Explorer/Search/DirectoryInfo/DirectoryInfoSearch.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ namespace Flow.Launcher.Plugin.Explorer.Search.DirectoryInfo
1010
{
1111
public class DirectoryInfoSearch
1212
{
13-
private Settings _settings;
13+
private readonly ResultManager resultManager;
1414

15-
public DirectoryInfoSearch(Settings settings)
15+
public DirectoryInfoSearch(PluginInitContext context)
1616
{
17-
_settings = settings;
17+
resultManager = new ResultManager(context);
1818
}
1919

2020
internal List<Result> TopLevelDirectorySearch(Query query, string search)
@@ -66,11 +66,11 @@ private List<Result> DirectorySearch(SearchOption searchOption, Query query, str
6666

6767
if (fileSystemInfo is System.IO.DirectoryInfo)
6868
{
69-
folderList.Add(ResultManager.CreateFolderResult(fileSystemInfo.Name, Constants.DefaultFolderSubtitleString, fileSystemInfo.FullName, query, true, false));
69+
folderList.Add(resultManager.CreateFolderResult(fileSystemInfo.Name, Constants.DefaultFolderSubtitleString, fileSystemInfo.FullName, query, true, false));
7070
}
7171
else
7272
{
73-
fileList.Add(ResultManager.CreateFileResult(fileSystemInfo.FullName, query, true, false));
73+
fileList.Add(resultManager.CreateFileResult(fileSystemInfo.FullName, query, true, false));
7474
}
7575
}
7676
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ internal static string TranslateEnvironmentVariablePath(string environmentVariab
4646
return environmentVariablePath;
4747
}
4848

49-
internal static List<Result> GetEnvironmentStringPathSuggestions(string querySearch, Query query)
49+
internal static List<Result> GetEnvironmentStringPathSuggestions(string querySearch, Query query, PluginInitContext context)
5050
{
5151
var results = new List<Result>();
5252

@@ -62,7 +62,7 @@ internal static List<Result> GetEnvironmentStringPathSuggestions(string querySea
6262
{
6363
var expandedPath = environmentVariables[search];
6464

65-
results.Add(ResultManager.CreateFolderResult($"%{search}%", expandedPath, expandedPath, query));
65+
results.Add(new ResultManager(context).CreateFolderResult($"%{search}%", expandedPath, expandedPath, query));
6666

6767
return results;
6868
}
@@ -81,7 +81,7 @@ internal static List<Result> GetEnvironmentStringPathSuggestions(string querySea
8181
{
8282
if (p.Key.StartsWith(search))
8383
{
84-
results.Add(ResultManager.CreateFolderResult($"%{p.Key}%", p.Value, p.Value, query));
84+
results.Add(new ResultManager(context).CreateFolderResult($"%{p.Key}%", p.Value, p.Value, query));
8585
}
8686
}
8787
return results;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ namespace Flow.Launcher.Plugin.Explorer.Search.FolderLinks
1010
{
1111
public class QuickFolderAccess
1212
{
13-
internal List<Result> FolderList(Query query, List<FolderLink> folderLinks)
13+
internal List<Result> FolderList(Query query, List<FolderLink> folderLinks, PluginInitContext context)
1414
{
1515
string search = query.Search.ToLower();
1616
var userFolderLinks = folderLinks.Where(
1717
x => x.Nickname.StartsWith(search, StringComparison.OrdinalIgnoreCase));
1818
var results = userFolderLinks.Select(item =>
19-
ResultManager.CreateFolderResult(item.Nickname, Constants.DefaultFolderSubtitleString, item.Path, query)).ToList();
19+
new ResultManager(context).CreateFolderResult(item.Nickname, Constants.DefaultFolderSubtitleString, item.Path, query)).ToList();
2020
return results;
2121
}
2222
}

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
using Flow.Launcher.Infrastructure;
22
using Flow.Launcher.Plugin.SharedCommands;
33
using System;
4-
using System.Collections.Generic;
54
using System.IO;
65
using System.Linq;
7-
using System.Text;
86
using System.Windows;
97

108
namespace Flow.Launcher.Plugin.Explorer.Search
119
{
12-
internal static class ResultManager
10+
public class ResultManager
1311
{
14-
internal static Result CreateFolderResult(string title, string subtitle, string path, Query query, bool showIndexState = false, bool windowsIndexed = false)
12+
private readonly PluginInitContext context;
13+
14+
public ResultManager(PluginInitContext context)
15+
{
16+
this.context = context;
17+
}
18+
internal Result CreateFolderResult(string title, string subtitle, string path, Query query, bool showIndexState = false, bool windowsIndexed = false)
1519
{
1620
return new Result
1721
{
@@ -36,7 +40,7 @@ internal static Result CreateFolderResult(string title, string subtitle, string
3640
}
3741

3842
string changeTo = path.EndsWith(Constants.DirectorySeperator) ? path : path + Constants.DirectorySeperator;
39-
Main.Context.API.ChangeQuery(string.IsNullOrEmpty(query.ActionKeyword) ?
43+
context.API.ChangeQuery(string.IsNullOrEmpty(query.ActionKeyword) ?
4044
changeTo :
4145
query.ActionKeyword + " " + changeTo);
4246
return false;
@@ -45,7 +49,7 @@ internal static Result CreateFolderResult(string title, string subtitle, string
4549
};
4650
}
4751

48-
internal static Result CreateOpenCurrentFolderResult(string path, bool windowsIndexed = false)
52+
internal Result CreateOpenCurrentFolderResult(string path, bool windowsIndexed = false)
4953
{
5054
var retrievedDirectoryPath = FilesFolders.ReturnPreviousDirectoryIfIncompleteString(path);
5155

@@ -85,7 +89,7 @@ internal static Result CreateOpenCurrentFolderResult(string path, bool windowsIn
8589
};
8690
}
8791

88-
internal static Result CreateFileResult(string filePath, Query query, bool showIndexState = false, bool windowsIndexed = false)
92+
internal Result CreateFileResult(string filePath, Query query, bool showIndexState = false, bool windowsIndexed = false)
8993
{
9094
var result = new Result
9195
{

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

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Flow.Launcher.Plugin.Explorer.Search.DirectoryInfo;
1+
using Flow.Launcher.Plugin.Explorer.Search.DirectoryInfo;
22
using Flow.Launcher.Plugin.Explorer.Search.FolderLinks;
33
using Flow.Launcher.Plugin.Explorer.Search.WindowsIndex;
44
using Flow.Launcher.Plugin.SharedCommands;
@@ -10,25 +10,29 @@ namespace Flow.Launcher.Plugin.Explorer.Search
1010
{
1111
public class SearchManager
1212
{
13-
private Settings _settings;
14-
private PluginInitContext _context;
13+
private readonly PluginInitContext context;
1514

16-
private IndexSearch _indexSearch;
15+
private readonly IndexSearch indexSearch;
1716

18-
private QuickFolderAccess quickFolderAccess = new QuickFolderAccess();
17+
private readonly QuickFolderAccess quickFolderAccess = new QuickFolderAccess();
18+
19+
private readonly ResultManager resultManager;
20+
21+
private readonly Settings settings;
1922

2023
public SearchManager(Settings settings, PluginInitContext context)
2124
{
22-
_settings = settings;
23-
_context = context;
24-
_indexSearch = new IndexSearch();
25+
this.context = context;
26+
indexSearch = new IndexSearch(context);
27+
resultManager = new ResultManager(context);
28+
this.settings = settings;
2529
}
2630

2731
internal List<Result> Search(Query query)
2832
{
2933
var querySearch = query.Search;
3034

31-
var quickFolderLinks = quickFolderAccess.FolderList(query, _settings.QuickFolderAccessLinks);
35+
var quickFolderLinks = quickFolderAccess.FolderList(query, settings.QuickFolderAccessLinks, context);
3236

3337
if (quickFolderLinks.Count > 0)
3438
return quickFolderLinks;
@@ -40,7 +44,7 @@ internal List<Result> Search(Query query)
4044

4145
if (EnvironmentVariables.IsEnvironmentVariableSearch(locationPath))
4246
{
43-
return EnvironmentVariables.GetEnvironmentStringPathSuggestions(locationPath, query);
47+
return EnvironmentVariables.GetEnvironmentStringPathSuggestions(locationPath, query, context);
4448
}
4549

4650
// Query is a location path with a full environment variable, eg. %appdata%\somefolder\
@@ -56,7 +60,7 @@ internal List<Result> Search(Query query)
5660

5761
var useIndexSearch = UseWindowsIndexForDirectorySearch(locationPath);
5862

59-
results.Add(ResultManager.CreateOpenCurrentFolderResult(locationPath, useIndexSearch));
63+
results.Add(resultManager.CreateOpenCurrentFolderResult(locationPath, useIndexSearch));
6064

6165
results.AddRange(TopLevelDirectorySearchBehaviour(WindowsIndexTopLevelFolderSearch,
6266
DirectoryInfoClassSearch,
@@ -69,7 +73,7 @@ internal List<Result> Search(Query query)
6973

7074
private List<Result> DirectoryInfoClassSearch(Query query, string querySearch)
7175
{
72-
var directoryInfoSearch = new DirectoryInfoSearch(_settings);
76+
var directoryInfoSearch = new DirectoryInfoSearch(context);
7377

7478
return directoryInfoSearch.TopLevelDirectorySearch(query, querySearch);
7579
}
@@ -89,34 +93,34 @@ public List<Result> TopLevelDirectorySearchBehaviour(
8993

9094
private List<Result> WindowsIndexFilesAndFoldersSearch(Query query, string querySearchString)
9195
{
92-
var queryConstructor = new QueryConstructor(_settings);
96+
var queryConstructor = new QueryConstructor(settings);
9397

94-
return _indexSearch.WindowsIndexSearch(querySearchString,
98+
return indexSearch.WindowsIndexSearch(querySearchString,
9599
queryConstructor.CreateQueryHelper().ConnectionString,
96100
queryConstructor.QueryForAllFilesAndFolders,
97101
query);
98102
}
99103

100104
private List<Result> WindowsIndexTopLevelFolderSearch(Query query, string path)
101105
{
102-
var queryConstructor = new QueryConstructor(_settings);
106+
var queryConstructor = new QueryConstructor(settings);
103107

104-
return _indexSearch.WindowsIndexSearch(path,
108+
return indexSearch.WindowsIndexSearch(path,
105109
queryConstructor.CreateQueryHelper().ConnectionString,
106110
queryConstructor.QueryForTopLevelDirectorySearch,
107111
query);
108112
}
109113

110114
private bool UseWindowsIndexForDirectorySearch(string locationPath)
111115
{
112-
if (!_settings.UseWindowsIndexForDirectorySearch)
116+
if (!settings.UseWindowsIndexForDirectorySearch)
113117
return false;
114118

115-
if (_settings.IndexSearchExcludedSubdirectoryPaths
119+
if (settings.IndexSearchExcludedSubdirectoryPaths
116120
.Any(x => FilesFolders.ReturnPreviousDirectoryIfIncompleteString(locationPath).StartsWith(x.Path)))
117121
return false;
118122

119-
return _indexSearch.PathIsIndexed(locationPath);
123+
return indexSearch.PathIsIndexed(locationPath);
120124
}
121125
}
122126
}

0 commit comments

Comments
 (0)