From 482e7aa083bdea76c27fb7bc5f293b782d1cf280 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Tue, 17 Jul 2018 11:54:18 +0200 Subject: [PATCH 1/5] Make attached files relative to the file directory Fixes #4201 Open files with default OS application if no External file type is present --- .../java/org/jabref/gui/desktop/JabRefDesktop.java | 13 +++++-------- .../org/jabref/gui/filelist/AttachFileAction.java | 11 ++++++++--- .../filelist/LinkedFilesEditDialogViewModel.java | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java b/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java index cfff8fb441c..9f6bfeda0b8 100644 --- a/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java +++ b/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java @@ -129,20 +129,15 @@ public static boolean openExternalFileAnyFormat(final BibDatabaseContext databas } Optional file = FileHelper.expandFilename(databaseContext, link, Globals.prefs.getFileDirectoryPreferences()); - if (file.isPresent() && Files.exists(file.get()) && (type.isPresent())) { + if (file.isPresent() && Files.exists(file.get())) { // Open the file: String filePath = file.get().toString(); openExternalFilePlatformIndependent(type, filePath); return true; } else { // No file matched the name, try to open it directly using the given app - if (type.isPresent()) { - openExternalFilePlatformIndependent(type, link); - return true; - } - - // Run out of ideas what to do... - return false; + openExternalFilePlatformIndependent(type, link); + return true; } } @@ -160,6 +155,8 @@ private static void openExternalFilePlatformIndependent(Optional { - LinkedFile newLinkedFile = new LinkedFile("", newFile.toString(), ""); + + Path relativePath = FileUtil.shortenFileName(newFile, panel.getBibDatabaseContext().getFileDirectoriesAsPaths(Globals.prefs.getFileDirectoryPreferences())); + LinkedFile newLinkedFile = new LinkedFile("", relativePath.toString(), ""); + LinkedFileEditDialogView dialog = new LinkedFileEditDialogView(newLinkedFile); diff --git a/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java b/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java index 5a24ba38822..dceb5114912 100644 --- a/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java +++ b/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java @@ -119,7 +119,7 @@ public ObjectProperty selectedExternalFileTypeProperty() { } public LinkedFile getNewLinkedFile() { - return new LinkedFile(description.getValue(), link.getValue(), selectedExternalFileType.getValue().toString()); + return new LinkedFile(description.getValue(), link.getValue(), selectedExternalFileType.getValue() == null ? null : selectedExternalFileType.getValue().toString()); } From c32aca63ed892d9a754d8ae194799da9a37e99cc Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Tue, 17 Jul 2018 11:57:58 +0200 Subject: [PATCH 2/5] add changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61cf25bc5be..7d5e6b18a97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +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. +- Files without a defined external file type are now directly opened with the default aplication of the operating system @@ -57,7 +58,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - We fixed an issue where the "Convert to BibTeX-Cleanup" moved the content of the `file` field to the `pdf` field [#4120](https://github.com/JabRef/jabref/issues/4120) - We fixed an issue where the preview pane in entry preview in preferences wasn't showing the citation style selected [#3849](https://github.com/JabRef/jabref/issues/3849) - We fixed an issue where the default entry preview style still contained the field `review`. The field `review` in the style is now replaced with comment to be consistent with the entry editor [#4098](https://github.com/JabRef/jabref/issues/4098) - +- We fixed an issue where filles added via the "Attach file" contextmenu of an entry were not made relative. [#4201](https://github.com/JabRef/jabref/issues/4201) From a19125c861657eeba2cb4433d3775eabf4cb8bc2 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Tue, 24 Jul 2018 15:44:35 +0200 Subject: [PATCH 3/5] use method from linked files view model for linked file --- .../java/org/jabref/gui/filelist/AttachFileAction.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/jabref/gui/filelist/AttachFileAction.java b/src/main/java/org/jabref/gui/filelist/AttachFileAction.java index 19fd3e4dad6..47e89416858 100644 --- a/src/main/java/org/jabref/gui/filelist/AttachFileAction.java +++ b/src/main/java/org/jabref/gui/filelist/AttachFileAction.java @@ -1,16 +1,15 @@ package org.jabref.gui.filelist; -import java.nio.file.Path; import java.util.Optional; import org.jabref.Globals; import org.jabref.gui.BasePanel; import org.jabref.gui.DialogService; import org.jabref.gui.actions.SimpleCommand; +import org.jabref.gui.fieldeditors.LinkedFilesEditorViewModel; import org.jabref.gui.undo.UndoableFieldChange; import org.jabref.gui.util.FileDialogConfiguration; import org.jabref.logic.l10n.Localization; -import org.jabref.logic.util.io.FileUtil; import org.jabref.model.FieldChange; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.LinkedFile; @@ -39,11 +38,9 @@ public void execute() { dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(newFile -> { - Path relativePath = FileUtil.shortenFileName(newFile, panel.getBibDatabaseContext().getFileDirectoriesAsPaths(Globals.prefs.getFileDirectoryPreferences())); - LinkedFile newLinkedFile = new LinkedFile("", relativePath.toString(), ""); + LinkedFile linkedFile = LinkedFilesEditorViewModel.fromFile(newFile, panel.getBibDatabaseContext().getFileDirectoriesAsPaths(Globals.prefs.getFileDirectoryPreferences())); - - LinkedFileEditDialogView dialog = new LinkedFileEditDialogView(newLinkedFile); + LinkedFileEditDialogView dialog = new LinkedFileEditDialogView(linkedFile); dialog.showAndWait() .ifPresent(editedLinkedFile -> { From 4aba5a4a7a3dbccc73f2f332e42d39c343d3ecfc Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Wed, 25 Jul 2018 11:15:51 +0200 Subject: [PATCH 4/5] fix opening of file from menu add monadic binding --- src/main/java/org/jabref/gui/BasePanel.java | 3 ++- src/main/java/org/jabref/gui/desktop/JabRefDesktop.java | 4 +++- .../gui/filelist/LinkedFilesEditDialogViewModel.java | 9 +++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 54938361525..52167a8b624 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -62,6 +62,7 @@ import org.jabref.gui.filelist.FileListEntry; import org.jabref.gui.filelist.FileListTableModel; import org.jabref.gui.groups.GroupAddRemoveDialog; +import org.jabref.gui.icon.JabRefIcon; import org.jabref.gui.importer.actions.AppendDatabaseAction; import org.jabref.gui.journals.AbbreviateAction; import org.jabref.gui.journals.UnabbreviateAction; @@ -674,7 +675,7 @@ private void openExternalFile() { return; } FileListEntry flEntry = fileListTableModel.getEntry(0); - ExternalFileMenuItem item = new ExternalFileMenuItem(frame(), "", flEntry.getLink(), flEntry.getType().get().getIcon().getSmallIcon(), bibDatabaseContext, flEntry.getType()); + ExternalFileMenuItem item = new ExternalFileMenuItem(frame(), "", flEntry.getLink(), flEntry.getType().map(ExternalFileType::getIcon).map(JabRefIcon::getSmallIcon).orElse(null), bibDatabaseContext, flEntry.getType()); item.doClick(); }); } diff --git a/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java b/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java index 9f6bfeda0b8..c9c1a515aa4 100644 --- a/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java +++ b/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java @@ -156,7 +156,9 @@ private static void openExternalFilePlatformIndependent(Optional allExternalFileTypes = new SimpleListProperty<>(FXCollections.emptyObservableList()); private final ObjectProperty selectedExternalFileType = new SimpleObjectProperty<>(); + private final MonadicObservableValue monadiccSelectedExternalFileType; private final BibDatabaseContext database; private final DialogService dialogService; private final PreferencesService preferences; @@ -44,6 +48,8 @@ public LinkedFilesEditDialogViewModel(LinkedFile linkedFile, BibDatabaseContext this.preferences = preferences; this.externalFileTypes = externalFileTypes; allExternalFileTypes.set(FXCollections.observableArrayList(externalFileTypes.getExternalFileTypeSelection())); + + monadiccSelectedExternalFileType = EasyBind.monadic(selectedExternalFileType); setValues(linkedFile); } @@ -119,8 +125,7 @@ public ObjectProperty selectedExternalFileTypeProperty() { } public LinkedFile getNewLinkedFile() { - return new LinkedFile(description.getValue(), link.getValue(), selectedExternalFileType.getValue() == null ? null : selectedExternalFileType.getValue().toString()); - + return new LinkedFile(description.getValue(), link.getValue(), monadiccSelectedExternalFileType.map(ExternalFileType::toString).getOrElse("")); } } From 447288db372d992b0c92c864e7012275ea771aa3 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Wed, 25 Jul 2018 16:11:19 +0200 Subject: [PATCH 5/5] fix variable name --- .../jabref/gui/filelist/LinkedFilesEditDialogViewModel.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java b/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java index 5ec1cc1205b..492cda62592 100644 --- a/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java +++ b/src/main/java/org/jabref/gui/filelist/LinkedFilesEditDialogViewModel.java @@ -36,7 +36,7 @@ public class LinkedFilesEditDialogViewModel extends AbstractViewModel { private final StringProperty description = new SimpleStringProperty(""); private final ListProperty allExternalFileTypes = new SimpleListProperty<>(FXCollections.emptyObservableList()); private final ObjectProperty selectedExternalFileType = new SimpleObjectProperty<>(); - private final MonadicObservableValue monadiccSelectedExternalFileType; + private final MonadicObservableValue monadicSelectedExternalFileType; private final BibDatabaseContext database; private final DialogService dialogService; private final PreferencesService preferences; @@ -49,7 +49,7 @@ public LinkedFilesEditDialogViewModel(LinkedFile linkedFile, BibDatabaseContext this.externalFileTypes = externalFileTypes; allExternalFileTypes.set(FXCollections.observableArrayList(externalFileTypes.getExternalFileTypeSelection())); - monadiccSelectedExternalFileType = EasyBind.monadic(selectedExternalFileType); + monadicSelectedExternalFileType = EasyBind.monadic(selectedExternalFileType); setValues(linkedFile); } @@ -125,7 +125,7 @@ public ObjectProperty selectedExternalFileTypeProperty() { } public LinkedFile getNewLinkedFile() { - return new LinkedFile(description.getValue(), link.getValue(), monadiccSelectedExternalFileType.map(ExternalFileType::toString).getOrElse("")); + return new LinkedFile(description.getValue(), link.getValue(), monadicSelectedExternalFileType.map(ExternalFileType::toString).getOrElse("")); } }