Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into switch-to-openj9
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor committed May 21, 2024
2 parents 9f0419f + 7dce65a commit 707172b
Show file tree
Hide file tree
Showing 31 changed files with 331 additions and 156 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- Added a formatter to remove word enclosing braces. [#11222](https://github.com/JabRef/jabref/issues/11222)
- We added the ability to add a keyword/crossref when typing the separator character (e.g., comma) in the keywords/crossref fields. [#11178](https://github.com/JabRef/jabref/issues/11178)
- We added an exporter and improved the importer for Endnote XML format. [#11137](https://github.com/JabRef/jabref/issues/11137)
- We added support for using BibTeX Style files (BST) in the Preview. [#11102](https://github.com/JabRef/jabref/issues/11102)
- We added support for automatically update LaTeX citations when a LaTeX file is created, removed, or modified. [#10585](https://github.com/JabRef/jabref/issues/10585)

### Changed
Expand Down
9 changes: 6 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ plugins {

id 'idea'

id 'org.openrewrite.rewrite' version '6.12.0'
id 'org.openrewrite.rewrite' version '6.14.0'
}

// Enable following for debugging
Expand Down Expand Up @@ -216,9 +216,9 @@ dependencies {
implementation('com.tobiasdiez:easybind:2.2.1-SNAPSHOT') {
exclude group: 'org.openjfx'
}
implementation 'org.fxmisc.flowless:flowless:0.7.2'
implementation 'org.fxmisc.flowless:flowless:0.7.3'
implementation 'org.fxmisc.richtext:richtextfx:0.11.2'
implementation (group: 'com.dlsc.gemsfx', name: 'gemsfx', version: '2.16.0') {
implementation (group: 'com.dlsc.gemsfx', name: 'gemsfx', version: '2.17.0') {
exclude module: 'javax.inject' // Split package, use only jakarta.inject
exclude module: 'commons-lang3'
exclude group: 'org.openjfx'
Expand Down Expand Up @@ -424,6 +424,9 @@ tasks.register('generateCitaviSource', XjcTask) {

tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'

// hint by https://docs.gradle.org/current/userguide/performance.html#run_the_compiler_as_a_separate_process
options.fork = true
}

compileJava {
Expand Down
10 changes: 10 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
org.gradle.vs.watch=true

# hint by https://docs.gradle.org/current/userguide/performance.html#increase_the_heap_size
org.gradle.jvmargs=-Xmx4096M

# hint by https://docs.gradle.org/current/userguide/performance.html#enable_configuration_cache
# Does not work:
# - Task `:compileJava` of type `org.gradle.api.tasks.compile.JavaCompile`: cannot serialize object of type 'org.gradle.api.internal.project.DefaultProject', a subtype of 'org.gradle.api.Project', as these are not supported with the configuration cache.
# org.gradle.configuration-cache=false

# hint by https://docs.gradle.org/current/userguide/performance.html#enable_the_build_cache
org.gradle.caching=true
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private FileAlterationListener getListener() {
@Override
public void onStart(FileAlterationObserver observer) {
if (!updateStatusOnCreate.get()) {
status.set(Status.IN_PROGRESS);
DefaultTaskExecutor.runInJavaFXThread(() -> status.set(Status.IN_PROGRESS));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<Label text="%Current Preview" styleClass="titleHeader"/>
<CheckBox fx:id="showAsTabCheckBox" text="%Show preview as a tab in entry editor"/>
<CheckBox fx:id="showPreviewTooltipCheckBox" text="Show preview in entry table tooltip"/>
<Button fx:id="bstFileButton" text="%Add BST file" onAction="#selectBstFile" />
<HBox spacing="4.0">
<VBox spacing="4.0" HBox.hgrow="ALWAYS">
<Label text="%Available" styleClass="sectionHeader"/>
Expand Down
33 changes: 27 additions & 6 deletions src/main/java/org/jabref/gui/preferences/preview/PreviewTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import javafx.application.Platform;
import javafx.beans.property.ListProperty;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
Expand All @@ -19,21 +20,23 @@
import javafx.scene.input.MouseEvent;
import javafx.scene.input.TransferMode;

import org.jabref.gui.Globals;
import org.jabref.gui.StateManager;
import org.jabref.gui.actions.ActionFactory;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.actions.StandardActions;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.preferences.AbstractPreferenceTabView;
import org.jabref.gui.preferences.PreferencesTab;
import org.jabref.gui.preview.PreviewViewer;
import org.jabref.gui.theme.ThemeManager;
import org.jabref.gui.util.BindingsHelper;
import org.jabref.gui.util.FileDialogConfiguration;
import org.jabref.gui.util.IconValidationDecorator;
import org.jabref.gui.util.ViewModelListCellFactory;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.preview.PreviewLayout;
import org.jabref.logic.util.StandardFileType;
import org.jabref.logic.util.TestEntry;
import org.jabref.model.database.BibDatabaseContext;

Expand Down Expand Up @@ -63,6 +66,7 @@ public class PreviewTab extends AbstractPreferenceTabView<PreviewTabViewModel> i

@Inject private StateManager stateManager;
@Inject private ThemeManager themeManager;
@Inject private KeyBindingRepository keyBindingRepository;

private final ContextMenu contextMenu = new ContextMenu();

Expand All @@ -89,10 +93,14 @@ public EditAction(StandardActions command) {
public void execute() {
if (editArea != null) {
switch (command) {
case COPY -> editArea.copy();
case CUT -> editArea.cut();
case PASTE -> editArea.paste();
case SELECT_ALL -> editArea.selectAll();
case COPY ->
editArea.copy();
case CUT ->
editArea.cut();
case PASTE ->
editArea.paste();
case SELECT_ALL ->
editArea.selectAll();
}
editArea.requestFocus();
}
Expand All @@ -104,6 +112,19 @@ public String getTabName() {
return Localization.lang("Entry preview");
}

@FXML
private void selectBstFile(ActionEvent event) {
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder()
.addExtensionFilter(StandardFileType.BST)
.withDefaultExtension(StandardFileType.BST)
.withInitialDirectory(preferencesService.getFilePreferences().getWorkingDirectory())
.build();

dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(bstFile -> {
viewModel.addBstStyle(bstFile);
});
}

public void initialize() {
this.viewModel = new PreviewTabViewModel(dialogService, preferencesService.getPreviewPreferences(), taskExecutor, stateManager);
lastKeyPressTime = System.currentTimeMillis();
Expand All @@ -114,7 +135,7 @@ public void initialize() {
searchBox.setPromptText(Localization.lang("Search") + "...");
searchBox.setLeft(IconTheme.JabRefIcons.SEARCH.getGraphicNode());

ActionFactory factory = new ActionFactory(Globals.getKeyPrefs());
ActionFactory factory = new ActionFactory(keyBindingRepository);
contextMenu.getItems().addAll(
factory.createMenuItem(StandardActions.CUT, new EditAction(StandardActions.CUT)),
factory.createMenuItem(StandardActions.COPY, new EditAction(StandardActions.COPY)),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jabref.gui.preferences.preview;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -33,6 +34,7 @@
import org.jabref.gui.util.CustomLocalDragboard;
import org.jabref.gui.util.NoSelectionModel;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.bst.BstPreviewLayout;
import org.jabref.logic.citationstyle.CitationStyle;
import org.jabref.logic.citationstyle.CitationStylePreviewLayout;
import org.jabref.logic.l10n.Localization;
Expand All @@ -52,11 +54,11 @@
/**
* This class is Preferences -> Entry Preview tab model
* <p>
* {@link PreviewTab} is the controller of Entry Preview tab
* {@link PreviewTab} is the controller of Entry Preview tab
* </p>
*
* @see PreviewTab
* */
*/
public class PreviewTabViewModel implements PreferenceTabViewModel {

private static final Logger LOGGER = LoggerFactory.getLogger(PreviewTabViewModel.class);
Expand All @@ -70,6 +72,8 @@ public class PreviewTabViewModel implements PreferenceTabViewModel {
private final ListProperty<PreviewLayout> chosenListProperty = new SimpleListProperty<>(FXCollections.observableArrayList());
private final ObjectProperty<MultipleSelectionModel<PreviewLayout>> chosenSelectionModelProperty = new SimpleObjectProperty<>(new NoSelectionModel<>());

private final ListProperty<Path> bstStylesPaths = new SimpleListProperty<>(FXCollections.observableArrayList());

private final BooleanProperty selectedIsEditableProperty = new SimpleBooleanProperty(false);
private final ObjectProperty<PreviewLayout> selectedLayoutProperty = new SimpleObjectProperty<>();
private final StringProperty sourceTextProperty = new SimpleStringProperty("");
Expand Down Expand Up @@ -103,10 +107,10 @@ public PreviewTabViewModel(DialogService dialogService,
chosenListProperty,
input -> !chosenListProperty.getValue().isEmpty(),
ValidationMessage.error("%s > %s %n %n %s".formatted(
Localization.lang("Entry preview"),
Localization.lang("Selected"),
Localization.lang("Selected Layouts can not be empty")
)
Localization.lang("Entry preview"),
Localization.lang("Selected"),
Localization.lang("Selected Layouts can not be empty")
)
)
);
}
Expand Down Expand Up @@ -135,6 +139,12 @@ public void setValues() {
dialogService.showErrorDialogAndWait(Localization.lang("Error adding discovered CitationStyles"), ex);
})
.executeWith(taskExecutor);
bstStylesPaths.clear();
bstStylesPaths.addAll(previewPreferences.getBstPreviewLayoutPaths());
bstStylesPaths.forEach(path -> {
BstPreviewLayout layout = new BstPreviewLayout(path);
availableListProperty.add(layout);
});
}

public void setPreviewLayout(PreviewLayout selectedLayout) {
Expand All @@ -153,13 +163,13 @@ public void setPreviewLayout(PreviewLayout selectedLayout) {
Localization.lang("Parsing error") + ": " + Localization.lang("illegal backslash expression"), exception);
}

if (selectedLayout instanceof TextBasedPreviewLayout layout) {
sourceTextProperty.setValue(layout.getText().replace("__NEWLINE__", "\n"));
selectedIsEditableProperty.setValue(true);
} else {
sourceTextProperty.setValue(((CitationStylePreviewLayout) selectedLayout).getSource());
selectedIsEditableProperty.setValue(false);
}
boolean isEditingAllowed = selectedLayout instanceof TextBasedPreviewLayout;
setContentForPreview(selectedLayout.getText(), isEditingAllowed);
}

private void setContentForPreview(String text, boolean editable) {
sourceTextProperty.setValue(text);
selectedIsEditableProperty.setValue(editable);
}

public void refreshPreview() {
Expand Down Expand Up @@ -194,10 +204,11 @@ public void storeSettings() {
previewPreferences.setShowPreviewAsExtraTab(showAsExtraTabProperty.getValue());
previewPreferences.setShowPreviewEntryTableTooltip(showPreviewInEntryTableTooltip.getValue());
previewPreferences.setCustomPreviewLayout((TextBasedPreviewLayout) customLayout);
previewPreferences.setBstPreviewLayoutPaths(bstStylesPaths);

if (!chosenSelectionModelProperty.getValue().getSelectedItems().isEmpty()) {
previewPreferences.setLayoutCyclePosition(chosenListProperty.getValue().indexOf(
chosenSelectionModelProperty.getValue().getSelectedItems().get(0)));
chosenSelectionModelProperty.getValue().getSelectedItems().getFirst()));
}
}

Expand Down Expand Up @@ -483,4 +494,11 @@ public ObjectProperty<PreviewLayout> selectedLayoutProperty() {
public StringProperty sourceTextProperty() {
return sourceTextProperty;
}

public void addBstStyle(Path bstFile) {
BstPreviewLayout bstPreviewLayout = new BstPreviewLayout(bstFile);
bstStylesPaths.add(bstFile);
availableListProperty().add(bstPreviewLayout);
chosenListProperty().add(bstPreviewLayout);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private List<String> generateCitations() throws IOException {
PreviewLayout previewLayout = preferencesService.getPreviewPreferences().getSelectedPreviewLayout();

if (previewLayout instanceof CitationStylePreviewLayout citationStyleLayout) {
styleSource = citationStyleLayout.getSource();
styleSource = citationStyleLayout.getText();
}

if (styleSource != null) {
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/org/jabref/logic/bst/BstEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ public class BstEntry {

public final BibEntry entry;

public final Map<String, String> localStrings = new HashMap<>();

// ENTRY: First sub list
public final Map<String, String> fields = new HashMap<>();

// ENTRY: Second sub list
public final Map<String, Integer> localIntegers = new HashMap<>();

// ENTRY: Third sub list
public final Map<String, String> localStrings = new HashMap<>();

public BstEntry(BibEntry e) {
this.entry = e;
}
Expand Down
Loading

0 comments on commit 707172b

Please sign in to comment.