* [Windows] allow renaming of files where just the upper/lower case is different
This commit is contained in:
parent
c75b376140
commit
3ed58bda08
|
@ -303,7 +303,7 @@ class RenameAction extends AbstractAction {
|
||||||
// rename file, throw exception on failure
|
// rename file, throw exception on failure
|
||||||
File source = mapping.getKey();
|
File source = mapping.getKey();
|
||||||
File destination = resolveDestination(mapping.getKey(), mapping.getValue(), false);
|
File destination = resolveDestination(mapping.getKey(), mapping.getValue(), false);
|
||||||
if (!source.equals(destination)) {
|
if (!source.getAbsolutePath().equals(destination.getAbsolutePath())) {
|
||||||
action.rename(source, destination);
|
action.rename(source, destination);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
|
|
||||||
package net.sourceforge.filebot.ui.rename;
|
package net.sourceforge.filebot.ui.rename;
|
||||||
|
|
||||||
|
|
||||||
import static net.sourceforge.filebot.similarity.EpisodeMetrics.*;
|
import static net.sourceforge.filebot.similarity.EpisodeMetrics.*;
|
||||||
import static net.sourceforge.tuned.FileUtilities.*;
|
import static net.sourceforge.tuned.FileUtilities.*;
|
||||||
import static net.sourceforge.tuned.ui.TunedUtilities.*;
|
import static net.sourceforge.tuned.ui.TunedUtilities.*;
|
||||||
|
@ -34,7 +32,6 @@ import net.sourceforge.tuned.FileUtilities;
|
||||||
import net.sourceforge.tuned.ui.DefaultFancyListCellRenderer;
|
import net.sourceforge.tuned.ui.DefaultFancyListCellRenderer;
|
||||||
import net.sourceforge.tuned.ui.GradientStyle;
|
import net.sourceforge.tuned.ui.GradientStyle;
|
||||||
|
|
||||||
|
|
||||||
class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
||||||
|
|
||||||
private RenameModel renameModel;
|
private RenameModel renameModel;
|
||||||
|
@ -50,7 +47,6 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
||||||
private Color pathRainbowBeginColor = new Color(0xCC3300);
|
private Color pathRainbowBeginColor = new Color(0xCC3300);
|
||||||
private Color pathRainbowEndColor = new Color(0x008080);
|
private Color pathRainbowEndColor = new Color(0x008080);
|
||||||
|
|
||||||
|
|
||||||
public RenameListCellRenderer(RenameModel renameModel) {
|
public RenameListCellRenderer(RenameModel renameModel) {
|
||||||
super(new Insets(4, 7, 4, 7));
|
super(new Insets(4, 7, 4, 7));
|
||||||
|
|
||||||
|
@ -61,7 +57,6 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
||||||
this.add(typeRenderer, "gap rel:push, hidemode 3");
|
this.add(typeRenderer, "gap rel:push, hidemode 3");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configureListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
public void configureListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||||
super.configureListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
super.configureListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||||
|
@ -154,22 +149,20 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
||||||
if (pathFuture.isDone() && !pathFuture.isCancelled()) {
|
if (pathFuture.isDone() && !pathFuture.isCancelled()) {
|
||||||
File from = renameModel.getMatch(index).getCandidate();
|
File from = renameModel.getMatch(index).getCandidate();
|
||||||
File to = resolveAbsolutePath(from.getParentFile(), pathFuture.toString(), renameModel.preserveExtension() ? getExtension(from) : null);
|
File to = resolveAbsolutePath(from.getParentFile(), pathFuture.toString(), renameModel.preserveExtension() ? getExtension(from) : null);
|
||||||
if (from.equals(to)) {
|
if (from.getAbsolutePath().equals(to.getAbsolutePath())) {
|
||||||
setIcon(ResourceManager.getIcon("dialog.continue"));
|
setIcon(ResourceManager.getIcon("dialog.continue"));
|
||||||
} else if (to.exists()) {
|
} else if (to.exists() && !to.equals(from)) {
|
||||||
setIcon(ResourceManager.getIcon("dialog.cancel"));
|
setIcon(ResourceManager.getIcon("dialog.cancel")); // take into account that on Windows equals/exists is case-insensitive which we have to work around
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected String formatPath(File file) {
|
protected String formatPath(File file) {
|
||||||
return normalizePathSeparators(file.getPath());
|
return normalizePathSeparators(file.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected String colorizePath(File file, boolean hasExtension) {
|
protected String colorizePath(File file, boolean hasExtension) {
|
||||||
List<File> path = listPath(file);
|
List<File> path = listPath(file);
|
||||||
StringBuilder html = new StringBuilder(512);
|
StringBuilder html = new StringBuilder(512);
|
||||||
|
@ -196,20 +189,14 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
||||||
return html.append("</nobr></html>").toString();
|
return html.append("</nobr></html>").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected File resolveAbsolutePath(File targetDir, String path, String extension) {
|
protected File resolveAbsolutePath(File targetDir, String path, String extension) {
|
||||||
File f = new File(extension == null || extension.isEmpty() ? path : String.format("%s.%s", path, extension));
|
File f = new File(extension == null || extension.isEmpty() ? path : String.format("%s.%s", path, extension));
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
return f.getCanonicalFile();
|
|
||||||
} catch (Exception e) {
|
|
||||||
return f.getAbsoluteFile();
|
return f.getAbsoluteFile();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected float getMatchProbablity(Match<Object, File> match) {
|
protected float getMatchProbablity(Match<Object, File> match) {
|
||||||
if (match.getValue() instanceof Episode) {
|
if (match.getValue() instanceof Episode) {
|
||||||
|
@ -226,7 +213,6 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
||||||
return 1; // assume match is OK
|
return 1; // assume match is OK
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected String getType(File file) {
|
protected String getType(File file) {
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
return "Folder";
|
return "Folder";
|
||||||
|
@ -241,7 +227,6 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
||||||
return "File";
|
return "File";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class TypeRenderer extends DefaultListCellRenderer {
|
private static class TypeRenderer extends DefaultListCellRenderer {
|
||||||
|
|
||||||
private final Insets margin = new Insets(0, 10, 0, 0);
|
private final Insets margin = new Insets(0, 10, 0, 0);
|
||||||
|
@ -253,7 +238,6 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
||||||
|
|
||||||
private float alpha = 1.0f;
|
private float alpha = 1.0f;
|
||||||
|
|
||||||
|
|
||||||
public TypeRenderer() {
|
public TypeRenderer() {
|
||||||
setOpaque(false);
|
setOpaque(false);
|
||||||
setForeground(new Color(0x141414));
|
setForeground(new Color(0x141414));
|
||||||
|
@ -261,7 +245,6 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
||||||
setBorder(new CompoundBorder(new EmptyBorder(margin), new EmptyBorder(padding)));
|
setBorder(new CompoundBorder(new EmptyBorder(margin), new EmptyBorder(padding)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintComponent(Graphics g) {
|
protected void paintComponent(Graphics g) {
|
||||||
Graphics2D g2d = (Graphics2D) g;
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
@ -282,7 +265,6 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
||||||
g2d.drawString(getText(), (float) (shape.getCenterX() - textBounds.getX() - (textBounds.getWidth() / 2f)), (float) (shape.getCenterY() - textBounds.getY() - (textBounds.getHeight() / 2)));
|
g2d.drawString(getText(), (float) (shape.getCenterX() - textBounds.getX() - (textBounds.getWidth() / 2f)), (float) (shape.getCenterY() - textBounds.getY() - (textBounds.getHeight() / 2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setAlpha(float alpha) {
|
public void setAlpha(float alpha) {
|
||||||
this.alpha = alpha;
|
this.alpha = alpha;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,8 @@ public final class FileUtilities {
|
||||||
} else {
|
} else {
|
||||||
// move file
|
// move file
|
||||||
try {
|
try {
|
||||||
java.nio.file.Files.move(source.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
// * On Windows ATOMIC_MOVE allows us to rename files even if only lower/upper-case changes (without ATOMIC_MOVE the operation would be ignored)
|
||||||
|
java.nio.file.Files.move(source.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);
|
||||||
} catch (LinkageError e) {
|
} catch (LinkageError e) {
|
||||||
org.apache.commons.io.FileUtils.moveFile(source, destination); // use "copy and delete" as fallback if standard rename fails
|
org.apache.commons.io.FileUtils.moveFile(source, destination); // use "copy and delete" as fallback if standard rename fails
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue