Refactor
This commit is contained in:
parent
5244a33fac
commit
f28800a3a9
|
@ -4,6 +4,7 @@ import static java.awt.Font.*;
|
|||
import static java.util.Arrays.*;
|
||||
import static java.util.Collections.*;
|
||||
import static java.util.regex.Pattern.*;
|
||||
import static java.util.stream.Collectors.*;
|
||||
import static javax.swing.JOptionPane.*;
|
||||
import static net.filebot.Logging.*;
|
||||
import static net.filebot.Settings.*;
|
||||
|
@ -37,7 +38,6 @@ import java.util.Map.Entry;
|
|||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
|
@ -446,15 +446,18 @@ class HistoryDialog extends JDialog {
|
|||
}
|
||||
|
||||
private enum Option {
|
||||
|
||||
Revert, ChangeDirectory, Cancel;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
switch (this) {
|
||||
case Revert:
|
||||
return "Revert";
|
||||
case ChangeDirectory:
|
||||
return "Change Directory";
|
||||
default:
|
||||
return name();
|
||||
return "Cancel";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -529,7 +532,7 @@ class HistoryDialog extends JDialog {
|
|||
private void revert(File directory, List<Element> elements) {
|
||||
Map<File, File> renamePlan = getRenameMap(directory);
|
||||
if (isMacSandbox()) {
|
||||
if (!MacAppUtilities.askUnlockFolders(parent(), Stream.of(renamePlan.keySet(), renamePlan.values()).flatMap(c -> c.stream()).collect(Collectors.toList()))) {
|
||||
if (!MacAppUtilities.askUnlockFolders(parent(), Stream.of(renamePlan.keySet(), renamePlan.values()).flatMap(c -> c.stream()).collect(toList()))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package net.filebot.ui.rename;
|
|||
|
||||
import static java.util.Arrays.*;
|
||||
import static java.util.Collections.*;
|
||||
import static java.util.stream.Collectors.*;
|
||||
import static javax.swing.JOptionPane.*;
|
||||
import static net.filebot.Logging.*;
|
||||
import static net.filebot.Settings.*;
|
||||
|
@ -32,7 +33,6 @@ import java.util.function.BiConsumer;
|
|||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
|
@ -202,14 +202,14 @@ class RenameAction extends AbstractAction {
|
|||
private Map<File, File> checkRenamePlan(List<Entry<File, File>> renamePlan, Window parent) throws IOException {
|
||||
// ask for user permissions to output paths
|
||||
if (isMacSandbox()) {
|
||||
if (!MacAppUtilities.askUnlockFolders(parent, renamePlan.stream().flatMap(e -> Stream.of(e.getKey(), resolve(e.getKey(), e.getValue()))).map(f -> new File(f.getAbsolutePath())).collect(Collectors.toList()))) {
|
||||
if (!MacAppUtilities.askUnlockFolders(parent, renamePlan.stream().flatMap(e -> Stream.of(e.getKey(), resolve(e.getKey(), e.getValue()))).map(f -> new File(f.getAbsolutePath())).collect(toList()))) {
|
||||
return emptyMap();
|
||||
}
|
||||
}
|
||||
|
||||
// build rename map and perform some sanity checks
|
||||
Map<File, File> renameMap = new HashMap<File, File>();
|
||||
Set<File> destinationSet = new HashSet<File>();
|
||||
Set<File> destinationFiles = new HashSet<File>();
|
||||
List<String> issues = new ArrayList<String>();
|
||||
|
||||
for (Entry<File, File> mapping : renamePlan) {
|
||||
|
@ -220,7 +220,7 @@ class RenameAction extends AbstractAction {
|
|||
if (renameMap.containsKey(source))
|
||||
throw new IllegalArgumentException("Duplicate source file: " + source.getPath());
|
||||
|
||||
if (destinationSet.contains(destination))
|
||||
if (destinationFiles.contains(destination))
|
||||
throw new IllegalArgumentException("Conflict detected: " + mapping.getValue().getPath());
|
||||
|
||||
if (destination.exists() && !resolve(mapping.getKey(), mapping.getValue()).equals(mapping.getKey()))
|
||||
|
@ -231,7 +231,7 @@ class RenameAction extends AbstractAction {
|
|||
|
||||
// use original mapping values
|
||||
renameMap.put(mapping.getKey(), mapping.getValue());
|
||||
destinationSet.add(destination);
|
||||
destinationFiles.add(destination);
|
||||
} catch (Exception e) {
|
||||
issues.add(e.getMessage());
|
||||
}
|
||||
|
|
|
@ -160,7 +160,7 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
|||
if (pathFuture.isDone() && !pathFuture.isCancelled()) {
|
||||
File from = renameModel.getMatch(index).getCandidate();
|
||||
File to = resolveAbsolutePath(from.getParentFile(), pathFuture.toString(), renameModel.preserveExtension() ? getExtension(from) : null);
|
||||
if (from.getAbsolutePath().equals(to.getAbsolutePath())) {
|
||||
if (equalsCaseSensitive(from, to)) {
|
||||
setIcon(ResourceManager.getIcon("dialog.continue"));
|
||||
} else if (to.exists() && !to.equals(from)) {
|
||||
setIcon(ResourceManager.getIcon("dialog.cancel")); // take into account that on Windows equals/exists is case-insensitive which we have to work around
|
||||
|
|
|
@ -59,6 +59,11 @@ public final class FileUtilities {
|
|||
// resolve destination
|
||||
destination = resolveDestination(source, destination);
|
||||
|
||||
// do nothing if source and destination path is the same
|
||||
if (equalsCaseSensitive(source, destination)) {
|
||||
return destination;
|
||||
}
|
||||
|
||||
if (source.isDirectory()) {
|
||||
// move folder
|
||||
FileUtils.moveDirectory(source, destination);
|
||||
|
@ -67,11 +72,11 @@ public final class FileUtilities {
|
|||
|
||||
// on Windows, use ATOMIC_MOVE which allows us to rename files even if only lower/upper-case changes (without ATOMIC_MOVE the operation would be ignored)
|
||||
// but ATOMIC_MOVE can only work for files on the same drive, if that is not the case there is no point trying move with ATOMIC_MOVE
|
||||
if (isWindows() && source.equals(destination) && !equalsCaseSensitive(source, destination)) {
|
||||
if (isWindows() && source.equals(destination)) {
|
||||
try {
|
||||
return Files.move(source.toPath(), destination.toPath(), StandardCopyOption.ATOMIC_MOVE).toFile();
|
||||
} catch (AtomicMoveNotSupportedException e) {
|
||||
debug.warning(e.getMessage());
|
||||
debug.warning(e::toString);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue