Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into searchColPrefs
Browse files Browse the repository at this point in the history
* upstream/main:
  Observable Preferences H (WorkingDir, getUser, NameFormatter, Version, SpecialFields) (#8260)
  Bump checkstyle from 9.0.1 to 9.1 (#8266)
  Bump mockito-core from 4.0.0 to 4.1.0 (#8267)
  Bump classgraph from 4.8.130 to 4.8.135 (#8268)
  Fix some fetcher tests (#8258)
  Clicking a DOI link in the preview pane no longer crashes (#8255)
  • Loading branch information
Siedlerchr committed Nov 22, 2021
2 parents c1282f9 + ab13b2a commit e367b1e
Show file tree
Hide file tree
Showing 67 changed files with 376 additions and 433 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- The default directory of the "LaTeX Citations" tab is now the directory of the currently opened database (and not the directory chosen at the last open file dialog or the last database save) [koppor#538](https://github.com/koppor/jabref/issues/538)
- We fixed an issue where right-clicking on a tab and selecting close will close the focused tab even if it is not the tab we right-clicked [#8193](https://github.com/JabRef/jabref/pull/8193)
- We fixed an issue where selecting a citation style in the preferences would sometimes produce an exception [#7860](https://github.com/JabRef/jabref/issues/7860)
- We fixed an issue where an exception would occur when clicking on a DOI link in the preview pane [#7706](https://github.com/JabRef/jabref/issues/7706)

### Removed

Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,14 @@ dependencies {

implementation group: 'net.harawata', name: 'appdirs', version: '1.2.1'

testImplementation 'io.github.classgraph:classgraph:4.8.130'
testImplementation 'io.github.classgraph:classgraph:4.8.135'
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
testImplementation 'org.junit.platform:junit-platform-launcher:1.8.1'

testImplementation 'net.bytebuddy:byte-buddy-parent:1.12.1'
testRuntimeOnly group: 'org.apache.logging.log4j', name: 'log4j-core', version: '3.0.0-SNAPSHOT'
testRuntimeOnly group: 'org.apache.logging.log4j', name: 'log4j-jul', version: '3.0.0-SNAPSHOT'
testImplementation 'org.mockito:mockito-core:4.0.0'
testImplementation 'org.mockito:mockito-core:4.1.0'
testImplementation 'org.xmlunit:xmlunit-core:2.8.3'
testImplementation 'org.xmlunit:xmlunit-matchers:2.8.3'
testRuntimeOnly 'com.tngtech.archunit:archunit-junit5-engine:0.22.0'
Expand All @@ -223,7 +223,7 @@ dependencies {
testImplementation "org.testfx:testfx-junit5:4.0.17-alpha-SNAPSHOT"
testImplementation "org.hamcrest:hamcrest-library:2.2"

checkstyle 'com.puppycrawl.tools:checkstyle:9.0.1'
checkstyle 'com.puppycrawl.tools:checkstyle:9.1'
xjc group: 'org.glassfish.jaxb', name: 'jaxb-xjc', version: '2.3.3'
}

Expand Down
24 changes: 12 additions & 12 deletions src/main/java/org/jabref/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,28 +310,28 @@ private void writeMetadatatoPDFsOfEntry(BibDatabaseContext databaseContext, Stri
try {
if (writeXMP) {
if (xmpPdfExporter.exportToAllFilesOfEntry(databaseContext, encoding, filePreferences, entry, List.of(entry))) {
System.out.println(String.format("Successfully written XMP metadata on at least one linked file of %s", citeKey));
System.out.printf("Successfully written XMP metadata on at least one linked file of %s%n", citeKey);
} else {
System.err.println(String.format("Cannot write XMP metadata on any linked files of %s. Make sure there is at least one linked file and the path is correct.", citeKey));
System.err.printf("Cannot write XMP metadata on any linked files of %s. Make sure there is at least one linked file and the path is correct.%n", citeKey);
}
}
if (embeddBibfile) {
if (embeddedBibFilePdfExporter.exportToAllFilesOfEntry(databaseContext, encoding, filePreferences, entry, List.of(entry))) {
System.out.println(String.format("Successfully embedded metadata on at least one linked file of %s", citeKey));
System.out.printf("Successfully embedded metadata on at least one linked file of %s%n", citeKey);
} else {
System.out.println(String.format("Cannot embedd metadata on any linked files of %s. Make sure there is at least one linked file and the path is correct.", citeKey));
System.out.printf("Cannot embedd metadata on any linked files of %s. Make sure there is at least one linked file and the path is correct.%n", citeKey);
}
}
} catch (Exception e) {
LOGGER.error(String.format("Failed writing metadata on a linked file of %s.", citeKey));
LOGGER.error("Failed writing metadata on a linked file of {}.", citeKey);
}
}

private void writeMetadatatoPdfByCitekey(BibDatabaseContext databaseContext, BibDatabase dataBase, Vector<String> citeKeys, Charset encoding, FilePreferences filePreferences, XmpPdfExporter xmpPdfExporter, EmbeddedBibFilePdfExporter embeddedBibFilePdfExporter, boolean writeXMP, boolean embeddBibfile) {
for (String citeKey : citeKeys) {
List<BibEntry> bibEntryList = dataBase.getEntriesByCitationKey(citeKey);
if (bibEntryList.isEmpty()) {
System.err.println(String.format("Skipped - Cannot find %s in library.", citeKey));
System.err.printf("Skipped - Cannot find %s in library.%n", citeKey);
continue;
}
for (BibEntry entry : bibEntryList) {
Expand All @@ -350,25 +350,25 @@ private void writeMetadatatoPdfByFileNames(BibDatabaseContext databaseContext, B
try {
if (writeXMP) {
if (xmpPdfExporter.exportToFileByPath(databaseContext, dataBase, encoding, filePreferences, filePath)) {
System.out.println(String.format("Successfully written XMP metadata of at least one entry to %s", fileName));
System.out.printf("Successfully written XMP metadata of at least one entry to %s%n", fileName);
} else {
System.out.println(String.format("File %s is not linked to any entry in database.", fileName));
System.out.printf("File %s is not linked to any entry in database.%n", fileName);
}
}
if (embeddBibfile) {
if (embeddedBibFilePdfExporter.exportToFileByPath(databaseContext, dataBase, encoding, filePreferences, filePath)) {
System.out.println(String.format("Successfully embedded XMP metadata of at least one entry to %s", fileName));
System.out.printf("Successfully embedded XMP metadata of at least one entry to %s%n", fileName);
} else {
System.out.println(String.format("File %s is not linked to any entry in database.", fileName));
System.out.printf("File %s is not linked to any entry in database.%n", fileName);
}
}
} catch (IOException e) {
LOGGER.error("Error accessing file '{}'.", fileName);
} catch (Exception e) {
LOGGER.error(String.format("Error writing entry to %s.", fileName));
LOGGER.error("Error writing entry to {}.", fileName);
}
} else {
LOGGER.error(String.format("Skipped - PDF %s does not exist", fileName));
LOGGER.error("Skipped - PDF {} does not exist", fileName);
}
}
}
Expand Down
29 changes: 15 additions & 14 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -754,19 +754,20 @@ private MenuBar createMenu() {
factory.createMenuItem(StandardActions.MASS_SET_FIELDS, new MassSetFieldsAction(stateManager, dialogService, undoManager))
);

if (prefs.getSpecialFieldsPreferences().isSpecialFieldsEnabled()) {
edit.getItems().addAll(
new SeparatorMenuItem(),
// ToDo: SpecialField needs the active BasePanel to mark it as changed.
// Refactor BasePanel, should mark the BibDatabaseContext or the UndoManager as dirty instead!
SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.RANKING, factory, this, dialogService, prefs, undoManager, stateManager),
SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.RELEVANCE, factory, this, dialogService, prefs, undoManager, stateManager),
SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.QUALITY, factory, this, dialogService, prefs, undoManager, stateManager),
SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.PRINTED, factory, this, dialogService, prefs, undoManager, stateManager),
SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.PRIORITY, factory, this, dialogService, prefs, undoManager, stateManager),
SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.READ_STATUS, factory, this, dialogService, prefs, undoManager, stateManager)
);
}
SeparatorMenuItem specialFieldsSeparator = new SeparatorMenuItem();
specialFieldsSeparator.visibleProperty().bind(prefs.getSpecialFieldsPreferences().specialFieldsEnabledProperty());

edit.getItems().addAll(
specialFieldsSeparator,
// ToDo: SpecialField needs the active BasePanel to mark it as changed.
// Refactor BasePanel, should mark the BibDatabaseContext or the UndoManager as dirty instead!
SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.RANKING, factory, this, dialogService, prefs, undoManager, stateManager),
SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.RELEVANCE, factory, this, dialogService, prefs, undoManager, stateManager),
SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.QUALITY, factory, this, dialogService, prefs, undoManager, stateManager),
SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.PRINTED, factory, this, dialogService, prefs, undoManager, stateManager),
SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.PRIORITY, factory, this, dialogService, prefs, undoManager, stateManager),
SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.READ_STATUS, factory, this, dialogService, prefs, undoManager, stateManager)
);

