* unfold/flatten folders when dropped in Rename panel and List panel
This commit is contained in:
parent
d3bdcf597e
commit
8364015504
|
@ -7,7 +7,6 @@ import static net.sourceforge.tuned.FileUtilities.*;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.filebot.MediaTypes;
|
||||
|
@ -47,24 +46,18 @@ class FileListTransferablePolicy extends FileTransferablePolicy {
|
|||
// clear selection
|
||||
list.getListComponent().clearSelection();
|
||||
|
||||
if (containsOnly(files, FOLDERS)) {
|
||||
loadFolders(files);
|
||||
} else if (containsOnly(files, MediaTypes.getDefaultFilter("application/torrent"))) {
|
||||
if (containsOnly(files, MediaTypes.getDefaultFilter("application/torrent"))) {
|
||||
loadTorrents(files);
|
||||
} else {
|
||||
loadFiles(files);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void loadFolders(List<File> folders) {
|
||||
if (folders.size() == 1) {
|
||||
// if only one folder was dropped, use its name as title
|
||||
list.setTitle(FileUtilities.getFolderName(folders.get(0)));
|
||||
}
|
||||
|
||||
for (File folder : folders) {
|
||||
loadFiles(Arrays.asList(folder.listFiles()));
|
||||
if (files.size() == 1 && files.get(0).isDirectory()) {
|
||||
list.setTitle(FileUtilities.getFolderName(files.get(0)));
|
||||
}
|
||||
|
||||
// load all files from the given folders recursively up do a depth of 5
|
||||
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
|
||||
public String getFileFilterDescription() {
|
||||
return "files, folders and torrents";
|
||||
|
|
|
@ -15,7 +15,7 @@ class FilesListTransferablePolicy extends FileTransferablePolicy {
|
|||
|
||||
private final List<File> model;
|
||||
|
||||
|
||||
|
||||
public FilesListTransferablePolicy(List<File> model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
@ -35,13 +35,7 @@ class FilesListTransferablePolicy extends FileTransferablePolicy {
|
|||
|
||||
@Override
|
||||
protected void load(List<File> files) {
|
||||
if (containsOnly(files, FOLDERS)) {
|
||||
for (File folder : files) {
|
||||
model.addAll(FastFile.foreach(folder.listFiles()));
|
||||
}
|
||||
} else {
|
||||
model.addAll(FastFile.foreach(files));
|
||||
}
|
||||
model.addAll(FastFile.foreach(flatten(files, 5)));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -107,14 +107,9 @@ class NamesListTransferablePolicy extends FileTransferablePolicy {
|
|||
} else if (containsOnly(files, MediaTypes.getDefaultFilter("application/torrent"))) {
|
||||
// torrent files
|
||||
loadTorrentFiles(files, values);
|
||||
} else if (containsOnly(files, FOLDERS)) {
|
||||
// load files from each folder
|
||||
for (File folder : files) {
|
||||
values.addAll(FastFile.foreach(folder.listFiles()));
|
||||
}
|
||||
} else {
|
||||
// just add all given files
|
||||
values.addAll(FastFile.foreach(files));
|
||||
// load all files from the given folders recursively up do a depth of 5
|
||||
values.addAll(FastFile.foreach(flatten(files, 5)));
|
||||
}
|
||||
|
||||
model.addAll(values);
|
||||
|
|
|
@ -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) {
|
||||
LinkedList<File> nodes = new LinkedList<File>();
|
||||
|
||||
|
|
Loading…
Reference in New Issue