// 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.Logging.*;
|
||||||
import static net.filebot.media.MediaDetection.*;
|
import static net.filebot.media.MediaDetection.*;
|
||||||
|
import static net.filebot.util.FileUtilities.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.Format;
|
import java.text.Format;
|
||||||
|
@ -75,8 +76,13 @@ class ExpressionFormatter implements MatchFormatter {
|
||||||
// try to resolve against structure root folder by default
|
// try to resolve against structure root folder by default
|
||||||
try {
|
try {
|
||||||
File structureRoot = getStructureRoot(source);
|
File structureRoot = getStructureRoot(source);
|
||||||
if (structureRoot != null) {
|
File destinationRoot = listPath(parent).get(0);
|
||||||
return new File(structureRoot, destination).getPath();
|
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) {
|
} catch (Exception e) {
|
||||||
debug.log(Level.SEVERE, "Failed to resolve structure root: " + source, 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 {
|
class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
||||||
|
|
||||||
private RenameModel renameModel;
|
private RenameModel renameModel;
|
||||||
|
private String home;
|
||||||
|
|
||||||
private TypeRenderer typeRenderer = new TypeRenderer();
|
private TypeRenderer typeRenderer = new TypeRenderer();
|
||||||
|
|
||||||
|
@ -46,12 +47,13 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
||||||
|
|
||||||
private TextColorizer textColorizer = new TextColorizer();
|
private TextColorizer textColorizer = new TextColorizer();
|
||||||
|
|
||||||
public RenameListCellRenderer(RenameModel renameModel) {
|
public RenameListCellRenderer(RenameModel renameModel, File home) {
|
||||||
super(new Insets(4, 7, 4, 7));
|
super(new Insets(4, 7, 4, 7));
|
||||||
|
|
||||||
this.renameModel = renameModel;
|
this.renameModel = renameModel;
|
||||||
setHighlightingEnabled(false);
|
this.home = home.getPath();
|
||||||
|
|
||||||
|
setHighlightingEnabled(false);
|
||||||
setLayout(new MigLayout("insets 0, fill", "align left", "align center"));
|
setLayout(new MigLayout("insets 0, fill", "align left", "align center"));
|
||||||
this.add(typeRenderer, "gap rel:push, hidemode 3");
|
this.add(typeRenderer, "gap rel:push, hidemode 3");
|
||||||
}
|
}
|
||||||
|
@ -169,14 +171,15 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String formatPath(File file) {
|
protected String formatPath(File file) {
|
||||||
|
if (file.getPath().startsWith(home)) {
|
||||||
|
return "~" + normalizePathSeparators(file.getPath().substring(home.length()));
|
||||||
|
}
|
||||||
return normalizePathSeparators(file.getPath());
|
return normalizePathSeparators(file.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String colorizePath(File file, boolean hasExtension) {
|
protected String colorizePath(File file, boolean hasExtension) {
|
||||||
StringBuilder html = new StringBuilder(512);
|
StringBuilder html = new StringBuilder(256);
|
||||||
html.append("<html><nobr>");
|
textColorizer.colorizePath(html, new File(formatPath(file)), hasExtension);
|
||||||
textColorizer.colorizePath(html, file, hasExtension);
|
|
||||||
html.append("</nobr></html>");
|
|
||||||
return html.toString();
|
return html.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,7 +188,6 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
||||||
if (!f.isAbsolute()) {
|
if (!f.isAbsolute()) {
|
||||||
f = new File(targetDir, f.getPath()); // resolve path against target folder
|
f = new File(targetDir, f.getPath()); // resolve path against target folder
|
||||||
}
|
}
|
||||||
|
|
||||||
return f.getAbsoluteFile();
|
return f.getAbsoluteFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -152,7 +152,7 @@ public class RenamePanel extends JComponent {
|
||||||
renameModel.useFormatter(FileInfo.class, new FileNameFormatter(renameModel.preserveExtension()));
|
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);
|
namesList.getListComponent().setCellRenderer(cellrenderer);
|
||||||
filesList.getListComponent().setCellRenderer(cellrenderer);
|
filesList.getListComponent().setCellRenderer(cellrenderer);
|
||||||
|
|
Loading…
Reference in New Issue