* unfold/flatten folders when dropped in Rename panel and List panel

This commit is contained in:
Reinhard Pointner 2010-10-23 03:51:19 +00:00
parent d3bdcf597e
commit 8364015504
4 changed files with 29 additions and 38 deletions

View File

@ -7,7 +7,6 @@ import static net.sourceforge.tuned.FileUtilities.*;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import net.sourceforge.filebot.MediaTypes; import net.sourceforge.filebot.MediaTypes;
@ -47,24 +46,18 @@ class FileListTransferablePolicy extends FileTransferablePolicy {
// clear selection // clear selection
list.getListComponent().clearSelection(); list.getListComponent().clearSelection();
if (containsOnly(files, FOLDERS)) { if (containsOnly(files, MediaTypes.getDefaultFilter("application/torrent"))) {
loadFolders(files);
} else if (containsOnly(files, MediaTypes.getDefaultFilter("application/torrent"))) {
loadTorrents(files); loadTorrents(files);
} else { } else {
loadFiles(files);
}
}
private void loadFolders(List<File> folders) {
if (folders.size() == 1) {
// if only one folder was dropped, use its name as title // if only one folder was dropped, use its name as title
list.setTitle(FileUtilities.getFolderName(folders.get(0))); if (files.size() == 1 && files.get(0).isDirectory()) {
} list.setTitle(FileUtilities.getFolderName(files.get(0)));
}
for (File folder : folders) { // load all files from the given folders recursively up do a depth of 5
loadFiles(Arrays.asList(folder.listFiles())); for (File file : flatten(files, 5)) {
list.getModel().add(FileUtilities.getName(file));
}
} }
} }
@ -88,13 +81,6 @@ class FileListTransferablePolicy extends FileTransferablePolicy {
} }
private void loadFiles(List<File> files) {
for (File file : files) {
list.getModel().add(FileUtilities.getName(file));
}
}
@Override @Override
public String getFileFilterDescription() { public String getFileFilterDescription() {
return "files, folders and torrents"; return "files, folders and torrents";

View File

@ -35,13 +35,7 @@ class FilesListTransferablePolicy extends FileTransferablePolicy {
@Override @Override
protected void load(List<File> files) { protected void load(List<File> files) {
if (containsOnly(files, FOLDERS)) { model.addAll(FastFile.foreach(flatten(files, 5)));
for (File folder : files) {
model.addAll(FastFile.foreach(folder.listFiles()));
}
} else {
model.addAll(FastFile.foreach(files));
}
} }

View File

@ -107,14 +107,9 @@ class NamesListTransferablePolicy extends FileTransferablePolicy {
} else if (containsOnly(files, MediaTypes.getDefaultFilter("application/torrent"))) { } else if (containsOnly(files, MediaTypes.getDefaultFilter("application/torrent"))) {
// torrent files // torrent files
loadTorrentFiles(files, values); loadTorrentFiles(files, values);
} else if (containsOnly(files, FOLDERS)) {
// load files from each folder
for (File folder : files) {
values.addAll(FastFile.foreach(folder.listFiles()));
}
} else { } else {
// just add all given files // load all files from the given folders recursively up do a depth of 5
values.addAll(FastFile.foreach(files)); values.addAll(FastFile.foreach(flatten(files, 5)));
} }
model.addAll(values); model.addAll(values);

View File

@ -142,6 +142,22 @@ public final class FileUtilities {
} }
public static List<File> flatten(Iterable<File> roots, int maxDepth) {
List<File> files = new ArrayList<File>();
// unfold/flatten file tree
for (File root : roots) {
if (root.isDirectory()) {
listFiles(root, 0, files, maxDepth);
} else {
files.add(root);
}
}
return files;
}
public static List<File> listPath(File file) { public static List<File> listPath(File file) {
LinkedList<File> nodes = new LinkedList<File>(); LinkedList<File> nodes = new LinkedList<File>();