Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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 Down Expand Up @@ -98,28 +100,43 @@ 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 index = QuickAccessLinks.IndexOf(SelectedAccessLink);
if (index >= 0)
{
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
{
var updatedLink = new AccessLink
var newAccessLink = new AccessLink
{
Name = SelectedName,
Type = SelectedAccessLink.Type,
Type = AccessLinkType,
Path = SelectedPath
};
QuickAccessLinks[index] = updatedLink;
QuickAccessLinks.Add(newAccessLink);
DialogResult = true;
Close();
}
DialogResult = true;
Close();
}
// Otherwise, add a new one
else
{
var newAccessLink = new AccessLink
{
Name = SelectedName,
Type = AccessLinkType,
Path = SelectedPath
};
QuickAccessLinks.Add(newAccessLink);
Expand All @@ -130,12 +147,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
};

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

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