Skip to content

Commit b8afbd7

Browse files
authored
Merge pull request #3586 from 01Dri/rename-quick-access-links
Enhancement: Rename Quick Access Links
2 parents a2ee428 + a6b6076 commit b8afbd7

File tree

10 files changed

+473
-101
lines changed

10 files changed

+473
-101
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ public List<Result> LoadContextMenus(Result selectedResult)
7575
{
7676
Settings.QuickAccessLinks.Add(new AccessLink
7777
{
78-
Path = record.FullPath, Type = record.Type
78+
Name = record.FullPath.GetPathName(),
79+
Path = record.FullPath,
80+
Type = record.Type
7981
});
8082

8183
Context.API.ShowMsg(Context.API.GetTranslation("plugin_explorer_addfilefoldersuccess"),
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.IO;
3+
using System.Linq;
4+
using Flow.Launcher.Plugin.Explorer.Search;
5+
6+
namespace Flow.Launcher.Plugin.Explorer.Helper;
7+
8+
public static class PathHelper
9+
{
10+
public static string GetPathName(this string selectedPath)
11+
{
12+
if (string.IsNullOrEmpty(selectedPath)) return string.Empty;
13+
var path = selectedPath.EndsWith(Constants.DirectorySeparator) ? selectedPath[0..^1] : selectedPath;
14+
15+
if (path.EndsWith(':'))
16+
return path[0..^1] + " Drive";
17+
18+
return path.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None)
19+
.Last();
20+
}
21+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
<!-- Dialogues -->
77
<system:String x:Key="plugin_explorer_make_selection_warning">Please make a selection first</system:String>
8+
<system:String x:Key="plugin_explorer_quick_access_link_no_folder_selected">Please select a folder path.</system:String>
9+
<system:String x:Key="plugin_explorer_quick_access_link_path_already_exists">Please choose a different name or folder path.</system:String>
810
<system:String x:Key="plugin_explorer_select_folder_link_warning">Please select a folder link</system:String>
911
<system:String x:Key="plugin_explorer_delete_folder_link">Are you sure you want to delete {0}?</system:String>
1012
<system:String x:Key="plugin_explorer_deletefileconfirm">Are you sure you want to permanently delete this file?</system:String>
@@ -27,6 +29,7 @@
2729
<system:String x:Key="plugin_explorer_add">Add</system:String>
2830
<system:String x:Key="plugin_explorer_generalsetting_header">General Setting</system:String>
2931
<system:String x:Key="plugin_explorer_manageactionkeywords_header">Customise Action Keywords</system:String>
32+
<system:String x:Key="plugin_explorer_manage_quick_access_links_header">Customise Quick Access</system:String>
3033
<system:String x:Key="plugin_explorer_quickaccesslinks_header">Quick Access Links</system:String>
3134
<system:String x:Key="plugin_explorer_everything_setting_header">Everything Setting</system:String>
3235
<system:String x:Key="plugin_explorer_previewpanel_setting_header">Preview Panel</system:String>
@@ -92,6 +95,7 @@
9295
<system:String x:Key="plugin_explorer_deletefile_subtitle">Permanently delete current file</system:String>
9396
<system:String x:Key="plugin_explorer_deletefolder_subtitle">Permanently delete current folder</system:String>
9497
<system:String x:Key="plugin_explorer_path">Path:</system:String>
98+
<system:String x:Key="plugin_explorer_name">Name:</system:String>
9599
<system:String x:Key="plugin_explorer_deletefilefolder_subtitle">Delete the selected</system:String>
96100
<system:String x:Key="plugin_explorer_runasdifferentuser">Run as different user</system:String>
97101
<system:String x:Key="plugin_explorer_runasdifferentuser_subtitle">Run the selected using a different user account</system:String>

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public Task InitAsync(PluginInitContext context)
3535
Context = context;
3636

3737
Settings = context.API.LoadSettingJsonStorage<Settings>();
38+
FillQuickAccessLinkNames();
3839

3940
viewModel = new SettingsViewModel(context, Settings);
4041

@@ -95,5 +96,17 @@ public string GetTranslatedPluginDescription()
9596
{
9697
return Context.API.GetTranslation("plugin_explorer_plugin_description");
9798
}
99+
100+
private void FillQuickAccessLinkNames()
101+
{
102+
// Legacy version does not have names for quick access links, so we fill them with the path name.
103+
foreach (var link in Settings.QuickAccessLinks)
104+
{
105+
if (string.IsNullOrWhiteSpace(link.Name))
106+
{
107+
link.Name = link.Path.GetPathName();
108+
}
109+
}
110+
}
98111
}
99112
}
Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,11 @@
1-
using System;
2-
using System.Linq;
3-
using System.Text.Json.Serialization;
4-
5-
namespace Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks
1+
namespace Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks
62
{
73
public class AccessLink
84
{
95
public string Path { get; set; }
106

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

13-
[JsonIgnore]
14-
public string Name
15-
{
16-
get
17-
{
18-
var path = Path.EndsWith(Constants.DirectorySeparator) ? Path[0..^1] : Path;
19-
20-
if (path.EndsWith(':'))
21-
return path[0..^1] + " Drive";
22-
23-
return path.Split(new[] { System.IO.Path.DirectorySeparatorChar }, StringSplitOptions.None)
24-
.Last();
25-
}
26-
}
9+
public string Name { get; set; }
2710
}
28-
2911
}

Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/SettingsViewModel.cs

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Windows;
1010
using System.Windows.Forms;
1111
using CommunityToolkit.Mvvm.Input;
12+
using Flow.Launcher.Plugin.Explorer.Helper;
1213
using Flow.Launcher.Plugin.Explorer.Search;
1314
using Flow.Launcher.Plugin.Explorer.Search.Everything;
1415
using Flow.Launcher.Plugin.Explorer.Search.Everything.Exceptions;
@@ -328,14 +329,10 @@ public void AppendLink(string containerName, AccessLink link)
328329
}
329330

