-
-
Notifications
You must be signed in to change notification settings - Fork 448
Support select file & folder in quick link access add button #3738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e4f02f9
Support select file & folder in quick link access add button
Jack251970 6df88c9
Use one function
Jack251970 b8768fe
Preserve original link type
Jack251970 5c97e78
Check null empty ealier
Jack251970 b89e05f
Code quality
Jack251970 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||||||
|
@@ -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) | ||||||
|
@@ -65,6 +68,7 @@ public QuickAccessLinkSettings(ObservableCollection<AccessLink> quickAccessLinks | |||||
_selectedName = selectedAccessLink.Name; | ||||||
_selectedPath = selectedAccessLink.Path; | ||||||
SelectedAccessLink = selectedAccessLink; | ||||||
AccessLinkType = selectedAccessLink.Type; | ||||||
QuickAccessLinks = quickAccessLinks; | ||||||
InitializeComponent(); | ||||||
} | ||||||
|
@@ -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) | ||||||
Jack251970 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
else | ||||||
{ | ||||||
Jack251970 marked this conversation as resolved.
Show resolved
Hide resolved
Jack251970 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
AddNewAccessLink(); | ||||||
} | ||||||
DialogResult = true; | ||||||
Close(); | ||||||
} | ||||||
// Otherwise, add a new one | ||||||
else | ||||||
{ | ||||||
AddNewAccessLink(); | ||||||
} | ||||||
|
||||||
void AddNewAccessLink() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] The
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
{ | ||||||
var newAccessLink = new AccessLink | ||||||
{ | ||||||
Name = SelectedName, | ||||||
Type = AccessLinkType, | ||||||
Path = SelectedPath | ||||||
}; | ||||||
QuickAccessLinks.Add(newAccessLink); | ||||||
|
@@ -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; | ||||||
Jack251970 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
} | ||||||
|
||||||
public event PropertyChangedEventHandler PropertyChanged; | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.