Skip to content

Commit a6b6076

Browse files
committed
Set IsEdit get only & Add type & Improve code quality
1 parent 6d206c5 commit a6b6076

File tree

1 file changed

+34
-24
lines changed

1 file changed

+34
-24
lines changed

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

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public string SelectedName
4747
}
4848
}
4949

50-
private bool IsEdit { get; set; }
50+
private bool IsEdit { get; }
5151
private AccessLink SelectedAccessLink { get; }
5252

5353
public ObservableCollection<AccessLink> QuickAccessLinks { get; }
@@ -77,30 +77,55 @@ private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
7777

7878
private void OnDoneButtonClick(object sender, RoutedEventArgs e)
7979
{
80+
// Validate the input before proceeding
8081
if (string.IsNullOrEmpty(SelectedName) || string.IsNullOrEmpty(SelectedPath))
8182
{
8283
var warning = Main.Context.API.GetTranslation("plugin_explorer_quick_access_link_no_folder_selected");
8384
Main.Context.API.ShowMsgBox(warning);
8485
return;
8586
}
86-
87+
88+
// Check if the path already exists in the quick access links
8789
if (QuickAccessLinks.Any(x =>
8890
x.Path.Equals(SelectedPath, StringComparison.OrdinalIgnoreCase) &&
89-
x.Name.Equals(SelectedName, StringComparison.OrdinalIgnoreCase)))
91+
x.Name.Equals(SelectedName, StringComparison.OrdinalIgnoreCase)))
9092
{
9193
var warning = Main.Context.API.GetTranslation("plugin_explorer_quick_access_link_path_already_exists");
9294
Main.Context.API.ShowMsgBox(warning);
9395
return;
9496
}
97+
98+
// If editing, update the existing link
9599
if (IsEdit)
96100
{
97-
EditAccessLink();
98-
return;
101+
if (SelectedAccessLink == null) return;
102+
103+
var index = QuickAccessLinks.IndexOf(SelectedAccessLink);
104+
if (index >= 0)
105+
{
106+
var updatedLink = new AccessLink
107+
{
108+
Name = SelectedName,
109+
Type = SelectedAccessLink.Type,
110+
Path = SelectedPath
111+
};
112+
QuickAccessLinks[index] = updatedLink;
113+
}
114+
DialogResult = true;
115+
Close();
116+
}
117+
// Otherwise, add a new one
118+
else
119+
{
120+
var newAccessLink = new AccessLink
121+
{
122+
Name = SelectedName,
123+
Path = SelectedPath
124+
};
125+
QuickAccessLinks.Add(newAccessLink);
126+
DialogResult = true;
127+
Close();
99128
}
100-
var newAccessLink = new AccessLink { Name = SelectedName, Path = SelectedPath };
101-
QuickAccessLinks.Add(newAccessLink);
102-
DialogResult = true;
103-
Close();
104129
}
105130

106131
private void SelectPath_OnClick(object commandParameter, RoutedEventArgs e)
@@ -112,21 +137,6 @@ private void SelectPath_OnClick(object commandParameter, RoutedEventArgs e)
112137

113138
SelectedPath = folderBrowserDialog.SelectedPath;
114139
}
115-
116-
private void EditAccessLink()
117-
{
118-
if (SelectedAccessLink == null) return;
119-
120-
var index = QuickAccessLinks.IndexOf(SelectedAccessLink);
121-
if (index >= 0)
122-
{
123-
var updatedLink = new AccessLink { Name = SelectedName, Path = SelectedPath };
124-
QuickAccessLinks[index] = updatedLink;
125-
}
126-
DialogResult = true;
127-
IsEdit = false;
128-
Close();
129-
}
130140

131141
public event PropertyChangedEventHandler PropertyChanged;
132142

0 commit comments

Comments
 (0)