Make sure that files can't be added twice with one single drop action (e.g. when parent folder and child file are part of the same file transferable)
This commit is contained in:
parent
6247dfdbef
commit
c41f564832
|
@ -69,7 +69,7 @@ class FileTreeTransferablePolicy extends BackgroundFileTransferablePolicy<TreeNo
|
||||||
}
|
}
|
||||||
|
|
||||||
// use fast file to minimize system calls like length(), isDirectory(), isFile(), ...
|
// use fast file to minimize system calls like length(), isDirectory(), isFile(), ...
|
||||||
FastFile root = FastFile.create(filter(files, FOLDERS)).get(0);
|
FastFile root = FastFile.create(filter(files, FOLDERS))[0];
|
||||||
|
|
||||||
// publish on EDT
|
// publish on EDT
|
||||||
publish(getTreeNode(root));
|
publish(getTreeNode(root));
|
||||||
|
|
|
@ -7,9 +7,11 @@ import static net.filebot.util.FileUtilities.*;
|
||||||
import java.awt.datatransfer.Transferable;
|
import java.awt.datatransfer.Transferable;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
@ -52,7 +54,7 @@ class FilesListTransferablePolicy extends BackgroundFileTransferablePolicy<File>
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void load(List<File> files, boolean recursive) {
|
protected void load(List<File> files, boolean recursive) {
|
||||||
List<File> entries = new ArrayList<File>();
|
Set<File> entries = new LinkedHashSet<File>();
|
||||||
LinkedList<File> queue = new LinkedList<File>(files);
|
LinkedList<File> queue = new LinkedList<File>(files);
|
||||||
|
|
||||||
while (queue.size() > 0) {
|
while (queue.size() > 0) {
|
||||||
|
@ -63,8 +65,7 @@ class FilesListTransferablePolicy extends BackgroundFileTransferablePolicy<File>
|
||||||
|
|
||||||
if (recursive && LIST_FILES.accept(f)) {
|
if (recursive && LIST_FILES.accept(f)) {
|
||||||
// don't use new Scanner(File) because of BUG 6368019 (http://bugs.sun.com/view_bug.do?bug_id=6368019)
|
// don't use new Scanner(File) because of BUG 6368019 (http://bugs.sun.com/view_bug.do?bug_id=6368019)
|
||||||
try {
|
try (Scanner scanner = new Scanner(createTextReader(f))) {
|
||||||
Scanner scanner = new Scanner(createTextReader(f));
|
|
||||||
List<File> paths = new ArrayList<File>();
|
List<File> paths = new ArrayList<File>();
|
||||||
while (scanner.hasNextLine()) {
|
while (scanner.hasNextLine()) {
|
||||||
String line = scanner.nextLine().trim();
|
String line = scanner.nextLine().trim();
|
||||||
|
@ -75,7 +76,6 @@ class FilesListTransferablePolicy extends BackgroundFileTransferablePolicy<File>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
scanner.close();
|
|
||||||
|
|
||||||
if (paths.isEmpty()) {
|
if (paths.isEmpty()) {
|
||||||
entries.add(f); // treat as simple text file
|
entries.add(f); // treat as simple text file
|
||||||
|
@ -92,7 +92,7 @@ class FilesListTransferablePolicy extends BackgroundFileTransferablePolicy<File>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
publish(FastFile.create(entries).toArray(new File[0]));
|
publish(FastFile.create(entries));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2,6 +2,7 @@ package net.filebot.ui.rename;
|
||||||
|
|
||||||
import static java.awt.datatransfer.DataFlavor.*;
|
import static java.awt.datatransfer.DataFlavor.*;
|
||||||
import static java.util.Arrays.*;
|
import static java.util.Arrays.*;
|
||||||
|
import static java.util.Collections.*;
|
||||||
import static net.filebot.MediaTypes.*;
|
import static net.filebot.MediaTypes.*;
|
||||||
import static net.filebot.hash.VerificationUtilities.*;
|
import static net.filebot.hash.VerificationUtilities.*;
|
||||||
import static net.filebot.ui.transfer.FileTransferable.*;
|
import static net.filebot.ui.transfer.FileTransferable.*;
|
||||||
|
@ -97,7 +98,7 @@ class NamesListTransferablePolicy extends FileTransferablePolicy {
|
||||||
loadTorrentFiles(files, values);
|
loadTorrentFiles(files, values);
|
||||||
} else {
|
} else {
|
||||||
// load all files from the given folders recursively up do a depth of 32
|
// load all files from the given folders recursively up do a depth of 32
|
||||||
values.addAll(FastFile.create(listFiles(files)));
|
addAll(values, FastFile.create(listFiles(files)));
|
||||||
}
|
}
|
||||||
|
|
||||||
model.addAll(values);
|
model.addAll(values);
|
||||||
|
|
|
@ -199,14 +199,8 @@ public class FastFile extends File {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<FastFile> create(Collection<File> files) {
|
public static FastFile[] create(Collection<File> files) {
|
||||||
List<FastFile> result = new ArrayList<FastFile>(files.size());
|
return files.stream().map(f -> new FastFile(f.getPath())).toArray(FastFile[]::new);
|
||||||
|
|
||||||
for (File file : files) {
|
|
||||||
result.add(new FastFile(file.getPath()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue