Skip to content

Commit 3b42541

Browse files
committed
Edit access link
1 parent 74167a9 commit 3b42541

File tree

4 files changed

+74
-51
lines changed

4 files changed

+74
-51
lines changed
Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,13 @@
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;
12-
13-
public string Name { get; set; }
14-
15-
private string GetPathName()
16-
{
17-
var path = Path.EndsWith(Constants.DirectorySeparator) ? Path[0..^1] : Path;
188

19-
if (path.EndsWith(':'))
20-
return path[0..^1] + " Drive";
9+
public string Name { get; set; }
2110

22-
return path.Split(new[] { System.IO.Path.DirectorySeparatorChar }, StringSplitOptions.None)
23-
.Last();
24-
}
25-
2611
}
27-
12+
2813
}

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

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -328,33 +328,43 @@ public void AppendLink(string containerName, AccessLink link)
328328
}
329329

330330
[RelayCommand]
331-
private void EditLink(object commandParameter)
331+
private void EditQuickAccessLink(object commandParameter)
332332
{
333-
var (selectedLink, collection) = commandParameter switch
333+
if (SelectedQuickAccessLink is null)
334334
{
335-
"QuickAccessLink" => (SelectedQuickAccessLink, Settings.QuickAccessLinks),
336-
"IndexSearchExcludedPaths" => (SelectedIndexSearchExcludedPath, Settings.IndexSearchExcludedSubdirectoryPaths),
337-
_ => throw new ArgumentOutOfRangeException(nameof(commandParameter))
338-
};
335+
ShowUnselectedMessage();
336+
return;
337+
}
338+
339+
var quickAccessLinkSettings = new QuickAccessLinkSettings(SelectedQuickAccessLink);
340+
quickAccessLinkSettings.ShowDialog();
341+
}
342+
343+
[RelayCommand]
344+
private void EditIndexSearchExcludePaths(object commandParameter)
345+
{
346+
347+
var collection = Settings.IndexSearchExcludedSubdirectoryPaths;
339348

340-
if (selectedLink is null)
349+
if (SelectedIndexSearchExcludedPath is null)
341350
{
342351
ShowUnselectedMessage();
343352
return;
344353
}
345354

346-
var path = PromptUserSelectPath(selectedLink.Type,
347-
selectedLink.Type == ResultType.Folder
348-
? selectedLink.Path
349-
: Path.GetDirectoryName(selectedLink.Path));
355+
var path = PromptUserSelectPath(SelectedIndexSearchExcludedPath.Type,
356+
SelectedIndexSearchExcludedPath.Type == ResultType.Folder
357+
? SelectedIndexSearchExcludedPath.Path
358+
: Path.GetDirectoryName(SelectedIndexSearchExcludedPath.Path));
350359

351360
if (path is null)
352361
return;
353362

354-
collection.Remove(selectedLink);
363+
var selectedType = SelectedIndexSearchExcludedPath.Type;
364+
collection.Remove(SelectedIndexSearchExcludedPath);
355365
collection.Add(new AccessLink
356366
{
357-
Path = path, Type = selectedLink.Type,
367+
Path = path, Type = selectedType,
358368
});
359369
}
360370

Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@
756756
<Button
757757
MinWidth="100"
758758
Margin="{StaticResource SettingPanelItemLeftMargin}"
759-
Command="{Binding EditLinkCommand}"
759+
Command="{Binding EditQuickAccessLinkCommand}"
760760
CommandParameter="QuickAccessLink"
761761
Content="{DynamicResource plugin_explorer_edit}" />
762762
<Button
@@ -816,7 +816,7 @@
816816
<Button
817817
MinWidth="100"
818818
Margin="{StaticResource SettingPanelItemLeftMargin}"
819-
Command="{Binding EditLinkCommand}"
819+
Command="{Binding EditIndexSearchExcludePathsCommand}"
820820
CommandParameter="IndexSearchExcludedPaths"
821821
Content="{DynamicResource plugin_explorer_edit}" />
822822
<Button

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

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88
using System.Windows.Forms;
99
using Flow.Launcher.Plugin.Explorer.Search;
1010
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;
11+
using JetBrains.Annotations;
1112

