diff --git a/CHANGELOG.md b/CHANGELOG.md index ffecf1b4298..bb82b89a80e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -87,6 +87,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We fixed an issue where the Undo/Redo buttons were active even when all libraries are closed. [#11837](https://github.com/JabRef/jabref/issues/11837) - We fixed an issue where recently opened files were not displayed in the main menu properly. [#9042](https://github.com/JabRef/jabref/issues/9042) - We fixed an issue where the DOI lookup would show an error when a DOI was found for an entry. [#11850](https://github.com/JabRef/jabref/issues/11850) +- We fixed an issue where we display warning message for moving attached open files. [#10121](https://github.com/JabRef/jabref/issues/10121) ### Removed diff --git a/src/main/java/org/jabref/gui/cleanup/CleanupAction.java b/src/main/java/org/jabref/gui/cleanup/CleanupAction.java index 9fdac23cd88..d0a5879da3d 100644 --- a/src/main/java/org/jabref/gui/cleanup/CleanupAction.java +++ b/src/main/java/org/jabref/gui/cleanup/CleanupAction.java @@ -1,5 +1,7 @@ package org.jabref.gui.cleanup; +import java.nio.file.FileSystemException; +import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.function.Supplier; @@ -31,6 +33,7 @@ public class CleanupAction extends SimpleCommand { private final StateManager stateManager; private final TaskExecutor taskExecutor; private final UndoManager undoManager; + private List exceptions; private boolean isCanceled; private int modifiedEntriesCount; @@ -47,6 +50,7 @@ public CleanupAction(Supplier tabSupplier, this.stateManager = stateManager; this.taskExecutor = taskExecutor; this.undoManager = undoManager; + this.exceptions = new ArrayList<>(); this.executable.bind(ActionHelper.needsEntriesSelected(stateManager)); } @@ -113,6 +117,8 @@ private void doCleanup(BibDatabaseContext databaseContext, CleanupPreferences pr for (FieldChange change : changes) { ce.addEdit(new UndoableFieldChange(change)); } + + exceptions = cleaner.getFileSystemExceptions(); } private void showResults() { @@ -132,6 +138,20 @@ private void showResults() { } else { dialogService.notify(Localization.lang("%0 entries needed a clean up", Integer.toString(modifiedEntriesCount))); } + + if (!exceptions.isEmpty()) { + showExceptions(); + } + } + + private void showExceptions() { + StringBuilder sb = new StringBuilder(); + sb.append(Localization.lang("The following errors occurred while moving files:")).append("\n\n"); + for (FileSystemException exception : exceptions) { + FileSystemException fse = exception; + sb.append("- ").append(Localization.lang("Could not move file %0. Please close this file and retry.", fse.getFile())).append("\n"); + } + dialogService.showErrorDialogAndWait(Localization.lang("File Move Errors"), sb.toString()); } private void cleanup(BibDatabaseContext databaseContext, CleanupPreferences cleanupPreferences) { diff --git a/src/main/java/org/jabref/logic/cleanup/CleanupWorker.java b/src/main/java/org/jabref/logic/cleanup/CleanupWorker.java index e9b01ad7081..61e07572574 100644 --- a/src/main/java/org/jabref/logic/cleanup/CleanupWorker.java +++ b/src/main/java/org/jabref/logic/cleanup/CleanupWorker.java @@ -1,5 +1,6 @@ package org.jabref.logic.cleanup; +import java.nio.file.FileSystemException; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -15,11 +16,13 @@ public class CleanupWorker { private final BibDatabaseContext databaseContext; private final FilePreferences filePreferences; private final TimestampPreferences timestampPreferences; + private final List fileSystemExceptions; public CleanupWorker(BibDatabaseContext databaseContext, FilePreferences filePreferences, TimestampPreferences timestampPreferences) { this.databaseContext = databaseContext; this.filePreferences = filePreferences; this.timestampPreferences = timestampPreferences; + this.fileSystemExceptions = new ArrayList<>(); } public List cleanup(CleanupPreferences preset, BibEntry entry) { @@ -31,6 +34,10 @@ public List cleanup(CleanupPreferences preset, BibEntry entry) { List changes = new ArrayList<>(); for (CleanupJob job : jobs) { changes.addAll(job.cleanup(entry)); + + if (job instanceof MoveFilesCleanup) { + fileSystemExceptions.addAll(((MoveFilesCleanup) job).getFileSystemExceptions()); + } } return changes; @@ -86,4 +93,8 @@ private CleanupJob toJob(CleanupPreferences.CleanupStep action) { throw new UnsupportedOperationException(action.name()); }; } + + public List getFileSystemExceptions() { + return fileSystemExceptions; + } } diff --git a/src/main/java/org/jabref/logic/cleanup/MoveFilesCleanup.java b/src/main/java/org/jabref/logic/cleanup/MoveFilesCleanup.java index c05a5c1a807..57c19ef7b4f 100644 --- a/src/main/java/org/jabref/logic/cleanup/MoveFilesCleanup.java +++ b/src/main/java/org/jabref/logic/cleanup/MoveFilesCleanup.java @@ -1,6 +1,8 @@ package org.jabref.logic.cleanup; import java.io.IOException; +import java.nio.file.FileSystemException; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; @@ -18,15 +20,16 @@ import org.slf4j.LoggerFactory; public class MoveFilesCleanup implements CleanupJob { - private static final Logger LOGGER = LoggerFactory.getLogger(MoveFilesCleanup.class); private final BibDatabaseContext databaseContext; private final FilePreferences filePreferences; + private final List fileSystemExceptions; public MoveFilesCleanup(BibDatabaseContext databaseContext, FilePreferences filePreferences) { this.databaseContext = Objects.requireNonNull(databaseContext); this.filePreferences = Objects.requireNonNull(filePreferences); + this.fileSystemExceptions = new ArrayList<>(); } @Override @@ -41,6 +44,8 @@ public List cleanup(BibEntry entry) { if (fileChanged) { changed = true; } + } catch (FileSystemException exception) { + fileSystemExceptions.add(exception); } catch (IOException exception) { LOGGER.error("Error while moving file {}", file.getLink(), exception); } @@ -53,4 +58,8 @@ public List cleanup(BibEntry entry) { return Collections.emptyList(); } + + public List getFileSystemExceptions() { + return fileSystemExceptions; + } } diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 0d980636e73..19750902c34 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2797,3 +2797,7 @@ Warning\:\ The\ selected\ directory\ is\ not\ a\ valid\ directory.=Warning: The Currently\ selected\ JStyle\:\ '%0' = Currently selected JStyle: '%0' Currently\ selected\ CSL\ Style\:\ '%0' = Currently selected CSL Style: '%0' Store\ url\ for\ downloaded\ file=Store url for downloaded file + +File\ Move\ Errors=File Move Errors +Could\ not\ move\ file\ %0.\ Please\ close\ this\ file\ and\ retry.=Could not move file %0. Please close this file and retry. +The\ following\ errors\ occurred\ while\ moving\ files:=The following errors occurred while moving files: