mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
FixLegacyQuickAccessLinkNames
This commit is contained in:
parent
a6a544a488
commit
fdeec11896
3 changed files with 40 additions and 21 deletions
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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<Settings>();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue