Skip to content

Commit

Permalink
Make attached files relative to the file directory (#4212)
Browse files Browse the repository at this point in the history
* Make attached files relative to the file directory

Fixes #4201
Open files with default OS application if no External file type is present

* add changelog

* use method from linked files view model for linked file

* fix opening of file from menu
add monadic binding

* fix variable name
  • Loading branch information
Siedlerchr authored Jul 25, 2018
1 parent ce071c7 commit 077fdac
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ 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 ̀<kbd>alt</kbd> + <kbd>up/down</kbd>.
- 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
- We streamlined the process to rename and move files by removing the confirmation dialogs.







### Fixed
- We fixed an issue where custom exports could not be selected in the 'Export (selected) entries' dialog [#4013](https://github.com/JabRef/jabref/issues/4013)
- Italic text is now rendered correctly. https://github.com/JabRef/jabref/issues/3356
Expand All @@ -58,7 +60,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)



Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
});
}
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/org/jabref/gui/desktop/JabRefDesktop.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,15 @@ public static boolean openExternalFileAnyFormat(final BibDatabaseContext databas
}

Optional<Path> 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;
}
}

Expand All @@ -160,6 +155,10 @@ private static void openExternalFilePlatformIndependent(Optional<ExternalFileTyp
} else {
NATIVE_DESKTOP.openFileWithApplication(filePath, application);
}
} else {
//File type is not given and therefore no application specified
//Let the OS handle the opening of the file
NATIVE_DESKTOP.openFile(filePath, "");
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/main/java/org/jabref/gui/filelist/AttachFileAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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;
Expand All @@ -32,13 +33,14 @@ public void execute() {
}
BibEntry entry = panel.getSelectedEntries().get(0);
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder()
.withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY))
.build();
.withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY))
.build();

dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(newFile -> {
LinkedFile newLinkedFile = new LinkedFile("", newFile.toString(), "");

LinkedFileEditDialogView dialog = new LinkedFileEditDialogView(newLinkedFile);
LinkedFile linkedFile = LinkedFilesEditorViewModel.fromFile(newFile, panel.getBibDatabaseContext().getFileDirectoriesAsPaths(Globals.prefs.getFileDirectoryPreferences()));

LinkedFileEditDialogView dialog = new LinkedFileEditDialogView(linkedFile);

dialog.showAndWait()
.ifPresent(editedLinkedFile -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@
import org.jabref.model.util.FileHelper;
import org.jabref.preferences.PreferencesService;

import org.fxmisc.easybind.EasyBind;
import org.fxmisc.easybind.monadic.MonadicObservableValue;

public class LinkedFilesEditDialogViewModel extends AbstractViewModel {

private static final Pattern REMOTE_LINK_PATTERN = Pattern.compile("[a-z]+://.*");
private final StringProperty link = new SimpleStringProperty("");
private final StringProperty description = new SimpleStringProperty("");
private final ListProperty<ExternalFileType> allExternalFileTypes = new SimpleListProperty<>(FXCollections.emptyObservableList());
private final ObjectProperty<ExternalFileType> selectedExternalFileType = new SimpleObjectProperty<>();
private final MonadicObservableValue<ExternalFileType> monadicSelectedExternalFileType;
private final BibDatabaseContext database;
private final DialogService dialogService;
private final PreferencesService preferences;
Expand All @@ -44,6 +48,8 @@ public LinkedFilesEditDialogViewModel(LinkedFile linkedFile, BibDatabaseContext
this.preferences = preferences;
this.externalFileTypes = externalFileTypes;
allExternalFileTypes.set(FXCollections.observableArrayList(externalFileTypes.getExternalFileTypeSelection()));

monadicSelectedExternalFileType = EasyBind.monadic(selectedExternalFileType);
setValues(linkedFile);
}

Expand Down Expand Up @@ -119,8 +125,7 @@ public ObjectProperty<ExternalFileType> selectedExternalFileTypeProperty() {
}

public LinkedFile getNewLinkedFile() {
return new LinkedFile(description.getValue(), link.getValue(), selectedExternalFileType.getValue().toString());

return new LinkedFile(description.getValue(), link.getValue(), monadicSelectedExternalFileType.map(ExternalFileType::toString).getOrElse(""));
}

}

0 comments on commit 077fdac

Please sign in to comment.