Skip to content
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

File widgets: sort list in drag-and-drop operation #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

imagejan
Copy link
Member

@imagejan imagejan commented Apr 8, 2022

Some file systems provide files in an unsorted way, resulting in e.g. the FileListWidget containing an unordered list when folder content is added. This pull request aims to improve user experience by always sorting the list of files returned by SwingFileWidget.getFiles().

@imagejan imagejan requested a review from ctrueden April 8, 2022 20:32
@ctrueden
Copy link
Member

ctrueden commented Apr 8, 2022

I tested the current behavior on macOS, and dragging from Finder, the order is consistent with how the files are listed/sorted, which seems like a good thing to me. When sorted by "Date Modified" for example, I would expect the files to drop into Fiji in that same order: the order they appear listed in Finder.

Which file systems provide files in an unsorted way? Perhaps we could sort only for those file systems?

@imagejan
Copy link
Member Author

imagejan commented Apr 9, 2022

Thanks, @ctrueden, for testing.

My use case was on Windows with a samba-mounted GPFS. I should have specified that I was dragging a single folder onto the Add folder content... button. In this case, you don't have an open Explorer window with a custom sorting.

I can confirm that when dragging multiple selected files the order of the files is conserved from how they're listed in Explorer.

So I guess the default sorting should be implemented for the folder content button only, which would be here:

private List<File> getFilesFromFolder(File inputFolder) {
// get files in folder and add to listModel
List<File> fileList = new ArrayList<>();
final WidgetModel widgetModel = get();
final String widgetStyle = widgetModel.getItem().getWidgetStyle();
FileFilter filter = SwingFileWidget.createFileFilter(widgetStyle);
try {
fileList = Arrays
.asList((Files.walk(inputFolder.toPath())
.filter(path -> filter.accept(path.toFile())))
.map(path -> path.toFile())
.toArray(File[]::new));
} catch (IOException exc) {
logService
.error("Error when trying to retrieve file list", exc);
}
return fileList;

Do you agree? I can update this PR accordingly.

@imagejan imagejan self-assigned this Apr 9, 2022
@ctrueden
Copy link
Member

ctrueden commented Apr 9, 2022

Do you agree?

Yes, that seems right to me (although I didn't have time to test it).

I can update this PR accordingly.

Thanks!

@imagejan
Copy link
Member Author

@ctrueden, I updated this pull request to only sort the file list when adding the (possibly filtered) content of an entire folder to the file list. (Sorry I didn't have a chance to test extensively with the samba-mounted file system yet because I'm currently traveling.)

@imagejan imagejan removed their assignment Jun 23, 2022
@imagejan imagejan removed the question label Jul 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants