1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-24 16:58:51 -05:00

Use human sort order for all paths loaded into the UI

This commit is contained in:
Reinhard Pointner 2016-09-28 20:25:11 +08:00
parent 99ad431994
commit aea553b154
11 changed files with 63 additions and 48 deletions

View File

@ -56,6 +56,7 @@ class AttributeTool extends Tool<TableModel> {
} }
List<File> files = filter(listFiles(root), VIDEO_FILES, SUBTITLE_FILES); List<File> files = filter(listFiles(root), VIDEO_FILES, SUBTITLE_FILES);
files.sort(HUMAN_ORDER);
for (File file : files) { for (File file : files) {
Object metaObject = xattr.getMetaInfo(file); Object metaObject = xattr.getMetaInfo(file);

View File

@ -1,6 +1,5 @@
package net.filebot.ui.filter; package net.filebot.ui.filter;
import static java.util.Collections.*;
import static net.filebot.Logging.*; import static net.filebot.Logging.*;
import static net.filebot.UserFiles.*; import static net.filebot.UserFiles.*;
import static net.filebot.util.ExceptionUtilities.*; import static net.filebot.util.ExceptionUtilities.*;
@ -78,21 +77,22 @@ class ExtractTool extends Tool<TableModel> {
@Override @Override
protected TableModel createModelInBackground(File root) throws InterruptedException { protected TableModel createModelInBackground(File root) throws InterruptedException {
List<File> files = root != null ? listFiles(root) : emptyList(); if (root == null) {
return new ArchiveEntryModel();
}
// ignore non-archives files and trailing multi-volume parts
List<File> files = filter(listFiles(root), Archive.VOLUME_ONE_FILTER);
files.sort(HUMAN_ORDER);
List<ArchiveEntry> entries = new ArrayList<ArchiveEntry>(); List<ArchiveEntry> entries = new ArrayList<ArchiveEntry>();
try { try {
for (File file : files) { for (File file : files) {
// ignore non-archives files and trailing multi-volume parts try (Archive archive = Archive.open(file)) {
if (Archive.VOLUME_ONE_FILTER.accept(file)) {
Archive archive = Archive.open(file);
try {
for (FileInfo it : archive.listFiles()) { for (FileInfo it : archive.listFiles()) {
entries.add(new ArchiveEntry(file, it)); entries.add(new ArchiveEntry(file, it));
} }
} finally {
archive.close();
}
} }
// unwind thread, if we have been cancelled // unwind thread, if we have been cancelled

View File

@ -86,10 +86,8 @@ class FileTreeTransferablePolicy extends BackgroundFileTransferablePolicy<TreeNo
if (file.isDirectory()) { if (file.isDirectory()) {
LinkedList<TreeNode> children = new LinkedList<TreeNode>(); LinkedList<TreeNode> children = new LinkedList<TreeNode>();
for (File f : getChildren(file)) {
if (f.isHidden())
continue;
for (File f : getChildren(file, NOT_HIDDEN, HUMAN_ORDER)) {
if (f.isDirectory()) { if (f.isDirectory()) {
children.addFirst(getTreeNode(f)); children.addFirst(getTreeNode(f));
} else { } else {

View File

@ -59,6 +59,8 @@ class MediaInfoTool extends Tool<TableModel> {
} }
List<File> files = filter(listFiles(root), VIDEO_FILES, AUDIO_FILES); List<File> files = filter(listFiles(root), VIDEO_FILES, AUDIO_FILES);
files.sort(HUMAN_ORDER);
Map<MediaInfoKey, String[]> data = new TreeMap<MediaInfoKey, String[]>(); Map<MediaInfoKey, String[]> data = new TreeMap<MediaInfoKey, String[]>();
try (MediaInfo mi = new MediaInfo()) { try (MediaInfo mi = new MediaInfo()) {

View File

@ -1,5 +1,6 @@
package net.filebot.ui.filter; package net.filebot.ui.filter;
import static java.util.Collections.*;
import static net.filebot.util.FileUtilities.*; import static net.filebot.util.FileUtilities.*;
import java.awt.Color; import java.awt.Color;
@ -68,10 +69,15 @@ class SplitTool extends Tool<TreeModel> {
@Override @Override
protected TreeModel createModelInBackground(File root) throws InterruptedException { protected TreeModel createModelInBackground(File root) throws InterruptedException {
if (root == null) {
return new DefaultTreeModel(new FolderNode("Volumes", emptyList()));
}
int nextPart = 1; int nextPart = 1;
long splitSize = getSplitSize(); long splitSize = getSplitSize();
List<File> files = (root != null) ? listFiles(root) : new ArrayList<File>(); List<File> files = listFiles(root);
files.sort(HUMAN_ORDER);
List<TreeNode> rootGroup = new ArrayList<TreeNode>(); List<TreeNode> rootGroup = new ArrayList<TreeNode>();
List<File> currentPart = new ArrayList<File>(); List<File> currentPart = new ArrayList<File>();

View File

@ -82,9 +82,12 @@ class FileListTransferablePolicy extends FileTransferablePolicy {
title.accept(getFolderName(files.get(0))); title.accept(getFolderName(files.get(0)));
} }
List<File> list = listFiles(files);
list.sort(HUMAN_ORDER);
// 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
format.accept(ListPanel.DEFAULT_FILE_FORMAT); format.accept(ListPanel.DEFAULT_FILE_FORMAT);
model.accept(listFiles(files)); model.accept(list);
} }
} }

View File

@ -1,6 +1,7 @@
package net.filebot.ui.rename; package net.filebot.ui.rename;
import static java.util.Collections.*; import static java.util.Collections.*;
import static net.filebot.util.FileUtilities.*;
import static net.filebot.util.ui.SwingUI.*; import static net.filebot.util.ui.SwingUI.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
@ -15,7 +16,6 @@ import net.filebot.format.ExpressionFileFilter;
import net.filebot.format.ExpressionFilter; import net.filebot.format.ExpressionFilter;
import net.filebot.format.ExpressionFormat; import net.filebot.format.ExpressionFormat;
import net.filebot.mac.MacAppUtilities; import net.filebot.mac.MacAppUtilities;
import net.filebot.util.FileUtilities;
import net.filebot.web.Datasource; import net.filebot.web.Datasource;
import net.filebot.web.EpisodeListProvider; import net.filebot.web.EpisodeListProvider;
import net.filebot.web.MovieIdentificationService; import net.filebot.web.MovieIdentificationService;
@ -84,10 +84,12 @@ public class Preset {
} }
} }
List<File> files = FileUtilities.listFiles(getInputFolder()); List<File> files = listFiles(getInputFolder());
if (filter != null) { if (filter != null) {
files = FileUtilities.filter(files, filter); files = filter(files, filter);
} }
files.sort(HUMAN_ORDER);
return files; return files;
} }

View File

@ -677,19 +677,20 @@ public class RenamePanel extends JComponent {
@Override @Override
public List<File> getFiles(ActionEvent evt) { public List<File> getFiles(ActionEvent evt) {
List<File> input = preset.selectInputFiles(evt); List<File> selection = preset.selectInputFiles(evt);
if (input != null) { if (selection != null) {
renameModel.clear(); renameModel.clear();
renameModel.files().addAll(input); renameModel.files().addAll(selection);
} else { } else {
input = new ArrayList<File>(super.getFiles(evt)); selection = new ArrayList<File>(super.getFiles(evt));
} }
if (input.isEmpty()) { if (selection.isEmpty()) {
throw new IllegalStateException("No files selected."); throw new IllegalStateException("No files selected.");
} }
return input;
return selection;
} }
@Override @Override

View File

@ -96,7 +96,7 @@ class ChecksumTableTransferablePolicy extends BackgroundFileTransferablePolicy<C
// handle single folder drop // handle single folder drop
if (files.size() == 1 && containsOnly(files, FOLDERS)) { if (files.size() == 1 && containsOnly(files, FOLDERS)) {
for (File folder : files) { for (File folder : files) {
for (File file : getChildren(folder, NOT_HIDDEN, CASE_INSENSITIVE_ORDER)) { for (File file : getChildren(folder, NOT_HIDDEN, HUMAN_ORDER)) {
load(file, null, folder); load(file, null, folder);
} }
} }
@ -179,7 +179,7 @@ class ChecksumTableTransferablePolicy extends BackgroundFileTransferablePolicy<C
if (absoluteFile.isDirectory()) { if (absoluteFile.isDirectory()) {
// load all files in the file tree // load all files in the file tree
for (File child : getChildren(absoluteFile, NOT_HIDDEN, CASE_INSENSITIVE_ORDER)) { for (File child : getChildren(absoluteFile, NOT_HIDDEN, HUMAN_ORDER)) {
load(child, relativeFile, root); load(child, relativeFile, root);
} }
} else { } else {

View File

@ -19,6 +19,7 @@ import java.awt.dnd.DropTargetEvent;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
@ -159,13 +160,13 @@ abstract class SubtitleDropTarget extends JButton {
public abstract String getQueryLanguage(); public abstract String getQueryLanguage();
@Override @Override
protected DropAction getDropAction(List<File> input) { protected DropAction getDropAction(List<File> selection) {
// accept video files and folders // accept video files and folders
return filter(input, VIDEO_FILES, FOLDERS).size() > 0 ? DropAction.Accept : DropAction.Cancel; return filter(input, VIDEO_FILES, FOLDERS).size() > 0 ? DropAction.Accept : DropAction.Cancel;
} }
@Override @Override
protected boolean handleDrop(List<File> input) { protected boolean handleDrop(List<File> selection) {
if (getQueryLanguage() == null) { if (getQueryLanguage() == null) {
log.info("Please select your preferred subtitle language."); log.info("Please select your preferred subtitle language.");
return false; return false;
@ -176,14 +177,11 @@ abstract class SubtitleDropTarget extends JButton {
return false; return false;
} }
// perform a drop action depending on the given files List<File> files = filter(listFiles(selection), VIDEO_FILES);
final Collection<File> videoFiles = new TreeSet<File>(); files.sort(HUMAN_ORDER);
// video files only if (files.size() > 0) {
videoFiles.addAll(filter(listFiles(input), VIDEO_FILES)); handleDownload(files);
if (videoFiles.size() > 0) {
handleDownload(videoFiles);
return true; return true;
} }
@ -234,13 +232,13 @@ abstract class SubtitleDropTarget extends JButton {
public static abstract class Upload extends SubtitleDropTarget { public static abstract class Upload extends SubtitleDropTarget {
@Override @Override
protected DropAction getDropAction(List<File> input) { protected DropAction getDropAction(List<File> selection) {
// accept video files and folders // accept video files and folders
return filter(input, SUBTITLE_FILES).size() > 0 || filter(input, FOLDERS).size() > 0 ? DropAction.Accept : DropAction.Cancel; return filter(selection, SUBTITLE_FILES).size() > 0 || filter(selection, FOLDERS).size() > 0 ? DropAction.Accept : DropAction.Cancel;
} }
@Override @Override
protected boolean handleDrop(List<File> input) { protected boolean handleDrop(List<File> selection) {
if (getSubtitleService().isAnonymous()) { if (getSubtitleService().isAnonymous()) {
log.info(String.format("%s: You must be logged in to upload subtitles.", getSubtitleService().getName())); log.info(String.format("%s: You must be logged in to upload subtitles.", getSubtitleService().getName()));
return false; return false;
@ -250,19 +248,20 @@ abstract class SubtitleDropTarget extends JButton {
// make sure we have access to the parent folder structure, not just the dropped file // make sure we have access to the parent folder structure, not just the dropped file
if (isMacSandbox()) { if (isMacSandbox()) {
MacAppUtilities.askUnlockFolders(getWindow(this), input); MacAppUtilities.askUnlockFolders(getWindow(this), selection);
} }
// perform a drop action depending on the given files // perform a drop action depending on the given files
final Collection<File> files = new TreeSet<File>(); List<File> files = listFiles(selection);
// video files only List<File> videos = filter(files, VIDEO_FILES);
files.addAll(listFiles(input)); videos.sort(HUMAN_ORDER);
final List<File> videos = filter(files, VIDEO_FILES); List<File> subtitles = filter(files, SUBTITLE_FILES);
final List<File> subtitles = filter(files, SUBTITLE_FILES); subtitles.sort(HUMAN_ORDER);
Map<File, File> uploadPlan = new LinkedHashMap<File, File>();
final Map<File, File> uploadPlan = new LinkedHashMap<File, File>();
for (File subtitle : subtitles) { for (File subtitle : subtitles) {
File video = getVideoForSubtitle(subtitle, filter(videos, new ParentFilter(subtitle.getParentFile()))); File video = getVideoForSubtitle(subtitle, filter(videos, new ParentFilter(subtitle.getParentFile())));
uploadPlan.put(subtitle, video); uploadPlan.put(subtitle, video);
@ -274,6 +273,7 @@ abstract class SubtitleDropTarget extends JButton {
handleUpload(uploadPlan); handleUpload(uploadPlan);
return true; return true;
} }
return false; return false;
} }

View File

@ -443,8 +443,10 @@ public final class FileUtilities {
// children array may be null if folder permissions do not allow listing of files // children array may be null if folder permissions do not allow listing of files
if (files == null) { if (files == null) {
files = new File[0]; return emptyList();
} else if (order != null) { }
if (order != null) {
sort(files, order); sort(files, order);
} }