Skip to content

Conversation

@imagejan
Copy link
Member

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().

@imagejanimagejan requested a review from ctruedenApril 8, 2022 20:32
@ctrueden
Copy link
Member

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
MemberAuthor

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:

privateList<File> getFilesFromFolder(FileinputFolder){
// get files in folder and add to listModel
List<File> fileList = newArrayList<>();
finalWidgetModelwidgetModel = get();
finalStringwidgetStyle = widgetModel.getItem().getWidgetStyle();
FileFilterfilter = 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 (IOExceptionexc){
logService
.error("Error when trying to retrieve file list", exc);
}
returnfileList;

Do you agree? I can update this PR accordingly.

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

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
MemberAuthor

@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.)

@imagejanimagejan removed their assignment Jun 23, 2022
Sign up for freeto 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.

3 participants

@imagejan@ctrueden