// @formatter:off
library.getItems().addAll(
Expand Down Expand Up @@ -1192,7 +1193,7 @@ private Boolean confirmEmptyEntry(LibraryTab libraryTab, BibDatabaseContext cont
if (response.isPresent() && response.get().equals(deleteEmptyEntries)) {
// The user wants to delete.
try {
for (BibEntry currentEntry : new ArrayList<BibEntry>(context.getEntries())) {
for (BibEntry currentEntry : new ArrayList<>(context.getEntries())) {
if (currentEntry.getFields().isEmpty()) {
context.getDatabase().removeEntries(Collections.singletonList(currentEntry));
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public JabRefGUI(Stage mainStage, List<ParserResult> databases, boolean isBlank,
openWindow(mainStage);

new VersionWorker(Globals.BUILD_INFO.version,
preferencesService.getVersionPreferences().getIgnoredVersion(),
mainFrame.getDialogService(),
Globals.TASK_EXECUTOR)
Globals.TASK_EXECUTOR,
preferencesService.getVersionPreferences())
.checkForNewVersionDelayed();
}

Expand Down
3 changes: 0 additions & 3 deletions src/main/java/org/jabref/gui/LibraryTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.jabref.gui.importer.actions.OpenDatabaseAction;
import org.jabref.gui.maintable.MainTable;
import org.jabref.gui.maintable.MainTableDataModel;
import org.jabref.gui.specialfields.SpecialFieldDatabaseChangeListener;
import org.jabref.gui.undo.CountingUndoManager;
import org.jabref.gui.undo.NamedCompound;
import org.jabref.gui.undo.UndoableFieldChange;
Expand Down Expand Up @@ -465,8 +464,6 @@ public void editEntryAndFocusField(BibEntry entry, Field field) {
}

private void createMainTable() {
bibDatabaseContext.getDatabase().registerListener(SpecialFieldDatabaseChangeListener.INSTANCE);

mainTable = new MainTable(tableModel,
this,
bibDatabaseContext,
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/auximport/FromAuxDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private void browseButtonClicked() {
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder()
.addExtensionFilter(StandardFileType.AUX)
.withDefaultExtension(StandardFileType.AUX)
.withInitialDirectory(preferences.getWorkingDir()).build();
.withInitialDirectory(preferences.getFilePreferences().getWorkingDirectory()).build();
dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(file -> auxFileField.setText(file.toAbsolutePath().toString()));
}
}
14 changes: 7 additions & 7 deletions src/main/java/org/jabref/gui/copyfiles/CopySingleFileAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,40 @@
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.LinkedFile;
import org.jabref.model.util.OptionalUtil;
import org.jabref.preferences.PreferencesService;
import org.jabref.preferences.FilePreferences;

public class CopySingleFileAction extends SimpleCommand {

private final LinkedFile linkedFile;
private final DialogService dialogService;
private final BibDatabaseContext databaseContext;
private final PreferencesService preferencesService;
private final FilePreferences filePreferences;

private final BiFunction<Path, Path, Path> resolvePathFilename = (path, file) -> path.resolve(file.getFileName());

public CopySingleFileAction(LinkedFile linkedFile, DialogService dialogService, BibDatabaseContext databaseContext, PreferencesService preferencesService) {
public CopySingleFileAction(LinkedFile linkedFile, DialogService dialogService, BibDatabaseContext databaseContext, FilePreferences filePreferences) {
this.linkedFile = linkedFile;
this.dialogService = dialogService;
this.databaseContext = databaseContext;
this.preferencesService = preferencesService;
this.filePreferences = filePreferences;

this.executable.bind(Bindings.createBooleanBinding(
() -> !linkedFile.isOnlineLink()
&& linkedFile.findIn(databaseContext, preferencesService.getFilePreferences()).isPresent(),
&& linkedFile.findIn(databaseContext, this.filePreferences).isPresent(),
linkedFile.linkProperty()));
}

@Override
public void execute() {
DirectoryDialogConfiguration dirDialogConfiguration = new DirectoryDialogConfiguration.Builder()
.withInitialDirectory(preferencesService.getWorkingDir())
.withInitialDirectory(filePreferences.getWorkingDirectory())
.build();
Optional<Path> exportPath = dialogService.showDirectorySelectionDialog(dirDialogConfiguration);
exportPath.ifPresent(this::copyFileToDestination);
}

private void copyFileToDestination(Path exportPath) {
Optional<Path> fileToExport = linkedFile.findIn(databaseContext, preferencesService.getFilePreferences());
Optional<Path> fileToExport = linkedFile.findIn(databaseContext, filePreferences);
Optional<Path> newPath = OptionalUtil.combine(Optional.of(exportPath), fileToExport, resolvePathFilename);

if (newPath.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,16 @@ enum Status {
private LatexParserResult latexParserResult;
private BibEntry currentEntry;

public LatexCitationsTabViewModel(BibDatabaseContext databaseContext, PreferencesService preferencesService,
TaskExecutor taskExecutor, DialogService dialogService) {
public LatexCitationsTabViewModel(BibDatabaseContext databaseContext,
PreferencesService preferencesService,
TaskExecutor taskExecutor,
DialogService dialogService) {
this.databaseContext = databaseContext;
this.preferencesService = preferencesService;
this.taskExecutor = taskExecutor;
this.dialogService = dialogService;
this.directory = new SimpleObjectProperty(databaseContext.getMetaData().getLatexFileDirectory(preferencesService.getUser())
.orElse(FileUtil.getInitialDirectory(databaseContext, preferencesService)));
this.directory = new SimpleObjectProperty<>(databaseContext.getMetaData().getLatexFileDirectory(preferencesService.getFilePreferences().getUser())
.orElse(FileUtil.getInitialDirectory(databaseContext, preferencesService.getFilePreferences().getWorkingDirectory())));
this.citationList = FXCollections.observableArrayList();
this.status = new SimpleObjectProperty<>(Status.IN_PROGRESS);
this.searchError = new SimpleStringProperty("");
Expand Down Expand Up @@ -128,8 +130,8 @@ private void cancelSearch() {

private Collection<Citation> searchAndParse(String citeKey) throws IOException {
// we need to check whether the user meanwhile set the LaTeX file directory or the database changed locations
Path newDirectory = databaseContext.getMetaData().getLatexFileDirectory(preferencesService.getUser())
.orElse(FileUtil.getInitialDirectory(databaseContext, preferencesService));
Path newDirectory = databaseContext.getMetaData().getLatexFileDirectory(preferencesService.getFilePreferences().getUser())
.orElse(FileUtil.getInitialDirectory(databaseContext, preferencesService.getFilePreferences().getWorkingDirectory()));

if (latexParserResult == null || !newDirectory.equals(directory.get())) {
directory.set(newDirectory);
Expand Down Expand Up @@ -170,7 +172,7 @@ public void setLatexDirectory() {
.withInitialDirectory(directory.get()).build();

dialogService.showDirectorySelectionDialog(directoryDialogConfiguration).ifPresent(selectedDirectory ->
databaseContext.getMetaData().setLatexFileDirectory(preferencesService.getUser(), selectedDirectory.toAbsolutePath()));
databaseContext.getMetaData().setLatexFileDirectory(preferencesService.getFilePreferences().getUser(), selectedDirectory.toAbsolutePath()));

init(currentEntry);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ private Optional<Path> askForSavePath() {
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder()
.addExtensionFilter(StandardFileType.BIBTEX_DB)
.withDefaultExtension(StandardFileType.BIBTEX_DB)
.withInitialDirectory(preferences.getWorkingDir())
.withInitialDirectory(preferences.getFilePreferences().getWorkingDirectory())
.build();
Optional<Path> selectedPath = dialogService.showFileSaveDialog(fileDialogConfiguration);
selectedPath.ifPresent(path -> preferences.setWorkingDirectory(path.getParent()));
selectedPath.ifPresent(path -> preferences.getFilePreferences().setWorkingDirectory(path.getParent()));
if (selectedPath.isPresent()) {
Path savePath = selectedPath.get();
// Workaround for linux systems not adding file extension
Expand Down
Loading

0 comments on commit e367b1e

Please sign in to comment.