1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-24 16:58:51 -05:00

* enforce good alphabetical order for all dropped data (on Windows files a dropped in selection order which can be confusing)

This commit is contained in:
Reinhard Pointner 2014-07-18 22:03:27 +00:00
parent 093a38593d
commit d69b1da6a3

View File

@ -1,8 +1,7 @@
package net.filebot.ui.transfer;
import static net.filebot.Settings.*;
import static net.filebot.util.FileUtilities.*;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
@ -22,12 +21,10 @@ import java.util.logging.Logger;
import net.filebot.gio.GVFS;
public class FileTransferable implements Transferable {
public static final DataFlavor uriListFlavor = createUriListFlavor();
private static DataFlavor createUriListFlavor() {
try {
return new DataFlavor("text/uri-list;class=java.nio.CharBuffer");
@ -39,17 +36,14 @@ public class FileTransferable implements Transferable {
private final File[] files;
public FileTransferable(File... files) {
this.files = files;
}
public FileTransferable(Collection<File> files) {
this.files = files.toArray(new File[0]);
}
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
if (flavor.isFlavorJavaFileListType())
@ -60,7 +54,6 @@ public class FileTransferable implements Transferable {
throw new UnsupportedFlavorException(flavor);
}
/**
* @return line separated list of file URIs
*/
@ -76,34 +69,29 @@ public class FileTransferable implements Transferable {
return sb.toString();
}
@Override
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[] { DataFlavor.javaFileListFlavor, uriListFlavor };
}
@Override
public boolean isDataFlavorSupported(DataFlavor 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")
public static List<File> getFilesFromTransferable(Transferable tr) throws IOException, UnsupportedFlavorException {
if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor) && !useGVFS()) {
// file list flavor
return (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor);
return sortByUniquePath((List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor)); // FORCE NATURAL FILE ORDER
}
if (tr.isDataFlavorSupported(FileTransferable.uriListFlavor)) {
@ -149,7 +137,7 @@ public class FileTransferable implements Transferable {
}
}
return files;
return sortByUniquePath(files); // FORCE NATURAL FILE ORDER
}
// cannot get files from transferable