Skip to content

Commit 29831d6

Browse files
committed
AI Review Refactor suggestion
1 parent cd62e7b commit 29831d6

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<!-- Dialogues -->
77
<system:String x:Key="plugin_explorer_make_selection_warning">Please make a selection first</system:String>
88
<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_select_different_folder">Please choose a different name or 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>
1010
<system:String x:Key="plugin_explorer_select_folder_link_warning">Please select a folder link</system:String>
1111
<system:String x:Key="plugin_explorer_delete_folder_link">Are you sure you want to delete {0}?</system:String>
1212
<system:String x:Key="plugin_explorer_deletefileconfirm">Are you sure you want to permanently delete this file?</system:String>

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

Lines changed: 6 additions & 4 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;
@@ -352,7 +353,7 @@ private void EditIndexSearchExcludePaths(object commandParameter)
352353
collection.Remove(SelectedIndexSearchExcludedPath);
353354
collection.Add(new AccessLink
354355
{
355-
Path = path, Type = selectedType,
356+
Path = path, Type = selectedType, Name = path.GetPathName()
356357
});
357358
}
358359

@@ -368,10 +369,12 @@ private void AddIndexSearchExcludePaths(object commandParameter)
368369

369370
var newAccessLink = new AccessLink
370371
{
372+
Name = folderBrowserDialog.SelectedPath.GetPathName(),
371373
Path = folderBrowserDialog.SelectedPath
372374
};
373375

374376
container.Add(newAccessLink);
377+
Save();
375378
}
376379

377380
[RelayCommand]
@@ -382,16 +385,15 @@ private void EditQuickAccessLink(object commandParameter)
382385
ShowUnselectedMessage();
383386
return;
384387
}
385-
386388
var quickAccessLinkSettings = new QuickAccessLinkSettings(Settings.QuickAccessLinks,SelectedQuickAccessLink);
387-
quickAccessLinkSettings.ShowDialog();
389+
if (quickAccessLinkSettings.ShowDialog() == true) Save();
388390
}
389391

390392
[RelayCommand]
391393
private void AddQuickAccessLink(object commandParameter)
392394
{
393395
var quickAccessLinkSettings = new QuickAccessLinkSettings(Settings.QuickAccessLinks);
394-
quickAccessLinkSettings.ShowDialog();
396+
if (quickAccessLinkSettings.ShowDialog() == true) Save();
395397
}
396398

397399

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public string SelectedName
5252
}
5353

5454
private bool IsEdit { get; set; }
55-
[CanBeNull] private AccessLink SelectedAccessLink { get; set; }
55+
[CanBeNull] private AccessLink SelectedAccessLink { get; }
5656

57-
public ObservableCollection<AccessLink> QuickAccessLinks { get; set; }
57+
public ObservableCollection<AccessLink> QuickAccessLinks { get; }
5858

5959
public QuickAccessLinkSettings(ObservableCollection<AccessLink> quickAccessLinks)
6060
{
@@ -89,10 +89,12 @@ private void OnDoneButtonClick(object sender, RoutedEventArgs e)
8989
Main.Context.API.ShowMsgBox(warning);
9090
return;
9191
}
92-
93-
if (QuickAccessLinks.Any(x => x.Path == SelectedPath && x.Name == SelectedName))
92+
93+
if (QuickAccessLinks.Any(x =>
94+
x.Path.Equals(SelectedPath, StringComparison.OrdinalIgnoreCase) &&
95+
x.Name.Equals(SelectedName, StringComparison.OrdinalIgnoreCase)))
9496
{
95-
var warning = Main.Context.API.GetTranslation("plugin_explorer_quick_access_link_select_different_folder");
97+
var warning = Main.Context.API.GetTranslation("plugin_explorer_quick_access_link_path_already_exists");
9698
Main.Context.API.ShowMsgBox(warning);
9799
return;
98100
}
@@ -103,7 +105,7 @@ private void OnDoneButtonClick(object sender, RoutedEventArgs e)
103105
}
104106
var newAccessLink = new AccessLink { Name = SelectedName, Path = SelectedPath };
105107
QuickAccessLinks.Add(newAccessLink);
106-
DialogResult = false;
108+
DialogResult = true;
107109
Close();
108110
}
109111

@@ -121,14 +123,13 @@ private void EditAccessLink()
121123
{
122124
if (SelectedAccessLink == null)throw new ArgumentException("Access Link object is null");
123125

124-
var obj = QuickAccessLinks.FirstOrDefault(x => x.GetHashCode() == SelectedAccessLink.GetHashCode());
125-
int index = QuickAccessLinks.IndexOf(obj);
126+
var index = QuickAccessLinks.IndexOf(SelectedAccessLink);
126127
if (index >= 0)
127128
{
128-
SelectedAccessLink = new AccessLink { Name = SelectedName, Path = SelectedPath };
129-
QuickAccessLinks[index] = SelectedAccessLink;
129+
var updatedLink = new AccessLink { Name = SelectedName, Path = SelectedPath };
130+
QuickAccessLinks[index] = updatedLink;
130131
}
131-
DialogResult = false;
132+
DialogResult = true;
132133
IsEdit = false;
133134
Close();
134135
}

0 commit comments

Comments
 (0)