Use human sort order for all paths loaded into the UI
This commit is contained in:
parent
5b290cf0ae
commit
5a2087c2b4
|
@ -51,13 +51,14 @@ class FilesListTransferablePolicy extends BackgroundFileTransferablePolicy<File>
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void load(List<File> files, TransferAction action) {
|
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 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
|
// 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) {
|
private void load(List<File> files, boolean recursive, Collection<File> sink) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.filebot.ui.transfer;
|
package net.filebot.ui.transfer;
|
||||||
|
|
||||||
|
import static java.util.stream.Collectors.*;
|
||||||
import static net.filebot.Logging.*;
|
import static net.filebot.Logging.*;
|
||||||
import static net.filebot.Settings.*;
|
import static net.filebot.Settings.*;
|
||||||
import static net.filebot.util.FileUtilities.*;
|
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;
|
private final File[] files;
|
||||||
|
|
||||||
public FileTransferable(File... files) {
|
public FileTransferable(File... files) {
|
||||||
|
@ -78,14 +87,6 @@ public class FileTransferable implements Transferable {
|
||||||
return isFileListFlavor(flavor);
|
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")
|
@SuppressWarnings("unchecked")
|
||||||
public static List<File> getFilesFromTransferable(Transferable tr) throws IOException, UnsupportedFlavorException {
|
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)
|
// 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)) {
|
if (tr.isDataFlavorSupported(FileTransferable.uriListFlavor)) {
|
||||||
// file URI list flavor (Linux)
|
// file URI list flavor (Linux)
|
||||||
Readable transferData = (Readable) tr.getTransferData(FileTransferable.uriListFlavor);
|
Readable transferData = (Readable) tr.getTransferData(FileTransferable.uriListFlavor);
|
||||||
Scanner scanner = new Scanner(transferData);
|
|
||||||
|
try (Scanner scanner = new Scanner(transferData)) {
|
||||||
List<File> files = new ArrayList<File>();
|
List<File> files = new ArrayList<File>();
|
||||||
|
|
||||||
while (scanner.hasNextLine()) {
|
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)) {
|
if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
|
||||||
// file list flavor
|
// file list flavor
|
||||||
Object transferable = tr.getTransferData(DataFlavor.javaFileListFlavor);
|
Object transferable = tr.getTransferData(DataFlavor.javaFileListFlavor);
|
||||||
|
|
||||||
if (transferable instanceof List) {
|
if (transferable instanceof List) {
|
||||||
return sortByUniquePath((List<File>) transferable); // FORCE NATURAL FILE ORDER
|
List<File> files = (List<File>) transferable;
|
||||||
} else {
|
return files.stream().distinct().sorted(HUMAN_NAME_ORDER).collect(toList());
|
||||||
return null; // on some platforms transferable data will not be available until the drop has been accepted
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// on some platforms transferable data will not be available until the drop has been accepted
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// cannot get files from transferable
|
// cannot get files from transferable
|
||||||
|
|
|
@ -364,10 +364,8 @@ public final class FileUtilities {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<File> sortByUniquePath(Collection<File> files) {
|
public static List<File> sortByUniquePath(Collection<File> files) {
|
||||||
// sort by unique lower-case paths
|
TreeSet<File> sortedSet = new TreeSet<File>(CASE_INSENSITIVE_PATH_ORDER); // sort by unique lower-case paths
|
||||||
TreeSet<File> sortedSet = new TreeSet<File>(CASE_INSENSITIVE_PATH_ORDER);
|
|
||||||
sortedSet.addAll(files);
|
sortedSet.addAll(files);
|
||||||
|
|
||||||
return new ArrayList<File>(sortedSet);
|
return new ArrayList<File>(sortedSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue