AI Review Refactor suggestion

This commit is contained in:
01Dri 2025-05-25 16:48:20 -03:00
parent cd62e7b5dc
commit 29831d61bb
3 changed files with 19 additions and 16 deletions

View file

@ -6,7 +6,7 @@
<!-- Dialogues --> <!-- Dialogues -->
<system:String x:Key="plugin_explorer_make_selection_warning">Please make a selection first</system:String> <system:String x:Key="plugin_explorer_make_selection_warning">Please make a selection first</system:String>
<system:String x:Key="plugin_explorer_quick_access_link_no_folder_selected">Please select a folder path.</system:String> <system:String x:Key="plugin_explorer_quick_access_link_no_folder_selected">Please select a folder path.</system:String>
<system:String x:Key="plugin_explorer_quick_access_link_select_different_folder">Please choose a different name or folder path.</system:String> <system:String x:Key="plugin_explorer_quick_access_link_path_already_exists">Please choose a different name or folder path.</system:String>
<system:String x:Key="plugin_explorer_select_folder_link_warning">Please select a folder link</system:String> <system:String x:Key="plugin_explorer_select_folder_link_warning">Please select a folder link</system:String>
<system:String x:Key="plugin_explorer_delete_folder_link">Are you sure you want to delete {0}?</system:String> <system:String x:Key="plugin_explorer_delete_folder_link">Are you sure you want to delete {0}?</system:String>
<system:String x:Key="plugin_explorer_deletefileconfirm">Are you sure you want to permanently delete this file?</system:String> <system:String x:Key="plugin_explorer_deletefileconfirm">Are you sure you want to permanently delete this file?</system:String>

View file

@ -9,6 +9,7 @@ using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Forms; using System.Windows.Forms;
using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Input;
using Flow.Launcher.Plugin.Explorer.Helper;
using Flow.Launcher.Plugin.Explorer.Search; using Flow.Launcher.Plugin.Explorer.Search;
using Flow.Launcher.Plugin.Explorer.Search.Everything; using Flow.Launcher.Plugin.Explorer.Search.Everything;
using Flow.Launcher.Plugin.Explorer.Search.Everything.Exceptions; using Flow.Launcher.Plugin.Explorer.Search.Everything.Exceptions;
@ -352,7 +353,7 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
collection.Remove(SelectedIndexSearchExcludedPath); collection.Remove(SelectedIndexSearchExcludedPath);
collection.Add(new AccessLink collection.Add(new AccessLink
{ {
Path = path, Type = selectedType, Path = path, Type = selectedType, Name = path.GetPathName()
}); });
} }
@ -368,10 +369,12 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
var newAccessLink = new AccessLink var newAccessLink = new AccessLink
{ {
Name = folderBrowserDialog.SelectedPath.GetPathName(),
Path = folderBrowserDialog.SelectedPath Path = folderBrowserDialog.SelectedPath
}; };
container.Add(newAccessLink); container.Add(newAccessLink);
Save();
} }
[RelayCommand] [RelayCommand]
@ -382,16 +385,15 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
ShowUnselectedMessage(); ShowUnselectedMessage();
return; return;
} }
var quickAccessLinkSettings = new QuickAccessLinkSettings(Settings.QuickAccessLinks,SelectedQuickAccessLink); var quickAccessLinkSettings = new QuickAccessLinkSettings(Settings.QuickAccessLinks,SelectedQuickAccessLink);
quickAccessLinkSettings.ShowDialog(); if (quickAccessLinkSettings.ShowDialog() == true) Save();
} }
[RelayCommand] [RelayCommand]
private void AddQuickAccessLink(object commandParameter) private void AddQuickAccessLink(object commandParameter)
{ {
var quickAccessLinkSettings = new QuickAccessLinkSettings(Settings.QuickAccessLinks); var quickAccessLinkSettings = new QuickAccessLinkSettings(Settings.QuickAccessLinks);
quickAccessLinkSettings.ShowDialog(); if (quickAccessLinkSettings.ShowDialog() == true) Save();
} }

View file

@ -52,9 +52,9 @@ public partial class QuickAccessLinkSettings : INotifyPropertyChanged
} }
private bool IsEdit { get; set; } private bool IsEdit { get; set; }
[CanBeNull] private AccessLink SelectedAccessLink { get; set; } [CanBeNull] private AccessLink SelectedAccessLink { get; }
public ObservableCollection<AccessLink> QuickAccessLinks { get; set; } public ObservableCollection<AccessLink> QuickAccessLinks { get; }
public QuickAccessLinkSettings(ObservableCollection<AccessLink> quickAccessLinks) public QuickAccessLinkSettings(ObservableCollection<AccessLink> quickAccessLinks)
{ {
@ -89,10 +89,12 @@ public partial class QuickAccessLinkSettings : INotifyPropertyChanged
Main.Context.API.ShowMsgBox(warning); Main.Context.API.ShowMsgBox(warning);
return; return;
} }
if (QuickAccessLinks.Any(x => x.Path == SelectedPath && x.Name == SelectedName)) if (QuickAccessLinks.Any(x =>
x.Path.Equals(SelectedPath, StringComparison.OrdinalIgnoreCase) &&
x.Name.Equals(SelectedName, StringComparison.OrdinalIgnoreCase)))
{ {
var warning = Main.Context.API.GetTranslation("plugin_explorer_quick_access_link_select_different_folder"); var warning = Main.Context.API.GetTranslation("plugin_explorer_quick_access_link_path_already_exists");
Main.Context.API.ShowMsgBox(warning); Main.Context.API.ShowMsgBox(warning);
return; return;
} }
@ -103,7 +105,7 @@ public partial class QuickAccessLinkSettings : INotifyPropertyChanged
} }
var newAccessLink = new AccessLink { Name = SelectedName, Path = SelectedPath }; var newAccessLink = new AccessLink { Name = SelectedName, Path = SelectedPath };
QuickAccessLinks.Add(newAccessLink); QuickAccessLinks.Add(newAccessLink);
DialogResult = false; DialogResult = true;
Close(); Close();
} }
@ -121,14 +123,13 @@ public partial class QuickAccessLinkSettings : INotifyPropertyChanged
{ {
if (SelectedAccessLink == null)throw new ArgumentException("Access Link object is null"); if (SelectedAccessLink == null)throw new ArgumentException("Access Link object is null");
var obj = QuickAccessLinks.FirstOrDefault(x => x.GetHashCode() == SelectedAccessLink.GetHashCode()); var index = QuickAccessLinks.IndexOf(SelectedAccessLink);
int index = QuickAccessLinks.IndexOf(obj);
if (index >= 0) if (index >= 0)
{ {
SelectedAccessLink = new AccessLink { Name = SelectedName, Path = SelectedPath }; var updatedLink = new AccessLink { Name = SelectedName, Path = SelectedPath };
QuickAccessLinks[index] = SelectedAccessLink; QuickAccessLinks[index] = updatedLink;
} }
DialogResult = false; DialogResult = true;
IsEdit = false; IsEdit = false;
Close(); Close();
} }