1213
namespace Flow.Launcher.Plugin.Explorer.Views;
1314

1415
public partial class QuickAccessLinkSettings : INotifyPropertyChanged
1516
{
16-
17+
18+
private bool IsEdit { get; set; }
19+
[CanBeNull] private AccessLink SelectedAccessLink { get; set; }
1720
private string _selectedPath;
21+
1822
public string SelectedPath
1923
{
2024
get => _selectedPath;
@@ -29,8 +33,9 @@ public string SelectedPath
2933
}
3034
}
3135

32-
36+
3337
private string _selectedName;
38+
3439
public string SelectedName
3540
{
3641
get
@@ -48,20 +53,29 @@ public string SelectedName
4853
}
4954
}
5055

51-
5256
public QuickAccessLinkSettings()
5357
{
5458
InitializeComponent();
5559
}
56-
57-
58-
60+
61+
public QuickAccessLinkSettings(AccessLink selectedAccessLink)
62+
{
63+
IsEdit = true;
64+
_selectedName = selectedAccessLink.Name;
65+
_selectedPath = selectedAccessLink.Path;
66+
SelectedAccessLink = selectedAccessLink;
67+
InitializeComponent();
68+
}
69+
70+
71+
5972
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
6073
{
6174
DialogResult = false;
6275
Close();
6376
}
6477

78+
6579
private void OnDoneButtonClick(object sender, RoutedEventArgs e)
6680
{
6781
if (string.IsNullOrEmpty(SelectedName) && string.IsNullOrEmpty(SelectedPath))
@@ -70,15 +84,13 @@ private void OnDoneButtonClick(object sender, RoutedEventArgs e)
7084
Main.Context.API.ShowMsgBox(warning);
7185
return;
7286
}
73-
var container = Settings.QuickAccessLinks;
74-
75-
76-
// Lembrar de colocar uma logica pra evitar path e name vazios
77-
var newAccessLink = new AccessLink
87+
if (IsEdit)
7888
{
79-
Name = SelectedName,
80-
Path = SelectedPath
81-
};
89+
EditAccessLink();
90+
return;
91+
}
92+
var container = Settings.QuickAccessLinks;
93+
var newAccessLink = new AccessLink { Name = SelectedName, Path = SelectedPath };
8294
container.Add(newAccessLink);
8395
DialogResult = false;
8496
Close();
@@ -87,13 +99,13 @@ private void OnDoneButtonClick(object sender, RoutedEventArgs e)
8799
private void SelectPath_OnClick(object commandParameter, RoutedEventArgs e)
88100
{
89101
var folderBrowserDialog = new FolderBrowserDialog();
90-
102+
91103
if (folderBrowserDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
92104
return;
93105

94106
SelectedPath = folderBrowserDialog.SelectedPath;
95107
}
96-
108+
97109
private string GetPathName()
98110
{
99111
if (string.IsNullOrEmpty(SelectedPath)) return "";
@@ -105,8 +117,24 @@ private string GetPathName()
105117
return path.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None)
106118
.Last();
107119
}
108-
109-
public event PropertyChangedEventHandler PropertyChanged;
120+
121+
private void EditAccessLink()
122+
{
123+
if (SelectedAccessLink == null)throw new ArgumentException("Access Link object is null");
124+
125+
var obj = Settings.QuickAccessLinks.FirstOrDefault(x => x.GetHashCode() == SelectedAccessLink.GetHashCode());
126+
int index = Settings.QuickAccessLinks.IndexOf(obj);
127+
if (index >= 0)
128+
{
129+
SelectedAccessLink = new AccessLink { Name = SelectedName, Path = SelectedPath };
130+
Settings.QuickAccessLinks[index] = SelectedAccessLink;
131+
}
132+
DialogResult = false;
133+
IsEdit = false;
134+
Close();
135+
}
136+
137+
public event PropertyChangedEventHandler PropertyChanged;
110138

111139
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
112140
{

0 commit comments

Comments
 (0)