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

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:
Reinhard Pointner 2016-02-11 20:15:40 +00:00
parent 6247dfdbef
commit c41f564832
4 changed files with 10 additions and 15 deletions

View File

@ -69,7 +69,7 @@ class FileTreeTransferablePolicy extends BackgroundFileTransferablePolicy<TreeNo
}
// 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(getTreeNode(root));

View File

@ -7,9 +7,11 @@ import static net.filebot.util.FileUtilities.*;
import java.awt.datatransfer.Transferable;
import java.io.File;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -52,7 +54,7 @@ class FilesListTransferablePolicy extends BackgroundFileTransferablePolicy<File>
}
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);
while (queue.size() > 0) {
@ -63,8 +65,7 @@ class FilesListTransferablePolicy extends BackgroundFileTransferablePolicy<File>
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)
try {
Scanner scanner = new Scanner(createTextReader(f));
try (Scanner scanner = new Scanner(createTextReader(f))) {
List<File> paths = new ArrayList<File>();
while (scanner.hasNextLine()) {
String line = scanner.nextLine().trim();
@ -75,7 +76,6 @@ class FilesListTransferablePolicy extends BackgroundFileTransferablePolicy<File>
}
}
}
scanner.close();
if (paths.isEmpty()) {
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

View File

@ -2,6 +2,7 @@ package net.filebot.ui.rename;
import static java.awt.datatransfer.DataFlavor.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static net.filebot.MediaTypes.*;
import static net.filebot.hash.VerificationUtilities.*;
import static net.filebot.ui.transfer.FileTransferable.*;
@ -97,7 +98,7 @@ class NamesListTransferablePolicy extends FileTransferablePolicy {
loadTorrentFiles(files, values);
} else {
// 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);

View File

@ -199,14 +199,8 @@ public class FastFile extends File {
throw new UnsupportedOperationException();
}
public static List<FastFile> create(Collection<File> files) {
List<FastFile> result = new ArrayList<FastFile>(files.size());
for (File file : files) {
result.add(new FastFile(file.getPath()));
}
return result;
public static FastFile[] create(Collection<File> files) {
return files.stream().map(f -> new FastFile(f.getPath())).toArray(FastFile[]::new);
}
}