Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Plugins/Flow.Launcher.Plugin.Explorer/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<system:String x:Key="plugin_explorer_directoryinfosearch_error">Error occurred during search: {0}</system:String>
<system:String x:Key="plugin_explorer_opendir_error">Could not open folder</system:String>
<system:String x:Key="plugin_explorer_openfile_error">Could not open file</system:String>
<system:String x:Key="plugin_explorer_quickAccessLinkFileOrFolderTitle">Select type</system:String>
<system:String x:Key="plugin_explorer_quickAccessLinkFileOrFolderSubtitle">Do you want to select a file?{0}{0}Click 'Yes' for file, 'No' for folder.</system:String>

<!-- Controls -->
<system:String x:Key="plugin_explorer_delete">Delete</system:String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Windows;
using System.Windows.Forms;
using Flow.Launcher.Plugin.Explorer.Helper;
using Flow.Launcher.Plugin.Explorer.Search;
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;

namespace Flow.Launcher.Plugin.Explorer.Views;
Expand Down Expand Up @@ -49,7 +50,8 @@ public string SelectedName

private bool IsEdit { get; }
private AccessLink SelectedAccessLink { get; }

private ResultType AccessLinkType { get; set; } = ResultType.Folder;

public ObservableCollection<AccessLink> QuickAccessLinks { get; }

public QuickAccessLinkSettings(ObservableCollection<AccessLink> quickAccessLinks)
Expand All @@ -65,6 +67,7 @@ public QuickAccessLinkSettings(ObservableCollection<AccessLink> quickAccessLinks
_selectedName = selectedAccessLink.Name;
_selectedPath = selectedAccessLink.Path;
SelectedAccessLink = selectedAccessLink;
AccessLinkType = selectedAccessLink.Type;
QuickAccessLinks = quickAccessLinks;
InitializeComponent();
}
Expand Down Expand Up @@ -98,28 +101,40 @@ private void OnDoneButtonClick(object sender, RoutedEventArgs e)
// If editing, update the existing link
if (IsEdit)
{
if (SelectedAccessLink == null) return;

var index = QuickAccessLinks.IndexOf(SelectedAccessLink);
if (index >= 0)
if (SelectedAccessLink != null)
{
var updatedLink = new AccessLink
var index = QuickAccessLinks.IndexOf(SelectedAccessLink);
if (index >= 0)
{
Name = SelectedName,
Type = SelectedAccessLink.Type,
Path = SelectedPath
};
QuickAccessLinks[index] = updatedLink;
var updatedLink = new AccessLink
{
Name = SelectedName,
Type = AccessLinkType,
Path = SelectedPath
};
QuickAccessLinks[index] = updatedLink;
}
DialogResult = true;
Close();
}
// Add a new one if the selected access link is null (should not happen in edit mode, but just in case)
else
{
AddNewAccessLink();
}
DialogResult = true;
Close();
}
// Otherwise, add a new one
else
{
AddNewAccessLink();
}

void AddNewAccessLink()
Copy link

Copilot AI Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The AddNewAccessLink local function is nested inside OnDoneButtonClick, which can reduce readability. Consider extracting it to a private method so it's easier to test and maintain.

Suggested change
void AddNewAccessLink()
private void AddNewAccessLink()

Copilot uses AI. Check for mistakes.

{
var newAccessLink = new AccessLink
{
Name = SelectedName,
Type = AccessLinkType,
Path = SelectedPath
};
QuickAccessLinks.Add(newAccessLink);
Expand All @@ -130,12 +145,81 @@ private void OnDoneButtonClick(object sender, RoutedEventArgs e)

private void SelectPath_OnClick(object commandParameter, RoutedEventArgs e)
{
var folderBrowserDialog = new FolderBrowserDialog();
// If we are editing an existing access link, we should keep the file/folder type consistent.
ResultType type;
if (SelectedAccessLink != null)
{
type = SelectedAccessLink.Type;
}
// Else we should allow the user to select any file or folder.
else
{
var result = Main.Context.API.ShowMsgBox(
string.Format(
Main.Context.API.GetTranslation("plugin_explorer_quickAccessLinkFileOrFolderSubtitle"),
Environment.NewLine),
Main.Context.API.GetTranslation("plugin_explorer_quickAccessLinkFileOrFolderTitle"),
MessageBoxButton.YesNo, MessageBoxImage.Question);
type = result == MessageBoxResult.Yes ? ResultType.File : ResultType.Folder;
}

if (folderBrowserDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
return;
if (type == ResultType.File)
{
var dialog = new OpenFileDialog
{
Multiselect = false,
CheckFileExists = true,
CheckPathExists = true
};

if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
return;

SelectedPath = folderBrowserDialog.SelectedPath;
SelectedPath = dialog.FileName;
}
else
{
var dialog = new FolderBrowserDialog
{
ShowNewFolderButton = true
};

if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
return;

SelectedPath = dialog.SelectedPath;
}

AccessLinkType = GetResultType(SelectedPath);
}

private static ResultType GetResultType(string path)
{
if (string.IsNullOrEmpty(path))
{
return ResultType.Folder;
}

// Check if the path is a file or folder
if (System.IO.File.Exists(path))
{
return ResultType.File;
}
else if (System.IO.Directory.Exists(path))
{
if (string.Equals(System.IO.Path.GetPathRoot(path), path, StringComparison.OrdinalIgnoreCase))
{
return ResultType.Volume;
}
else
{
return ResultType.Folder;
}
}
else
{
return ResultType.Folder;
}
}

public event PropertyChangedEventHandler PropertyChanged;
Expand Down
Loading