1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-02 00:15:02 -04:00

Use human sort order for all paths loaded into the UI

This commit is contained in:
Reinhard Pointner 2016-09-29 13:45:42 +08:00
parent 5b290cf0ae
commit 5a2087c2b4
3 changed files with 44 additions and 39 deletions

View File

@ -51,13 +51,14 @@ class FilesListTransferablePolicy extends BackgroundFileTransferablePolicy<File>
@Override
protected void load(List<File> files, TransferAction action) {
Set<File> fileset = new LinkedHashSet<File>();
// collect files recursively and eliminate duplicates
Set<File> sink = new LinkedHashSet<File>(64, 4);
// load files recursively by default
load(files, action != TransferAction.LINK, fileset);
load(files, action != TransferAction.LINK, sink);
// use fast file to minimize system calls like length(), isDirectory(), isFile(), ... and list files in human order
publish(fileset.stream().map(FastFile::new).toArray(File[]::new));
publish(sink.stream().map(FastFile::new).toArray(File[]::new));
}
private void load(List<File> files, boolean recursive, Collection<File> sink) {

View File

@ -1,5 +1,6 @@
package net.filebot.ui.transfer;
import static java.util.stream.Collectors.*;
import static net.filebot.Logging.*;
import static net.filebot.Settings.*;
import static net.filebot.util.FileUtilities.*;
@ -33,6 +34,14 @@ public class FileTransferable implements Transferable {
}
}
public static boolean isFileListFlavor(DataFlavor flavor) {
return flavor.isFlavorJavaFileListType() || flavor.equals(uriListFlavor);
}
public static boolean hasFileListFlavor(Transferable tr) {
return tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor) || tr.isDataFlavorSupported(FileTransferable.uriListFlavor);
}
private final File[] files;
public FileTransferable(File... files) {
@ -78,14 +87,6 @@ public class FileTransferable implements Transferable {
return isFileListFlavor(flavor);
}
public static boolean isFileListFlavor(DataFlavor flavor) {
return flavor.isFlavorJavaFileListType() || flavor.equals(uriListFlavor);
}
public static boolean hasFileListFlavor(Transferable tr) {
return tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor) || tr.isDataFlavorSupported(FileTransferable.uriListFlavor);
}
@SuppressWarnings("unchecked")
public static List<File> getFilesFromTransferable(Transferable tr) throws IOException, UnsupportedFlavorException {
// On Linux, if a file is dragged from a smb share to into a java application (e.g. Ubuntu Files to FileBot)
@ -96,7 +97,8 @@ public class FileTransferable implements Transferable {
if (tr.isDataFlavorSupported(FileTransferable.uriListFlavor)) {
// file URI list flavor (Linux)
Readable transferData = (Readable) tr.getTransferData(FileTransferable.uriListFlavor);
Scanner scanner = new Scanner(transferData);
try (Scanner scanner = new Scanner(transferData)) {
List<File> files = new ArrayList<File>();
while (scanner.hasNextLine()) {
@ -122,19 +124,23 @@ public class FileTransferable implements Transferable {
}
}
return sortByUniquePath(files); // FORCE NATURAL FILE ORDER
return files.stream().distinct().sorted(HUMAN_NAME_ORDER).collect(toList());
}
}
}
// Windows, Mac and default handling
// Windows / Mac and default handling
if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
// file list flavor
Object transferable = tr.getTransferData(DataFlavor.javaFileListFlavor);
if (transferable instanceof List) {
return sortByUniquePath((List<File>) transferable); // FORCE NATURAL FILE ORDER
} else {
return null; // on some platforms transferable data will not be available until the drop has been accepted
List<File> files = (List<File>) transferable;
return files.stream().distinct().sorted(HUMAN_NAME_ORDER).collect(toList());
}
// on some platforms transferable data will not be available until the drop has been accepted
return null;
}
// cannot get files from transferable

View File

@ -364,10 +364,8 @@ public final class FileUtilities {
}
public static List<File> sortByUniquePath(Collection<File> files) {
// sort by unique lower-case paths
TreeSet<File> sortedSet = new TreeSet<File>(CASE_INSENSITIVE_PATH_ORDER);
TreeSet<File> sortedSet = new TreeSet<File>(CASE_INSENSITIVE_PATH_ORDER); // sort by unique lower-case paths
sortedSet.addAll(files);
return new ArrayList<File>(sortedSet);
}