Edit access link

This commit is contained in:
01Dri 2025-05-25 04:31:08 -03:00
parent 74167a91e3
commit 3b425413a2
4 changed files with 74 additions and 51 deletions

View file

@ -1,28 +1,13 @@
using System;
using System.Linq;
using System.Text.Json.Serialization;
namespace Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks
namespace Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks
{
public class AccessLink
{
public string Path { get; set; }
public ResultType Type { get; set; } = ResultType.Folder;
public string Name { get; set; }
private string GetPathName()
{
var path = Path.EndsWith(Constants.DirectorySeparator) ? Path[0..^1] : Path;
if (path.EndsWith(':'))
return path[0..^1] + " Drive";
return path.Split(new[] { System.IO.Path.DirectorySeparatorChar }, StringSplitOptions.None)
.Last();
}
}
}

View file

@ -328,33 +328,43 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
}
[RelayCommand]
private void EditLink(object commandParameter)
private void EditQuickAccessLink(object commandParameter)
{
var (selectedLink, collection) = commandParameter switch
if (SelectedQuickAccessLink is null)
{
"QuickAccessLink" => (SelectedQuickAccessLink, Settings.QuickAccessLinks),
"IndexSearchExcludedPaths" => (SelectedIndexSearchExcludedPath, Settings.IndexSearchExcludedSubdirectoryPaths),
_ => throw new ArgumentOutOfRangeException(nameof(commandParameter))
};
ShowUnselectedMessage();
return;
}
var quickAccessLinkSettings = new QuickAccessLinkSettings(SelectedQuickAccessLink);
quickAccessLinkSettings.ShowDialog();
}
if (selectedLink is null)
[RelayCommand]
private void EditIndexSearchExcludePaths(object commandParameter)
{
var collection = Settings.IndexSearchExcludedSubdirectoryPaths;
if (SelectedIndexSearchExcludedPath is null)
{
ShowUnselectedMessage();
return;
}
var path = PromptUserSelectPath(selectedLink.Type,
selectedLink.Type == ResultType.Folder
? selectedLink.Path
: Path.GetDirectoryName(selectedLink.Path));
var path = PromptUserSelectPath(SelectedIndexSearchExcludedPath.Type,
SelectedIndexSearchExcludedPath.Type == ResultType.Folder
? SelectedIndexSearchExcludedPath.Path
: Path.GetDirectoryName(SelectedIndexSearchExcludedPath.Path));
if (path is null)
return;
collection.Remove(selectedLink);
var selectedType = SelectedIndexSearchExcludedPath.Type;
collection.Remove(SelectedIndexSearchExcludedPath);
collection.Add(new AccessLink
{
Path = path, Type = selectedLink.Type,
Path = path, Type = selectedType,
});
}

View file

@ -756,7 +756,7 @@
<Button
MinWidth="100"
Margin="{StaticResource SettingPanelItemLeftMargin}"
Command="{Binding EditLinkCommand}"
Command="{Binding EditQuickAccessLinkCommand}"
CommandParameter="QuickAccessLink"
Content="{DynamicResource plugin_explorer_edit}" />
<Button
@ -816,7 +816,7 @@
<Button
MinWidth="100"
Margin="{StaticResource SettingPanelItemLeftMargin}"
Command="{Binding EditLinkCommand}"
Command="{Binding EditIndexSearchExcludePathsCommand}"
CommandParameter="IndexSearchExcludedPaths"
Content="{DynamicResource plugin_explorer_edit}" />
<Button

View file

@ -8,13 +8,17 @@ using System.Windows;
using System.Windows.Forms;
using Flow.Launcher.Plugin.Explorer.Search;
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;
using JetBrains.Annotations;
namespace Flow.Launcher.Plugin.Explorer.Views;
public partial class QuickAccessLinkSettings : INotifyPropertyChanged
{
private bool IsEdit { get; set; }
[CanBeNull] private AccessLink SelectedAccessLink { get; set; }
private string _selectedPath;
public string SelectedPath
{
get => _selectedPath;
@ -29,8 +33,9 @@ public partial class QuickAccessLinkSettings : INotifyPropertyChanged
}
}
private string _selectedName;
public string SelectedName
{
get
@ -48,20 +53,29 @@ public partial class QuickAccessLinkSettings : INotifyPropertyChanged
}
}
public QuickAccessLinkSettings()
{
InitializeComponent();
}
public QuickAccessLinkSettings(AccessLink selectedAccessLink)
{
IsEdit = true;
_selectedName = selectedAccessLink.Name;
_selectedPath = selectedAccessLink.Path;
SelectedAccessLink = selectedAccessLink;
InitializeComponent();
}
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
{
DialogResult = false;
Close();
}
private void OnDoneButtonClick(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(SelectedName) && string.IsNullOrEmpty(SelectedPath))
@ -70,15 +84,13 @@ public partial class QuickAccessLinkSettings : INotifyPropertyChanged
Main.Context.API.ShowMsgBox(warning);
return;
}
var container = Settings.QuickAccessLinks;
// Lembrar de colocar uma logica pra evitar path e name vazios
var newAccessLink = new AccessLink
if (IsEdit)
{
Name = SelectedName,
Path = SelectedPath
};
EditAccessLink();
return;
}
var container = Settings.QuickAccessLinks;
var newAccessLink = new AccessLink { Name = SelectedName, Path = SelectedPath };
container.Add(newAccessLink);
DialogResult = false;
Close();
@ -87,13 +99,13 @@ public partial class QuickAccessLinkSettings : INotifyPropertyChanged
private void SelectPath_OnClick(object commandParameter, RoutedEventArgs e)
{
var folderBrowserDialog = new FolderBrowserDialog();
if (folderBrowserDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
return;
SelectedPath = folderBrowserDialog.SelectedPath;
}
private string GetPathName()
{
if (string.IsNullOrEmpty(SelectedPath)) return "";
@ -105,8 +117,24 @@ public partial class QuickAccessLinkSettings : INotifyPropertyChanged
return path.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None)
.Last();
}
public event PropertyChangedEventHandler PropertyChanged;
private void EditAccessLink()
{
if (SelectedAccessLink == null)throw new ArgumentException("Access Link object is null");
var obj = Settings.QuickAccessLinks.FirstOrDefault(x => x.GetHashCode() == SelectedAccessLink.GetHashCode());
int index = Settings.QuickAccessLinks.IndexOf(obj);
if (index >= 0)
{
SelectedAccessLink = new AccessLink { Name = SelectedName, Path = SelectedPath };
Settings.QuickAccessLinks[index] = SelectedAccessLink;
}
DialogResult = false;
IsEdit = false;
Close();
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{