Skip to content

Commit

Permalink
Changed default value of "search and store files relative to bibtex f…
Browse files Browse the repository at this point in the history
…ile" to true (#6928)

* Fixes #6863

* CHANGELOG.md

* Reworded bibLocationAsPrimary to reflect real meaning of the preference setting, changed default val to true

* Cleanup of deprecated methods LinkedFiles(String, String, String) and List<String> getFileDirectories(...)

* Reworded package filelist to linkedfile

* Fixed SpringerFetcher
  • Loading branch information
calixtus committed Sep 25, 2020
1 parent 75b6770 commit 3123090
Show file tree
Hide file tree
Showing 51 changed files with 290 additions and 338 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We completed the rebranding of `bibtexkey` as `citationkey` which was started in JabRef 5.1.
- JabRef no longer opens the entry editor with the first entry on startup [#6855](https://github.com/JabRef/jabref/issues/6855)
- Fetch by ID: (long) "SAO/NASA Astrophysics Data System" replaced by (short) "SAO/NASA ADS" [#6876](https://github.com/JabRef/jabref/pull/6876)
- We changed the default preference option "Search and store files relative to library file location" to on, as this seems to be a more intuitive behaviour. [#6863](https://github.com/JabRef/jabref/issues/6863)
- We changed the title of the window "Manage field names and content": to have the same title as the corresponding menu item [#6895](https://github.com/JabRef/jabref/pull/6895)
- Improved detection of "short" DOIs [6880](https://github.com/JabRef/jabref/issues/6880)

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private void openDatabases() {
new SharedDatabaseUIManager(mainFrame).openSharedDatabaseFromParserResult(pr);
} catch (SQLException | DatabaseNotSupportedException | InvalidDBMSConnectionPropertiesException |
NotASharedDatabaseException e) {
pr.getDatabaseContext().clearDatabaseFile(); // do not open the original file
pr.getDatabaseContext().clearDatabasePath(); // do not open the original file
pr.getDatabase().clearSharedDatabaseID();

LOGGER.error("Connection error", e);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/SendAsEMailAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private String sendEmail() throws Exception {
// the unofficial "mailto:attachment" property
boolean openFolders = JabRefPreferences.getInstance().getBoolean(JabRefPreferences.OPEN_FOLDERS_OF_ATTACHED_FILES);

List<Path> fileList = FileUtil.getListOfLinkedFiles(entries, databaseContext.getFileDirectoriesAsPaths(Globals.prefs.getFilePreferences()));
List<Path> fileList = FileUtil.getListOfLinkedFiles(entries, databaseContext.getFileDirectories(Globals.prefs.getFilePreferences()));
for (Path path : fileList) {
attachments.add(path.toAbsolutePath().toString());
if (openFolders) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/desktop/JabRefDesktop.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static void openExternalViewer(BibDatabaseContext databaseContext, String
Field field = initialField;
if (StandardField.PS.equals(field) || StandardField.PDF.equals(field)) {
// Find the default directory for this field type:
List<Path> directories = databaseContext.getFileDirectoriesAsPaths(Globals.prefs.getFilePreferences());
List<Path> directories = databaseContext.getFileDirectories(Globals.prefs.getFilePreferences());

Optional<Path> file = FileHelper.find(link, directories);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ private ExportResult exportToClipboard(Exporter exporter) throws Exception {
// Set the global variable for this database's file directory before exporting,
// so formatters can resolve linked files correctly.
// (This is an ugly hack!)
Globals.prefs.fileDirForDatabase = panel.getBibDatabaseContext().getFileDirectoriesAsPaths(Globals.prefs.getFilePreferences()).stream().map(Path::toString).collect(Collectors.toList());
Globals.prefs.fileDirForDatabase = panel.getBibDatabaseContext()
.getFileDirectories(Globals.prefs.getFilePreferences());

// Add chosen export type to last used pref, to become default
Globals.prefs.put(JabRefPreferences.LAST_USED_EXPORT, exporter.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class AutoSetFileLinksUtil {
private ExternalFileTypes externalFileTypes;

public AutoSetFileLinksUtil(BibDatabaseContext databaseContext, FilePreferences filePreferences, AutoLinkPreferences autoLinkPreferences, ExternalFileTypes externalFileTypes) {
this(databaseContext.getFileDirectoriesAsPaths(filePreferences), autoLinkPreferences, externalFileTypes);
this(databaseContext.getFileDirectories(filePreferences), autoLinkPreferences, externalFileTypes);
}

private AutoSetFileLinksUtil(List<Path> directories, AutoLinkPreferences autoLinkPreferences, ExternalFileTypes externalFileTypes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private void addLinkedFileFromURL(BibDatabaseContext databaseContext, URL url, B
downloadTask.onSuccess(destination -> {
LinkedFile downloadedFile = LinkedFilesEditorViewModel.fromFile(
destination,
databaseContext.getFileDirectoriesAsPaths(preferences.getFilePreferences()),
databaseContext.getFileDirectories(preferences.getFilePreferences()),
ExternalFileTypes.getInstance());
entry.addFile(downloadedFile);
dialogService.notify(Localization.lang("Finished downloading full text document for entry %0.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public void addFilesToEntry(BibEntry entry, List<Path> files) {
FileUtil.getFileExtension(file).ifPresent(ext -> {
ExternalFileType type = externalFileTypes.getExternalFileTypeByExt(ext)
.orElse(new UnknownExternalFileType(ext));
Path relativePath = FileUtil.relativize(file, bibDatabaseContext.getFileDirectoriesAsPaths(filePreferences));
LinkedFile linkedfile = new LinkedFile("", relativePath.toString(), type.getName());
Path relativePath = FileUtil.relativize(file, bibDatabaseContext.getFileDirectories(filePreferences));
LinkedFile linkedfile = new LinkedFile("", relativePath, type.getName());
entry.addFile(linkedfile);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
import org.jabref.gui.externalfiletype.ExternalFileType;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.externalfiletype.StandardExternalFileType;
import org.jabref.gui.filelist.LinkedFileEditDialogView;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.icon.JabRefIcon;
import org.jabref.gui.linkedfile.LinkedFileEditDialogView;
import org.jabref.gui.util.BackgroundTask;
import org.jabref.gui.util.ControlHelper;
import org.jabref.gui.util.TaskExecutor;
Expand Down Expand Up @@ -187,7 +187,7 @@ public Observable[] getObservables() {
observables.add(downloadOngoing);
observables.add(downloadProgress);
observables.add(isAutomaticallyFound);
return observables.toArray(new Observable[observables.size()]);
return observables.toArray(new Observable[0]);
}

public void open() {
Expand Down Expand Up @@ -426,7 +426,7 @@ public void download() {
URLDownload urlDownload = new URLDownload(linkedFile.getLink());
BackgroundTask<Path> downloadTask = prepareDownloadTask(targetDirectory.get(), urlDownload);
downloadTask.onSuccess(destination -> {
LinkedFile newLinkedFile = LinkedFilesEditorViewModel.fromFile(destination, databaseContext.getFileDirectoriesAsPaths(filePreferences), externalFileTypes);
LinkedFile newLinkedFile = LinkedFilesEditorViewModel.fromFile(destination, databaseContext.getFileDirectories(filePreferences), externalFileTypes);

List<LinkedFile> linkedFiles = entry.getFiles();
int oldFileIndex = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ public class LinkedFilesEditor extends HBox implements FieldEditorFX {
private final BibDatabaseContext databaseContext;
private final UiThreadObservableList<LinkedFileViewModel> decoratedModelList;

public LinkedFilesEditor(Field field, DialogService dialogService, BibDatabaseContext databaseContext, TaskExecutor taskExecutor, SuggestionProvider<?> suggestionProvider,
public LinkedFilesEditor(Field field,
DialogService dialogService,
BibDatabaseContext databaseContext,
TaskExecutor taskExecutor,
SuggestionProvider<?> suggestionProvider,
FieldCheckers fieldCheckers,
JabRefPreferences preferences) {
this.viewModel = new LinkedFilesEditorViewModel(field, suggestionProvider, dialogService, databaseContext, taskExecutor, fieldCheckers, preferences);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ public static LinkedFile fromFile(Path file, List<Path> fileDirectories, Externa
.getExternalFileTypeByExt(fileExtension)
.orElse(new UnknownExternalFileType(fileExtension));
Path relativePath = FileUtil.relativize(file, fileDirectories);
return new LinkedFile("", relativePath.toString(), suggestedFileType.getName());
return new LinkedFile("", relativePath, suggestedFileType.getName());
}

public LinkedFileViewModel fromFile(Path file) {
List<Path> fileDirectories = databaseContext.getFileDirectoriesAsPaths(preferences.getFilePreferences());
List<Path> fileDirectories = databaseContext.getFileDirectories(preferences.getFilePreferences());

LinkedFile linkedFile = fromFile(file, fileDirectories, externalFileTypes);
return new LinkedFileViewModel(
Expand Down Expand Up @@ -150,7 +150,7 @@ public void addNewFile() {
.withInitialDirectory(workingDirectory)
.build();

List<Path> fileDirectories = databaseContext.getFileDirectoriesAsPaths(preferences.getFilePreferences());
List<Path> fileDirectories = databaseContext.getFileDirectories(preferences.getFilePreferences());
dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(newFile -> {
LinkedFile newLinkedFile = fromFile(newFile, fileDirectories, externalFileTypes);
files.add(new LinkedFileViewModel(
Expand Down
77 changes: 0 additions & 77 deletions src/main/java/org/jabref/gui/filelist/FileListEntry.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private ParserResult loadDatabase(Path file) throws Exception {
new SharedDatabaseUIManager(frame).openSharedDatabaseFromParserResult(result);
} catch (SQLException | DatabaseNotSupportedException | InvalidDBMSConnectionPropertiesException |
NotASharedDatabaseException e) {
result.getDatabaseContext().clearDatabaseFile(); // do not open the original file
result.getDatabaseContext().clearDatabasePath(); // do not open the original file
result.getDatabase().clearSharedDatabaseID();
LOGGER.error("Connection error", e);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jabref.gui.filelist;
package org.jabref.gui.linkedfile;

import java.nio.file.Path;
import java.util.Optional;
Expand Down Expand Up @@ -60,7 +60,7 @@ public void execute() {

dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(newFile -> {
LinkedFile linkedFile = LinkedFilesEditorViewModel.fromFile(newFile,
databaseContext.getFileDirectoriesAsPaths(preferencesService.getFilePreferences()),
databaseContext.getFileDirectories(preferencesService.getFilePreferences()),
ExternalFileTypes.getInstance());

LinkedFileEditDialogView dialog = new LinkedFileEditDialogView(linkedFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<DialogPane minHeight="-Infinity" prefHeight="150.0" prefWidth="536.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.filelist.LinkedFileEditDialogView">
<DialogPane minHeight="-Infinity" prefHeight="150.0" prefWidth="536.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.linkedfile.LinkedFileEditDialogView">
<content>
<GridPane>
<columnConstraints>
Expand All @@ -22,19 +22,21 @@
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
</rowConstraints>
<children>
<Label minWidth="95.0" text="%Link"/>
<TextField fx:id="link" minHeight="-Infinity" minWidth="-Infinity" prefHeight="25.0" prefWidth="150.0" GridPane.columnIndex="1" GridPane.hgrow="ALWAYS"/>
<Label text="Description" GridPane.rowIndex="1"/>
<TextField fx:id="description" minHeight="-Infinity" minWidth="-Infinity" prefHeight="25.0" prefWidth="150.0" GridPane.columnIndex="1" GridPane.hgrow="ALWAYS" GridPane.rowIndex="1"/>
<ComboBox fx:id="fileType" minHeight="-Infinity" prefWidth="150.0" GridPane.columnIndex="1" GridPane.columnSpan="2" GridPane.hgrow="ALWAYS" GridPane.rowIndex="2"/>
<Button id="browse" mnemonicParsing="false" onAction="#openBrowseDialog" text="%Browse" GridPane.columnIndex="2">
<GridPane.margin>
<Insets left="10.0"/>
</GridPane.margin>
</Button>
<Label text="Filetype" GridPane.rowIndex="2"/>
</children>
<Label minWidth="95.0" text="%Link"/>
<TextField fx:id="link" minHeight="-Infinity" minWidth="-Infinity" prefHeight="25.0" prefWidth="150.0"
GridPane.columnIndex="1" GridPane.hgrow="ALWAYS"/>
<Label text="Description" GridPane.rowIndex="1"/>
<TextField fx:id="description" minHeight="-Infinity" minWidth="-Infinity" prefHeight="25.0"
prefWidth="150.0" GridPane.columnIndex="1" GridPane.hgrow="ALWAYS" GridPane.rowIndex="1"/>
<ComboBox fx:id="fileType" minHeight="-Infinity" prefWidth="150.0" GridPane.columnIndex="1"
GridPane.columnSpan="2" GridPane.hgrow="ALWAYS" GridPane.rowIndex="2"/>
<Button id="browse" mnemonicParsing="false" onAction="#openBrowseDialog" text="%Browse"
GridPane.columnIndex="2">
<GridPane.margin>
<Insets left="10.0"/>
</GridPane.margin>
</Button>
<Label text="Filetype" GridPane.rowIndex="2"/>
</GridPane>
</content>
</DialogPane>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jabref.gui.filelist;
package org.jabref.gui.linkedfile;

import javax.inject.Inject;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jabref.gui.filelist;
package org.jabref.gui.linkedfile;

import java.nio.file.Path;
import java.util.List;
Expand Down Expand Up @@ -125,11 +125,11 @@ public ObjectProperty<ExternalFileType> selectedExternalFileTypeProperty() {
}

public LinkedFile getNewLinkedFile() {
return new LinkedFile(description.getValue(), link.getValue(), monadicSelectedExternalFileType.getValue().map(ExternalFileType::toString).orElse(""));
return new LinkedFile(description.getValue(), Path.of(link.getValue()), monadicSelectedExternalFileType.getValue().map(ExternalFileType::toString).orElse(""));
}

private String relativize(Path filePath) {
List<Path> fileDirectories = database.getFileDirectoriesAsPaths(preferences.getFilePreferences());
List<Path> fileDirectories = database.getFileDirectories(preferences.getFilePreferences());
return FileUtil.relativize(filePath, fileDirectories).toString();
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/maintable/RightClickMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import org.jabref.gui.edit.CopyMoreAction;
import org.jabref.gui.edit.EditAction;
import org.jabref.gui.exporter.ExportToClipboardAction;
import org.jabref.gui.filelist.AttachFileAction;
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.linkedfile.AttachFileAction;
import org.jabref.gui.menus.ChangeEntryTypeMenu;
import org.jabref.gui.mergeentries.MergeEntriesAction;
import org.jabref.gui.mergeentries.MergeWithFetchedEntryAction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public LinkedFilesTabViewModel(DialogService dialogService, PreferencesService p
public void setValues() {
// External files preferences / Attached files preferences / File preferences
mainFileDirectoryProperty.setValue(initialFilePreferences.getFileDirectory().orElse(Path.of("")).toString());
useBibLocationAsPrimaryProperty.setValue(initialFilePreferences.isBibLocationAsPrimary());
useBibLocationAsPrimaryProperty.setValue(initialFilePreferences.shouldStoreFilesRelativeToBib());
searchFilesOnOpenProperty.setValue(initialFilePreferences.shouldSearchFilesOnOpen());
openBrowseOnCreateProperty.setValue(initialFilePreferences.shouldOpenBrowseOnCreate());
fileNamePatternProperty.setValue(initialFilePreferences.getFileNamePattern());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public List<FieldChange> cleanup(BibEntry entry) {
} else {
// only try to transform local file path to relative one
newFileName = FileUtil
.relativize(Path.of(oldFileName), databaseContext.getFileDirectoriesAsPaths(filePreferences))
.relativize(Path.of(oldFileName), databaseContext.getFileDirectories(filePreferences))
.toString();
}
LinkedFile newFileEntry = fileEntry;
if (!oldFileName.equals(newFileName)) {
newFileEntry = new LinkedFile(fileEntry.getDescription(), newFileName, fileEntry.getFileType());
newFileEntry = new LinkedFile(fileEntry.getDescription(), Path.of(newFileName), fileEntry.getFileType());
changed = true;
}
newFileList.add(newFileEntry);
Expand Down
Loading

0 comments on commit 3123090

Please sign in to comment.