* automatically cancel drops of internally-generated files

This commit is contained in:
Reinhard Pointner 2011-11-22 15:21:19 +00:00
parent b08ec77642
commit e7d697df0a
3 changed files with 23 additions and 5 deletions

View File

@ -3,6 +3,7 @@ package net.sourceforge.filebot.ui.transfer;
import static net.sourceforge.filebot.ui.transfer.FileTransferable.*;
import static net.sourceforge.tuned.FileUtilities.*;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
@ -16,11 +17,16 @@ public abstract class FileTransferablePolicy extends TransferablePolicy {
@Override
public boolean accept(Transferable tr) throws Exception {
try {
return accept(getFilesFromTransferable(tr));
List<File> files = getFilesFromTransferable(tr);
if (!containsOnly(files, TEMPORARY)) {
return accept(getFilesFromTransferable(tr));
}
} catch (UnsupportedFlavorException e) {
// no file list flavor
return false;
}
return false;
}

View File

@ -428,6 +428,17 @@ public final class FileUtilities {
}
};
public static final FileFilter TEMPORARY = new FileFilter() {
private final File TEMP_DIR = new File(System.getProperty("java.io.tmpdir"));
@Override
public boolean accept(File file) {
return file.getAbsolutePath().startsWith(TEMP_DIR.getAbsolutePath());
}
};
public static class ExtensionFileFilter implements FileFilter {

View File

@ -13,8 +13,6 @@ import java.util.UUID;
public final class TemporaryFolder {
private static final File tmpdir = new File(System.getProperty("java.io.tmpdir"));
private static final Map<String, TemporaryFolder> folders = new HashMap<String, TemporaryFolder>();
@ -35,7 +33,10 @@ public final class TemporaryFolder {
TemporaryFolder folder = folders.get(name);
if (folder == null) {
folder = new TemporaryFolder(new File(tmpdir, String.format("%s [%s]", name, UUID.randomUUID())));
File tmpdir = new File(System.getProperty("java.io.tmpdir"));
String subdir = String.format("%s [%s]", name, UUID.randomUUID());
folder = new TemporaryFolder(new File(tmpdir, subdir));
folders.put(name, folder);
}