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