330331
[RelayCommand]
331-
private void EditLink(object commandParameter)
332+
private void EditIndexSearchExcludePaths()
332333
{
333-
var (selectedLink, collection) = commandParameter switch
334-
{
335-
"QuickAccessLink" => (SelectedQuickAccessLink, Settings.QuickAccessLinks),
336-
"IndexSearchExcludedPaths" => (SelectedIndexSearchExcludedPath, Settings.IndexSearchExcludedSubdirectoryPaths),
337-
_ => throw new ArgumentOutOfRangeException(nameof(commandParameter))
338-
};
334+
var selectedLink = SelectedIndexSearchExcludedPath;
335+
var collection = Settings.IndexSearchExcludedSubdirectoryPaths;
339336

340337
if (selectedLink is null)
341338
{
@@ -354,45 +351,66 @@ private void EditLink(object commandParameter)
354351
collection.Remove(selectedLink);
355352
collection.Add(new AccessLink
356353
{
357-
Path = path, Type = selectedLink.Type,
354+
Path = path, Type = selectedLink.Type, Name = path.GetPathName()
358355
});
359-
}
360-
361-
private void ShowUnselectedMessage()
362-
{
363-
var warning = Context.API.GetTranslation("plugin_explorer_make_selection_warning");
364-
Context.API.ShowMsgBox(warning);
356+
Save();
365357
}
366358

367359
[RelayCommand]
368-
private void AddLink(object commandParameter)
360+
private void AddIndexSearchExcludePaths()
369361
{
370-
var container = commandParameter switch
371-
{
372-
"QuickAccessLink" => Settings.QuickAccessLinks,
373-
"IndexSearchExcludedPaths" => Settings.IndexSearchExcludedSubdirectoryPaths,
374-
_ => throw new ArgumentOutOfRangeException(nameof(commandParameter))
375-
};
376-
377-
ArgumentNullException.ThrowIfNull(container);
362+
var container = Settings.IndexSearchExcludedSubdirectoryPaths;
378363

364+
if (container is null) return;
365+
379366
var folderBrowserDialog = new FolderBrowserDialog();
380367

381368
if (folderBrowserDialog.ShowDialog() != DialogResult.OK)
382369
return;
383370

384371
var newAccessLink = new AccessLink
385372
{
373+
Name = folderBrowserDialog.SelectedPath.GetPathName(),
386374
Path = folderBrowserDialog.SelectedPath
387375
};
388376

389377
container.Add(newAccessLink);
378+
Save();
379+
}
380+
381+
[RelayCommand]
382+
private void EditQuickAccessLink()
383+
{
384+
var selectedLink = SelectedQuickAccessLink;
385+
var collection = Settings.QuickAccessLinks;
386+
387+
if (selectedLink is null)
388+
{
389+
ShowUnselectedMessage();
390+
return;
391+
}
392+
393+
var quickAccessLinkSettings = new QuickAccessLinkSettings(collection, SelectedQuickAccessLink);
394+
if (quickAccessLinkSettings.ShowDialog() == true)
395+
{
396+
Save();
397+
}
398+
}
399+
400+
[RelayCommand]
401+
private void AddQuickAccessLink()
402+
{
403+
var quickAccessLinkSettings = new QuickAccessLinkSettings(Settings.QuickAccessLinks);
404+
if (quickAccessLinkSettings.ShowDialog() == true)
405+
{
406+
Save();
407+
}
390408
}
391409

392410
[RelayCommand]
393-
private void RemoveLink(object obj)
411+
private void RemoveLink(object commandParameter)
394412
{
395-
if (obj is not string container) return;
413+
if (commandParameter is not string container) return;
396414

397415
switch (container)
398416
{
@@ -407,10 +425,16 @@ private void RemoveLink(object obj)
407425
}
408426
Save();
409427
}
428+
429+
private void ShowUnselectedMessage()
430+
{
431+
var warning = Context.API.GetTranslation("plugin_explorer_make_selection_warning");
432+
Context.API.ShowMsgBox(warning);
433+
}
410434

411435
#endregion
412436

413-
private string? PromptUserSelectPath(ResultType type, string? initialDirectory = null)
437+
private static string? PromptUserSelectPath(ResultType type, string? initialDirectory = null)
414438
{
415439
string? path = null;
416440

0 commit comments

Comments
 (0)