mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-22 07:48:52 -05:00
* apply "preserve extension" policy to filename formatter too
This commit is contained in:
parent
8729d227a1
commit
6d890b27d2
@ -178,9 +178,10 @@ public class Torrent {
|
||||
|
||||
public static class Entry {
|
||||
|
||||
private final String path;
|
||||
|
||||
private final String name;
|
||||
private final long length;
|
||||
private final String path;
|
||||
|
||||
|
||||
public Entry(String name, long length, String path) {
|
||||
@ -190,6 +191,11 @@ public class Torrent {
|
||||
}
|
||||
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@ -200,11 +206,6 @@ public class Torrent {
|
||||
}
|
||||
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getPath();
|
||||
|
@ -2,13 +2,13 @@
|
||||
package net.sourceforge.filebot.ui.panel.rename;
|
||||
|
||||
|
||||
class AbstractFileEntry {
|
||||
class AbstractFile {
|
||||
|
||||
private final String name;
|
||||
private final long length;
|
||||
|
||||
|
||||
public AbstractFileEntry(String name, long length) {
|
||||
public AbstractFile(String name, long length) {
|
||||
this.name = name;
|
||||
this.length = length;
|
||||
}
|
@ -13,7 +13,7 @@ import net.sourceforge.filebot.web.Episode;
|
||||
import net.sourceforge.filebot.web.EpisodeFormat;
|
||||
|
||||
|
||||
public class EpisodeExpressionFormatter extends ExpressionFormat implements MatchFormatter {
|
||||
class EpisodeExpressionFormatter extends ExpressionFormat implements MatchFormatter {
|
||||
|
||||
public EpisodeExpressionFormatter(String expression) throws ScriptException {
|
||||
super(expression);
|
||||
|
@ -8,11 +8,19 @@ import net.sourceforge.filebot.similarity.Match;
|
||||
import net.sourceforge.tuned.FileUtilities;
|
||||
|
||||
|
||||
public class FileNameFormatter implements MatchFormatter {
|
||||
class FileNameFormatter implements MatchFormatter {
|
||||
|
||||
private final boolean preserveExtension;
|
||||
|
||||
|
||||
public FileNameFormatter(boolean preserveExtension) {
|
||||
this.preserveExtension = preserveExtension;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canFormat(Match<?, ?> match) {
|
||||
return match.getValue() instanceof File;
|
||||
return match.getValue() instanceof File || match.getValue() instanceof AbstractFile;
|
||||
}
|
||||
|
||||
|
||||
@ -24,9 +32,20 @@ public class FileNameFormatter implements MatchFormatter {
|
||||
|
||||
@Override
|
||||
public String format(Match<?, ?> match) {
|
||||
File file = (File) match.getValue();
|
||||
if (match.getValue() instanceof File) {
|
||||
File file = (File) match.getValue();
|
||||
|
||||
return preserveExtension ? FileUtilities.getName(file) : file.getName();
|
||||
}
|
||||
|
||||
return FileUtilities.getName(file);
|
||||
if (match.getValue() instanceof AbstractFile) {
|
||||
AbstractFile file = (AbstractFile) match.getValue();
|
||||
|
||||
return preserveExtension ? FileUtilities.getNameWithoutExtension(file.getName()) : file.getName();
|
||||
}
|
||||
|
||||
// type not supported
|
||||
throw new IllegalArgumentException("Type not supported");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -63,8 +63,8 @@ class MatchAction extends AbstractAction {
|
||||
|
||||
@Override
|
||||
protected long getLength(Object object) {
|
||||
if (object instanceof AbstractFileEntry) {
|
||||
return ((AbstractFileEntry) object).getLength();
|
||||
if (object instanceof AbstractFile) {
|
||||
return ((AbstractFile) object).getLength();
|
||||
}
|
||||
|
||||
return super.getLength(object);
|
||||
|
@ -5,7 +5,7 @@ package net.sourceforge.filebot.ui.panel.rename;
|
||||
import net.sourceforge.filebot.similarity.Match;
|
||||
|
||||
|
||||
public interface MatchFormatter {
|
||||
interface MatchFormatter {
|
||||
|
||||
public boolean canFormat(Match<?, ?> match);
|
||||
|
||||
|
@ -7,7 +7,6 @@ import static net.sourceforge.filebot.FileBotUtilities.LIST_FILES;
|
||||
import static net.sourceforge.filebot.FileBotUtilities.TORRENT_FILES;
|
||||
import static net.sourceforge.tuned.FileUtilities.FOLDERS;
|
||||
import static net.sourceforge.tuned.FileUtilities.containsOnly;
|
||||
import static net.sourceforge.tuned.FileUtilities.getNameWithoutExtension;
|
||||
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
@ -140,7 +139,7 @@ class NamesListTransferablePolicy extends FileTransferablePolicy {
|
||||
Torrent torrent = new Torrent(file);
|
||||
|
||||
for (Torrent.Entry entry : torrent.getFiles()) {
|
||||
values.add(new AbstractFileEntry(getNameWithoutExtension(entry.getName()), entry.getLength()));
|
||||
values.add(new AbstractFile(entry.getName(), entry.getLength()));
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
@ -80,7 +80,7 @@ public class RenamePanel extends JComponent {
|
||||
renameModel.setPreserveExtension(Boolean.valueOf(Settings.userRoot().get("rename.preserveExtension", "true")));
|
||||
|
||||
// filename formatter
|
||||
renameModel.useFormatter(File.class, new FileNameFormatter());
|
||||
renameModel.useFormatter(File.class, new FileNameFormatter(renameModel.preserveExtension()));
|
||||
|
||||
// restore custom episode formatter
|
||||
renameModel.useFormatter(Episode.class, persistentFormatExpression.getValue());
|
||||
@ -220,6 +220,9 @@ public class RenamePanel extends JComponent {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
renameModel.setPreserveExtension(activate);
|
||||
|
||||
// use different file name formatter
|
||||
renameModel.useFormatter(File.class, new FileNameFormatter(renameModel.preserveExtension()));
|
||||
|
||||
// display changed state
|
||||
filesList.repaint();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user