From 7cb7ea60324932723db22fcd1964e26f73f7d9b4 Mon Sep 17 00:00:00 2001 From: Benedikt Tutzer Date: Mon, 4 May 2020 16:12:28 +0200 Subject: [PATCH] Added a download checkbox to the import dialog (#6381) * Added a download checkbox to the import dialog When importing entries, users now have a checkbox available to download files linked via url. * Added languages * removed translations * Fixed style problems * Added preference in import tab * Fixed style * Removed singleton-access to preferences * Downloaded file is inserted before link * Fix style * Consider FileDirPattern when downloading fulltext * Added changes Co-authored-by: Benedikt Tutzer --- CHANGELOG.md | 2 ++ .../gui/fieldeditors/LinkedFileViewModel.java | 7 +++++-- .../jabref/gui/importer/ImportEntriesDialog.fxml | 2 ++ .../jabref/gui/importer/ImportEntriesDialog.java | 6 +++++- .../gui/importer/ImportEntriesViewModel.java | 15 ++++++++++++++- .../org/jabref/gui/preferences/ImportTab.fxml | 2 ++ .../org/jabref/gui/preferences/ImportTabView.java | 3 +++ .../gui/preferences/ImportTabViewModel.java | 7 +++++++ .../java/org/jabref/model/entry/BibEntry.java | 6 ++++++ .../jabref/model/metadata/FilePreferences.java | 7 ++++++- .../org/jabref/preferences/JabRefPreferences.java | 6 +++++- src/main/resources/l10n/JabRef_en.properties | 1 + 12 files changed, 58 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d7f4d83496..f1046088013 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We added support for basic markdown in custom formatted previews [#6194](https://github.com/JabRef/jabref/issues/6194) - We now show the number of items found and selected to import in the online search dialog. [#6248](https://github.com/JabRef/jabref/pull/6248) - We created a new install screen for macOS. [#5759](https://github.com/JabRef/jabref/issues/5759) +- We implemented an option to download fulltext files while importing. [#6381](https://github.com/JabRef/jabref/pull/6381) ### Changed @@ -26,6 +27,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We changed the buttons for import/export/show all/reset of preferences to smaller icon buttons in the preferences dialog. [#6130](https://github.com/JabRef/jabref/pull/6130) - We moved the functionality "Manage field names & content" from the "Library" menu to the "Edit" menu, because it affects the selected entries and not the whole library - We merged the functionality "Append contents from a BibTeX library into the currently viewed library" into the "Import into database" functionality. Fixes [#6049](https://github.com/JabRef/jabref/issues/6049). +- We changed the directory where fulltext downloads are stored to the directory set in the import-tab in preferences. [#6381](https://github.com/JabRef/jabref/pull/6381) - We improved the error message for invalid jstyles. [#6303](https://github.com/JabRef/jabref/issues/6303) ### Fixed diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java index ca4af64148c..add0b6c1727 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java @@ -38,6 +38,7 @@ import org.jabref.logic.l10n.Localization; import org.jabref.logic.net.URLDownload; import org.jabref.logic.util.io.FileNameUniqueness; +import org.jabref.logic.util.io.FileUtil; import org.jabref.logic.xmp.XmpPreferences; import org.jabref.logic.xmp.XmpUtilWriter; import org.jabref.model.database.BibDatabaseContext; @@ -415,6 +416,7 @@ public void download() { LinkedFile newLinkedFile = LinkedFilesEditorViewModel.fromFile(destination, databaseContext.getFileDirectoriesAsPaths(filePreferences), externalFileTypes); linkedFile.setLink(newLinkedFile.getLink()); linkedFile.setFileType(newLinkedFile.getFileType()); + entry.addFile(0, newLinkedFile); }); downloadProgress.bind(downloadTask.workDonePercentageProperty()); taskExecutor.execute(downloadTask); @@ -431,8 +433,9 @@ public BackgroundTask prepareDownloadTask(Path targetDirectory, URLDownloa String suggestedTypeName = externalFileType.getName(); linkedFile.setFileType(suggestedTypeName); String suggestedName = linkedFileHandler.getSuggestedFileName(externalFileType.getExtension()); - suggestedName = FileNameUniqueness.getNonOverWritingFileName(targetDirectory, suggestedName); - return targetDirectory.resolve(suggestedName); + String fulltextDir = FileUtil.createDirNameFromPattern(databaseContext.getDatabase(), entry, filePreferences.getFileDirPattern()); + suggestedName = FileNameUniqueness.getNonOverWritingFileName(targetDirectory.resolve(fulltextDir), suggestedName); + return targetDirectory.resolve(fulltextDir).resolve(suggestedName); }) .then(destination -> new FileDownloadTask(urlDownload.getSource(), destination)) .onFailure(exception -> dialogService.showErrorDialogAndWait("Download failed", exception)); diff --git a/src/main/java/org/jabref/gui/importer/ImportEntriesDialog.fxml b/src/main/java/org/jabref/gui/importer/ImportEntriesDialog.fxml index 0a161e436ec..a9eaa748f47 100644 --- a/src/main/java/org/jabref/gui/importer/ImportEntriesDialog.fxml +++ b/src/main/java/org/jabref/gui/importer/ImportEntriesDialog.fxml @@ -1,6 +1,7 @@ + @@ -38,6 +39,7 @@