Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
@@ -1,11 +1,13 @@
using System;
using System.Collections.ObjectModel;
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.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 +51,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 +68,7 @@ public QuickAccessLinkSettings(ObservableCollection<AccessLink> quickAccessLinks
_selectedName = selectedAccessLink.Name;
_selectedPath = selectedAccessLink.Path;
SelectedAccessLink = selectedAccessLink;
AccessLinkType = selectedAccessLink.Type;
QuickAccessLinks = quickAccessLinks;
InitializeComponent();
}
Expand Down Expand Up @@ -96,30 +100,42 @@ private void OnDoneButtonClick(object sender, RoutedEventArgs e)
}

// If editing, update the existing link
if (IsEdit)
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 +146,79 @@ 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 ||
string.IsNullOrEmpty(dialog.FileName))
return;

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

if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK ||
string.IsNullOrEmpty(dialog.SelectedPath))
return;

SelectedPath = folderBrowserDialog.SelectedPath;
SelectedPath = dialog.SelectedPath;
}

AccessLinkType = GetResultType(SelectedPath);
}

private static ResultType GetResultType(string path)
{
// Check if the path is a file or folder
if (File.Exists(path))
{
return ResultType.File;
}
else if (Directory.Exists(path))
{
if (string.Equals(Path.GetPathRoot(path), path, StringComparison.OrdinalIgnoreCase))
{
return ResultType.Volume;
}
else
{
return ResultType.Folder;
}
}
else
{
// This should not happen, but just in case, we assume it's a folder
return ResultType.Folder;
}
}

public event PropertyChangedEventHandler PropertyChanged;
Expand Down
Loading