mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-23 16:28:51 -05:00
// try to merge overlapping path sections
This commit is contained in:
parent
af3c60eeef
commit
69311852d1
@ -2,6 +2,7 @@ package net.filebot.ui.rename;
|
||||
|
||||
import static net.filebot.Logging.*;
|
||||
import static net.filebot.media.MediaDetection.*;
|
||||
import static net.filebot.util.FileUtilities.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.Format;
|
||||
@ -75,8 +76,13 @@ class ExpressionFormatter implements MatchFormatter {
|
||||
// try to resolve against structure root folder by default
|
||||
try {
|
||||
File structureRoot = getStructureRoot(source);
|
||||
if (structureRoot != null) {
|
||||
return new File(structureRoot, destination).getPath();
|
||||
File destinationRoot = listPath(parent).get(0);
|
||||
while (structureRoot != null) {
|
||||
// try to merge overlapping path sections
|
||||
if (!structureRoot.getName().equals(destinationRoot.getName())) {
|
||||
return new File(structureRoot, destination).getPath();
|
||||
}
|
||||
structureRoot = structureRoot.getParentFile();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
debug.log(Level.SEVERE, "Failed to resolve structure root: " + source, e);
|
||||
|
@ -35,6 +35,7 @@ import net.miginfocom.swing.MigLayout;
|
||||
class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
||||
|
||||
private RenameModel renameModel;
|
||||
private String home;
|
||||
|
||||
private TypeRenderer typeRenderer = new TypeRenderer();
|
||||
|
||||
@ -46,12 +47,13 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
||||
|
||||
private TextColorizer textColorizer = new TextColorizer();
|
||||
|
||||
public RenameListCellRenderer(RenameModel renameModel) {
|
||||
public RenameListCellRenderer(RenameModel renameModel, File home) {
|
||||
super(new Insets(4, 7, 4, 7));
|
||||
|
||||
this.renameModel = renameModel;
|
||||
setHighlightingEnabled(false);
|
||||
this.home = home.getPath();
|
||||
|
||||
setHighlightingEnabled(false);
|
||||
setLayout(new MigLayout("insets 0, fill", "align left", "align center"));
|
||||
this.add(typeRenderer, "gap rel:push, hidemode 3");
|
||||
}
|
||||
@ -169,14 +171,15 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
||||
}
|
||||
|
||||
protected String formatPath(File file) {
|
||||
if (file.getPath().startsWith(home)) {
|
||||
return "~" + normalizePathSeparators(file.getPath().substring(home.length()));
|
||||
}
|
||||
return normalizePathSeparators(file.getPath());
|
||||
}
|
||||
|
||||
protected String colorizePath(File file, boolean hasExtension) {
|
||||
StringBuilder html = new StringBuilder(512);
|
||||
html.append("<html><nobr>");
|
||||
textColorizer.colorizePath(html, file, hasExtension);
|
||||
html.append("</nobr></html>");
|
||||
StringBuilder html = new StringBuilder(256);
|
||||
textColorizer.colorizePath(html, new File(formatPath(file)), hasExtension);
|
||||
return html.toString();
|
||||
}
|
||||
|
||||
@ -185,7 +188,6 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
||||
if (!f.isAbsolute()) {
|
||||
f = new File(targetDir, f.getPath()); // resolve path against target folder
|
||||
}
|
||||
|
||||
return f.getAbsoluteFile();
|
||||
}
|
||||
|
||||
|
@ -152,7 +152,7 @@ public class RenamePanel extends JComponent {
|
||||
renameModel.useFormatter(FileInfo.class, new FileNameFormatter(renameModel.preserveExtension()));
|
||||
}
|
||||
|
||||
RenameListCellRenderer cellrenderer = new RenameListCellRenderer(renameModel);
|
||||
RenameListCellRenderer cellrenderer = new RenameListCellRenderer(renameModel, ApplicationFolder.UserHome.getCanonicalFile());
|
||||
|
||||
namesList.getListComponent().setCellRenderer(cellrenderer);
|
||||
filesList.getListComponent().setCellRenderer(cellrenderer);
|
||||
|
Loading…
Reference in New Issue
Block a user