diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Helper/FolderPathHelper.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Helper/FolderPathHelper.cs new file mode 100644 index 000000000..74e23be3a --- /dev/null +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Helper/FolderPathHelper.cs @@ -0,0 +1,22 @@ +using System; +using System.IO; +using System.Linq; +using Flow.Launcher.Plugin.Explorer.Search; + +namespace Flow.Launcher.Plugin.Explorer.Helper; + +public static class FolderPathHelper +{ + public static string GetPathName(this string selectedPath) + { + if (string.IsNullOrEmpty(selectedPath)) return ""; + var path = selectedPath.EndsWith(Constants.DirectorySeparator) ? selectedPath[0..^1] : selectedPath; + + if (path.EndsWith(':')) + return path[0..^1] + " Drive"; + + return path.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None) + .Last(); + } + +} diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs index 1c5d074a0..cb2d29ec1 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Main.cs @@ -6,6 +6,7 @@ using Flow.Launcher.Plugin.Explorer.Views; using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Threading; using System.Threading.Tasks; using System.Windows.Controls; @@ -35,7 +36,8 @@ namespace Flow.Launcher.Plugin.Explorer Context = context; Settings = context.API.LoadSettingJsonStorage(); - + FixLegacyQuickAccessLinkNames(); + viewModel = new SettingsViewModel(context, Settings); contextMenu = new ContextMenu(Context, Settings, viewModel); @@ -95,5 +97,16 @@ namespace Flow.Launcher.Plugin.Explorer { return Context.API.GetTranslation("plugin_explorer_plugin_description"); } + + private void FixLegacyQuickAccessLinkNames() + { + foreach (var link in Settings.QuickAccessLinks) + { + if (string.IsNullOrWhiteSpace(link.Name)) + { + link.Name = link.Path.GetPathName(); + } + } + } } } diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Views/QuickAccessLinkSettings.xaml.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Views/QuickAccessLinkSettings.xaml.cs index e12898b5e..5eda62558 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Views/QuickAccessLinkSettings.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Views/QuickAccessLinkSettings.xaml.cs @@ -1,12 +1,11 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Windows; using System.Windows.Forms; -using Flow.Launcher.Plugin.Explorer.Search; +using Flow.Launcher.Plugin.Explorer.Helper; using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks; using JetBrains.Annotations; @@ -26,7 +25,7 @@ public partial class QuickAccessLinkSettings : INotifyPropertyChanged { _selectedPath = value; OnPropertyChanged(); - if (string.IsNullOrEmpty(_selectedName)) SelectedName = GetPathName(); + if (string.IsNullOrEmpty(_selectedName)) SelectedName = _selectedPath.GetPathName(); } } } @@ -38,7 +37,7 @@ public partial class QuickAccessLinkSettings : INotifyPropertyChanged { get { - if (string.IsNullOrEmpty(_selectedName)) return GetPathName(); + if (string.IsNullOrEmpty(_selectedName)) return _selectedPath.GetPathName(); return _selectedName; } set @@ -116,26 +115,11 @@ public partial class QuickAccessLinkSettings : INotifyPropertyChanged SelectedPath = folderBrowserDialog.SelectedPath; } - - private string GetPathName() - { - if (string.IsNullOrEmpty(SelectedPath)) return ""; - var path = SelectedPath.EndsWith(Constants.DirectorySeparator) ? SelectedPath[0..^1] : SelectedPath; - - if (path.EndsWith(':')) - return path[0..^1] + " Drive"; - - return path.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None) - .Last(); - } - + private void EditAccessLink() { if (SelectedAccessLink == null)throw new ArgumentException("Access Link object is null"); - - // Talvez nao seja preciso buscar pelo hash code, mas sim pelo nome ou path - // Uma possivel validação, se pode nomes e paths iguais var obj = Settings.QuickAccessLinks.FirstOrDefault(x => x.GetHashCode() == SelectedAccessLink.GetHashCode()); int index = Settings.QuickAccessLinks.IndexOf(obj); if (index >= 0)