diff --git a/CHANGELOG.md b/CHANGELOG.md index 61cf25bc5be..d51da016989 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - We changed the default keyboard shortcuts for moving between entries when the entry editor is active to ̀alt + up/down. - Opening a new file now prompts the directory of the currently selected file, instead of the directory of the last opened file. - Window state is saved on close and restored on start. - +- We streamlined the process to rename and move files by removing the confirmation dialogs. diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java index e1480c08688..8c59ea5d45e 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java @@ -201,34 +201,19 @@ public void rename() { // Cannot rename remote links return; } - Optional fileDir = databaseContext.getFirstExistingFileDir(fileDirectoryPreferences); - if (!fileDir.isPresent()) { - dialogService.showErrorDialogAndWait(Localization.lang("Rename file"), Localization.lang("File directory is not set or does not exist!")); - return; - } Optional file = linkedFile.findIn(databaseContext, fileDirectoryPreferences); if ((file.isPresent()) && Files.exists(file.get())) { RenamePdfCleanup pdfCleanup = new RenamePdfCleanup(false, databaseContext, fileDirPattern, fileDirectoryPreferences, linkedFile); - - String targetFileName = pdfCleanup.getTargetFileName(linkedFile, entry); - - boolean confirm = dialogService.showConfirmationDialogAndWait(Localization.lang("Rename file"), - Localization.lang("Rename file to") + " " + targetFileName, - Localization.lang("Rename file"), - Localization.lang("Cancel")); - - if (confirm) { - Optional fileConflictCheck = pdfCleanup.findExistingFile(linkedFile, entry); - performRenameWithConflictCheck(file, pdfCleanup, targetFileName, fileConflictCheck); - } + performRenameWithConflictCheck(file.get(), pdfCleanup); } else { dialogService.showErrorDialogAndWait(Localization.lang("File not found"), Localization.lang("Could not find file '%0'.", linkedFile.getLink())); } } - private void performRenameWithConflictCheck(Optional file, RenamePdfCleanup pdfCleanup, String targetFileName, Optional fileConflictCheck) { + private void performRenameWithConflictCheck(Path file, RenamePdfCleanup pdfCleanup) { boolean confirm; + Optional fileConflictCheck = pdfCleanup.findExistingFile(linkedFile, entry); if (!fileConflictCheck.isPresent()) { try { pdfCleanup.cleanupWithException(entry); @@ -236,6 +221,7 @@ private void performRenameWithConflictCheck(Optional file, RenamePdfCleanu dialogService.showErrorDialogAndWait(Localization.lang("Rename failed"), Localization.lang("JabRef cannot access the file because it is being used by another process.")); } } else { + String targetFileName = pdfCleanup.getTargetFileName(linkedFile, entry); confirm = dialogService.showConfirmationDialogAndWait(Localization.lang("File exists"), Localization.lang("'%0' exists. Overwrite file?", targetFileName), Localization.lang("Overwrite"), @@ -243,7 +229,7 @@ private void performRenameWithConflictCheck(Optional file, RenamePdfCleanu if (confirm) { try { - FileUtil.renameFileWithException(fileConflictCheck.get(), file.get(), true); + FileUtil.renameFileWithException(fileConflictCheck.get(), file, true); pdfCleanup.cleanupWithException(entry); } catch (IOException e) { dialogService.showErrorDialogAndWait(Localization.lang("Rename failed"), @@ -268,13 +254,9 @@ public void moveToDefaultDirectory() { Optional file = linkedFile.findIn(databaseContext, fileDirectoryPreferences); if ((file.isPresent()) && Files.exists(file.get())) { - // Linked file exists, so move it + // Found the linked file, so move it MoveFilesCleanup moveFiles = new MoveFilesCleanup(databaseContext, fileDirPattern, fileDirectoryPreferences, linkedFile); - - boolean confirm = dialogService.showConfirmationDialogAndWait(Localization.lang("Move file"), Localization.lang("Move file to file directory?") + " " + fileDir.get(), Localization.lang("Move file"), Localization.lang("Cancel")); - if (confirm) { - moveFiles.cleanup(entry); - } + moveFiles.cleanup(entry); } else { // File doesn't exist, so we can't move it. dialogService.showErrorDialogAndWait(Localization.lang("File not found"), Localization.lang("Could not find file '%0'.", linkedFile.getLink())); diff --git a/src/main/java/org/jabref/logic/util/io/FileBasedLock.java b/src/main/java/org/jabref/logic/util/io/FileBasedLock.java index 4ebeef010c9..62525eb8774 100644 --- a/src/main/java/org/jabref/logic/util/io/FileBasedLock.java +++ b/src/main/java/org/jabref/logic/util/io/FileBasedLock.java @@ -11,13 +11,11 @@ import org.slf4j.LoggerFactory; public class FileBasedLock { - private static final Logger LOGGER = LoggerFactory.getLogger(FileBasedLock.class); - /** - * The age in ms of a lockfile before JabRef will offer to "steal" the locked file. + * The age in ms of a lock file before JabRef will offer to "steal" the locked file. */ public static final long LOCKFILE_CRITICAL_AGE = 60000; - + private static final Logger LOGGER = LoggerFactory.getLogger(FileBasedLock.class); private static final String LOCKFILE_SUFFIX = ".lock"; // default retry count for acquiring file lock diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index e521d6e9272..80fc4e39a81 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -1196,7 +1196,6 @@ Error\ while\ fetching\ from\ %0=Error while fetching from %0 Show\ search\ results\ in\ a\ window=Show search results in a window Show\ global\ search\ results\ in\ a\ window=Show global search results in a window Search\ in\ all\ open\ libraries=Search in all open libraries -Move\ file\ to\ file\ directory?=Move file to file directory? Library\ is\ protected.\ Cannot\ save\ until\ external\ changes\ have\ been\ reviewed.=Library is protected. Cannot save until external changes have been reviewed. Protected\ library=Protected library