diff --git a/source/net/filebot/ui/rename/ExpressionFormatter.java b/source/net/filebot/ui/rename/ExpressionFormatter.java index edc7a2a4..6535f5d9 100644 --- a/source/net/filebot/ui/rename/ExpressionFormatter.java +++ b/source/net/filebot/ui/rename/ExpressionFormatter.java @@ -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); diff --git a/source/net/filebot/ui/rename/RenameListCellRenderer.java b/source/net/filebot/ui/rename/RenameListCellRenderer.java index 5e9af6f1..d0068f25 100644 --- a/source/net/filebot/ui/rename/RenameListCellRenderer.java +++ b/source/net/filebot/ui/rename/RenameListCellRenderer.java @@ -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(""); - textColorizer.colorizePath(html, file, hasExtension); - html.append(""); + 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(); } diff --git a/source/net/filebot/ui/rename/RenamePanel.java b/source/net/filebot/ui/rename/RenamePanel.java index 0096428c..307177d5 100644 --- a/source/net/filebot/ui/rename/RenamePanel.java +++ b/source/net/filebot/ui/rename/RenamePanel.java @@ -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);