Skip to content

Commit fdeec11

Browse files
committed
FixLegacyQuickAccessLinkNames
1 parent a6a544a commit fdeec11

File tree

3 files changed

+40
-21
lines changed

3 files changed

+40
-21
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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 FolderPathHelper
9+
{
10+
public static string GetPathName(this string selectedPath)
11+
{
12+
if (string.IsNullOrEmpty(selectedPath)) return "";
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+
22+
}

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System;
77
using System.Collections.Generic;
88
using System.IO;
9+
using System.Linq;
910
using System.Threading;
1011
using System.Threading.Tasks;
1112
using System.Windows.Controls;
@@ -35,7 +36,8 @@ public Task InitAsync(PluginInitContext context)
3536
Context = context;
3637

3738
Settings = context.API.LoadSettingJsonStorage<Settings>();
38-
39+
FixLegacyQuickAccessLinkNames();
40+
3941
viewModel = new SettingsViewModel(context, Settings);
4042

4143
contextMenu = new ContextMenu(Context, Settings, viewModel);
@@ -95,5 +97,16 @@ public string GetTranslatedPluginDescription()
9597
{
9698
return Context.API.GetTranslation("plugin_explorer_plugin_description");
9799
}
100+
101+
private void FixLegacyQuickAccessLinkNames()
102+
{
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
}

Plugins/Flow.Launcher.Plugin.Explorer/Views/QuickAccessLinkSettings.xaml.cs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
using System;
22
using System.Collections.Generic;
33
using System.ComponentModel;
4-
using System.IO;
54
using System.Linq;
65
using System.Runtime.CompilerServices;
76
using System.Windows;
87
using System.Windows.Forms;
9-
using Flow.Launcher.Plugin.Explorer.Search;
8+
using Flow.Launcher.Plugin.Explorer.Helper;
109
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;
1110
using JetBrains.Annotations;
1211

@@ -26,7 +25,7 @@ public string SelectedPath
2625
{
2726
_selectedPath = value;
2827
OnPropertyChanged();
29-
if (string.IsNullOrEmpty(_selectedName)) SelectedName = GetPathName();
28+
if (string.IsNullOrEmpty(_selectedName)) SelectedName = _selectedPath.GetPathName();
3029
}
3130
}
3231
}
@@ -38,7 +37,7 @@ public string SelectedName
3837
{
3938
get
4039
{
41-
if (string.IsNullOrEmpty(_selectedName)) return GetPathName();
40+
if (string.IsNullOrEmpty(_selectedName)) return _selectedPath.GetPathName();
4241
return _selectedName;
4342
}
4443
set
@@ -116,26 +115,11 @@ private void SelectPath_OnClick(object commandParameter, RoutedEventArgs e)
116115

117116
SelectedPath = folderBrowserDialog.SelectedPath;
118117
}
119-
120-
private string GetPathName()
121-
{
122-
if (string.IsNullOrEmpty(SelectedPath)) return "";
123-
var path = SelectedPath.EndsWith(Constants.DirectorySeparator) ? SelectedPath[0..^1] : SelectedPath;
124-
125-
if (path.EndsWith(':'))
126-
return path[0..^1] + " Drive";
127-
128-
return path.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None)
129-
.Last();
130-
}
131-
118+
132119
private void EditAccessLink()
133120
{
134121
if (SelectedAccessLink == null)throw new ArgumentException("Access Link object is null");
135122

136-
137-
// Talvez nao seja preciso buscar pelo hash code, mas sim pelo nome ou path
138-
// Uma possivel validação, se pode nomes e paths iguais
139123
var obj = Settings.QuickAccessLinks.FirstOrDefault(x => x.GetHashCode() == SelectedAccessLink.GetHashCode());
140124
int index = Settings.QuickAccessLinks.IndexOf(obj);
141125
if (index >= 0)

0 commit comments

Comments
 (0)