Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
4d44da1
Functionality to modify title and header format
priyanshu16095 Mar 20, 2025
77a038e
Add CHANGELOG.md entry, rename Formats to Format and address the reviews
priyanshu16095 Mar 20, 2025
2cf8338
Merge branch 'main' into titleAndFormat
priyanshu16095 Mar 20, 2025
4c31d87
Fix typo in CHANGELOG.md entry
priyanshu16095 Mar 20, 2025
bbe688d
Rename variables
priyanshu16095 Mar 20, 2025
7ec30bb
Rename variable, remove two methods, fix check
priyanshu16095 Mar 20, 2025
e1f6f5c
Rename variables and fix the check
priyanshu16095 Mar 20, 2025
595adf2
Rename classes
priyanshu16095 Mar 20, 2025
9b62cab
Some minor changes
priyanshu16095 Mar 23, 2025
e3d0f64
Renamed variables
priyanshu16095 Mar 25, 2025
e0c4255
Rename variable
priyanshu16095 Mar 25, 2025
9b028db
Remove hardcoded value from constructor
priyanshu16095 Mar 25, 2025
18bcf95
Rename variable
priyanshu16095 Mar 25, 2025
267b141
Use CSLFormatUtils for title and format
priyanshu16095 Mar 25, 2025
9a3178a
Remove preference from constructor
priyanshu16095 Mar 25, 2025
9560346
Update JabRefCliPreferences.java
priyanshu16095 Mar 25, 2025
27c33af
Update JabRefCliPreferences.java
priyanshu16095 Mar 25, 2025
3fd34a4
Update ModifyCSLBibliographyTitleDialogViewModel.java
priyanshu16095 Mar 25, 2025
6a2777a
Update ModifyCSLBibliographyTitleDialogViewModel.java
priyanshu16095 Mar 25, 2025
2de2946
Remove static import
priyanshu16095 Mar 25, 2025
d2ad4c4
Merge branch 'titleAndFormat' of https://github.com/priyanshu16095/ja…
priyanshu16095 Mar 25, 2025
9d8dbe7
Remove DEFAULT from variable names
priyanshu16095 Mar 25, 2025
cd79816
Use getters
priyanshu16095 Mar 25, 2025
8df5f95
Remove unused methods
subhramit Mar 25, 2025
e93737b
Elaborate changelog entry
subhramit Mar 25, 2025
ebfac0c
Shorten changelog entry
subhramit Mar 25, 2025
fd754d4
Merge branch 'main' into titleAndFormat
subhramit Mar 25, 2025
4d3e4f4
Restore methods
priyanshu16095 Mar 25, 2025
ed85c2a
Merge branch 'titleAndFormat' of https://github.com/priyanshu16095/ja…
priyanshu16095 Mar 25, 2025
2e83e7e
Reduce use of `get()`, better naming for methods
subhramit Mar 25, 2025
7f5c9a6
Use correct function
subhramit Mar 25, 2025
f6f7ce9
Rename controller to view as per MVVM
subhramit Mar 25, 2025
d70deca
More renaming
subhramit Mar 25, 2025
a23ba66
Consistent naming in `CliPreferences`
subhramit Mar 25, 2025
461165a
Fix functionality
subhramit Mar 25, 2025
42d02bf
Tragbot comment - resolve architectural violation
subhramit Mar 25, 2025
0279333
Variable naming convention and Tragbot comment - resolve encapsulation
subhramit Mar 25, 2025
20212a1
Fix preferences
subhramit Mar 25, 2025
13555c5
Remove Heading from Format
priyanshu16095 Mar 26, 2025
cb89799
Merge branch 'titleAndFormat' of https://github.com/priyanshu16095/ja…
priyanshu16095 Mar 26, 2025
b507ba9
Merge branch 'main' into titleAndFormat
subhramit Mar 26, 2025
6d4fc2c
Update CHANGELOG.md
priyanshu16095 Mar 26, 2025
21f031c
Use localized strings
priyanshu16095 Mar 27, 2025
8f6f308
Merge branch 'titleAndFormat' of https://github.com/priyanshu16095/ja…
priyanshu16095 Mar 27, 2025
f1d28fa
Merge branch 'main' into titleAndFormat
subhramit Mar 27, 2025
d8cb06c
Fix preferences initialization pipeline
subhramit Mar 27, 2025
cb7fb06
Merge branch 'main' into titleAndFormat
subhramit Mar 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv

### Added

- In the Open/LibreOffice integration, we added the provision to modify the bibliography title and its format for CSL styles, in the "Select style" dialog. [#12663](https://github.com/JabRef/jabref/issues/12663)
- We added a new Welcome tab which shows a welcome screen if no database is open. [#12272](https://github.com/JabRef/jabref/issues/12272)
- We added <kbd>F5</kbd> as a shortcut key for fetching data and <kbd>Alt+F</kbd> as a shortcut for looking up data using DOI. [#11802](https://github.com/JabRef/jabref/issues/11802)
- We added a feature to rename the subgroup, with the keybinding (<kbd>F2</kbd>) for quick access. [#11896](https://github.com/JabRef/jabref/issues/11896)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.ButtonType?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.DialogPane?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.GridPane?>
<DialogPane xmlns:fx="http://javafx.com/fxml/1"
xmlns="http://javafx.com/javafx/8.0.121" fx:controller="org.jabref.gui.openoffice.ModifyCSLBibliographyTitleDialogView">
<content>
<GridPane hgap="10.0" vgap="4.0">
<Label text="%Bibliography title" GridPane.rowIndex="0" GridPane.columnIndex="0" />
<TextField fx:id="titleField" prefWidth="300.0" GridPane.rowIndex="0" GridPane.columnIndex="1" />
<Label text="%Header format" GridPane.rowIndex="1" GridPane.columnIndex="0" />
<ComboBox fx:id="formats" prefWidth="300.0" GridPane.rowIndex="1" GridPane.columnIndex="1" />
</GridPane>
</content>
<ButtonType fx:constant="OK"/>
</DialogPane>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.jabref.gui.openoffice;

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;
import javafx.stage.Modality;

import org.jabref.gui.util.BaseDialog;
import org.jabref.gui.util.ViewModelListCellFactory;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.openoffice.OpenOfficePreferences;

import com.airhacks.afterburner.views.ViewLoader;

public class ModifyCSLBibliographyTitleDialogView extends BaseDialog<Void> {

@FXML private TextField titleField;
@FXML private ComboBox<String> formats;

private final ModifyCSLBibliographyTitleDialogViewModel viewModel;

public ModifyCSLBibliographyTitleDialogView(OpenOfficePreferences openOfficePreferences) {
this.viewModel = new ModifyCSLBibliographyTitleDialogViewModel(openOfficePreferences);

this.setTitle(Localization.lang("Modify bibliography title"));
this.initModality(Modality.NONE);
this.setResizable(false);

ViewLoader.view(this)
.load()
.setAsDialogPane(this);

Button okButton = (Button) getDialogPane().lookupButton(ButtonType.OK);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why it should be looked up?

Can't it have an id and be used like @FXML private Button okButton?

Truly speaking, I haven't written dialogs in FXML. So maybe this is a common idiom?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has been a year for me as well since I have done JavaFX, but I only had some experience, so you are probably right. I also remember reading about the annotations in the docs - I can recall we follow it in JabRef.
@priyanshu16095 can you adjust using the fxml annotations and avoid the lookup? Just a small change, and would lead to neatness.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't it have an id and be used like @FXML private Button okButton?
Yeah I did this in the GUI for Consistency check feature.

Copy link
Copy Markdown
Contributor Author

@priyanshu16095 priyanshu16095 Mar 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FXML private Button okButton cannot be used on a ButtonType, as in JavaFX DialogPane manages the button internally.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah okay it won't work with the dialogpane, it's a standard added automatically as per the constant we specify in the fxml file (which was "CLOSE" before). you can leave this as it is then.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update (for learning) - lookupButton can be avoided by using setResultConverter, example as present in StyleSelectDialogView.

okButton.setOnAction(event -> {
viewModel.updateSettings();
this.close();
});
}

@FXML
public void initialize() {
titleField.textProperty().bindBidirectional(viewModel.cslBibliographyTitleProperty());

new ViewModelListCellFactory<String>()
.withText(format -> format)
.install(formats);
formats.itemsProperty().bind(viewModel.formatListProperty());
formats.valueProperty().bindBidirectional(viewModel.cslBibliographySelectedHeaderFormatProperty());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.jabref.gui.openoffice;

import java.util.Arrays;

import javafx.beans.property.ReadOnlyListProperty;
import javafx.beans.property.ReadOnlyListWrapper;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;

import org.jabref.logic.openoffice.OpenOfficePreferences;
import org.jabref.logic.openoffice.oocsltext.CSLFormatUtils;

public class ModifyCSLBibliographyTitleDialogViewModel {

private final StringProperty cslBibliographyTitle = new SimpleStringProperty();
private final StringProperty cslBibliographySelectedHeaderFormat = new SimpleStringProperty();
private final ReadOnlyListProperty<String> formatListProperty =
new ReadOnlyListWrapper<>(FXCollections.observableArrayList(
Arrays.stream(CSLFormatUtils.Format.values()).map(CSLFormatUtils.Format::getFormat).toList()
));
private final OpenOfficePreferences openOfficePreferences;

public ModifyCSLBibliographyTitleDialogViewModel(OpenOfficePreferences openOfficePreferences) {
this.openOfficePreferences = openOfficePreferences;
this.cslBibliographyTitle.set(openOfficePreferences.getCslBibliographyTitle());
this.cslBibliographySelectedHeaderFormat.set(openOfficePreferences.getCslBibliographyHeaderFormat());

cslBibliographyTitle.bindBidirectional(openOfficePreferences.cslBibliographyTitleProperty());
cslBibliographySelectedHeaderFormat.bindBidirectional(openOfficePreferences.cslBibliographyHeaderFormatProperty());
Comment on lines +29 to +30
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These direct bindings here are too sensitive - will capture and save updates regardless of whether a "save/ok" button is pressed, will be changing them in an upcoming PR.

}

public StringProperty cslBibliographyTitleProperty() {
return cslBibliographyTitle;
}

public StringProperty cslBibliographySelectedHeaderFormatProperty() {
return cslBibliographySelectedHeaderFormat;
}

public ReadOnlyListProperty<String> formatListProperty() {
return formatListProperty;
}

public void updateSettings() {
CSLFormatUtils.setBibliographyProperties(openOfficePreferences);
}
}
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/gui/openoffice/OOBibBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.jabref.logic.openoffice.frontend.OOFrontend;
import org.jabref.logic.openoffice.frontend.RangeForOverlapCheck;
import org.jabref.logic.openoffice.oocsltext.CSLCitationOOAdapter;
import org.jabref.logic.openoffice.oocsltext.CSLFormatUtils;
import org.jabref.logic.openoffice.oocsltext.CSLUpdateBibliography;
import org.jabref.logic.openoffice.style.JStyle;
import org.jabref.logic.openoffice.style.OOStyle;
Expand Down Expand Up @@ -94,6 +95,7 @@ private void initializeCitationAdapter(XTextDocument doc) throws WrappedTargetEx
OOStyle initialStyle = openOfficePreferences.getCurrentStyle(); // may be a jstyle, can still be used for detecting subsequent style changes in context of CSL
cslCitationOOAdapter = new CSLCitationOOAdapter(doc, databasesSupplier, initialStyle);
cslUpdateBibliography = new CSLUpdateBibliography();
CSLFormatUtils.setBibliographyProperties(openOfficePreferences);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The addition of this line in the initializeCitationAdapter method changes the method's behavior, but the JavaDoc for the method has not been updated to reflect this change, violating instruction 1.

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<Label text="%Preview" styleClass="sectionHeader"/>
<VBox fx:id="cslPreviewBox" prefHeight="300.0" spacing="4.0"/>
</VBox>
<Button text="%Modify bibliography title" alignment="CENTER_RIGHT" onAction="#modifyBibliographyTitle" />
</VBox>
</Tab>
<Tab text="JStyles">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ private ContextMenu createContextMenu() {
return contextMenu;
}

@FXML
private void modifyBibliographyTitle() {
ModifyCSLBibliographyTitleDialogView modifyBibliographyTitleDialogView = new ModifyCSLBibliographyTitleDialogView(preferences.getOpenOfficePreferences());
dialogService.showCustomDialog(modifyBibliographyTitleDialogView);
}

@FXML
private void addStyleFile() {
viewModel.addStyleFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,27 @@ public class OpenOfficePreferences {
private final StringProperty currentJStyle;
private final ObjectProperty<OOStyle> currentStyle;
private final BooleanProperty alwaysAddCitedOnPages;
private final StringProperty cslBibliographyTitle;
private final StringProperty cslBibliographyHeaderFormat;

public OpenOfficePreferences(String executablePath,
boolean useAllDatabases,
boolean syncWhenCiting,
List<String> externalStyles,
String currentJStyle,
OOStyle currentStyle,
boolean alwaysAddCitedOnPages) {
boolean alwaysAddCitedOnPages,
String cslBibliographyTitle,
String cslBibliographyHeaderFormat) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is cslBibliographyHeaderFormat limited to values in CSLFormatUtils#Format?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

this.executablePath = new SimpleStringProperty(executablePath);
this.useAllDatabases = new SimpleBooleanProperty(useAllDatabases);
this.syncWhenCiting = new SimpleBooleanProperty(syncWhenCiting);
this.externalStyles = FXCollections.observableArrayList(externalStyles);
this.currentJStyle = new SimpleStringProperty(currentJStyle);
this.currentStyle = new SimpleObjectProperty<>(currentStyle);
this.alwaysAddCitedOnPages = new SimpleBooleanProperty(alwaysAddCitedOnPages);
this.cslBibliographyTitle = new SimpleStringProperty(cslBibliographyTitle);
this.cslBibliographyHeaderFormat = new SimpleStringProperty(cslBibliographyHeaderFormat);
}

public void clearConnectionSettings() {
Expand Down Expand Up @@ -152,4 +158,20 @@ public BooleanProperty alwaysAddCitedOnPagesProperty() {
public void setAlwaysAddCitedOnPages(boolean alwaysAddCitedOnPages) {
this.alwaysAddCitedOnPages.set(alwaysAddCitedOnPages);
}

public StringProperty cslBibliographyTitleProperty() {
return cslBibliographyTitle;
}

public String getCslBibliographyTitle() {
return cslBibliographyTitle.get();
}

public StringProperty cslBibliographyHeaderFormatProperty() {
return cslBibliographyHeaderFormat;
}

public String getCslBibliographyHeaderFormat() {
return cslBibliographyHeaderFormat.get();
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No set methods? Typically we write 3 method for each option

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had the same doubt - but there was no use for setters in this case as only bidirectional bindings were used to sync their values.
No strong opinions about having unused methods - but as a good practice (or possible future extensions), we can add them.

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public CSLCitationOOAdapter(XTextDocument doc, Supplier<List<BibDatabaseContext>
this.document = doc;
this.markManager = new CSLReferenceMarkManager(doc);
this.databasesSupplier = databasesSupplier;

if (initialStyle instanceof CitationStyle citationStyle) {
this.currentStyle = citationStyle; // else the currentStyle purposely stays null, still causing a difference with the subsequent style if CSL (valid comparison)
}
Expand Down Expand Up @@ -176,7 +177,7 @@ public void insertBibliography(XTextCursor cursor, CitationStyle selectedStyle,
throws WrappedTargetException, CreationException {
boolean isNumericStyle = selectedStyle.isNumericStyle();

OOText title = OOFormat.paragraph(OOText.fromString(CSLFormatUtils.DEFAULT_BIBLIOGRAPHY_TITLE), CSLFormatUtils.DEFAULT_BIBLIOGRAPHY_HEADER_PARAGRAPH_FORMAT);
OOText title = OOFormat.paragraph(OOText.fromString(CSLFormatUtils.getBibliographyTitle()), CSLFormatUtils.getBibliographyHeaderFormat());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said in some other comment.

Why not use these values from preferences (OpenOfficePreferences)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Answered in #12784 (comment).

OOTextIntoOO.write(document, cursor, OOText.fromString(title.toString()));
OOText ooBreak = OOFormat.paragraph(OOText.fromString(""), CSLFormatUtils.DEFAULT_BIBLIOGRAPHY_BODY_PARAGRAPH_FORMAT);
OOTextIntoOO.write(document, cursor, ooBreak);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import org.jabref.logic.citationkeypattern.BracketedPattern;
import org.jabref.logic.citationstyle.CitationStyleOutputFormat;
import org.jabref.logic.openoffice.OpenOfficePreferences;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.AuthorList;
import org.jabref.model.entry.BibEntry;
Expand All @@ -25,15 +26,48 @@
*/
public class CSLFormatUtils {

// TODO: These are static final fields right now, should add the functionality to let user select these and store them in preferences.
public static final String DEFAULT_BIBLIOGRAPHY_TITLE = "References";
public static final String DEFAULT_BIBLIOGRAPHY_HEADER_PARAGRAPH_FORMAT = "Heading 2";
public enum Format {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For which purpose this enum is used?

I think styles can be chosen from this enum, but not limited to. Thus, I think a comment would look good here

Copy link
Copy Markdown
Contributor Author

@priyanshu16095 priyanshu16095 Mar 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enum was initially used to pop up the dropdown list, as used in the codebase, to maintain consistency with existing practices.
Should a text field also be present for providing a custom format?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A simple list could be used too. An enum just seemed cleaner, and enums are generally used to denote "options" - so I didn't complain.

Copy link
Copy Markdown
Member

@subhramit subhramit Mar 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@priyanshu16095 As @InAnYan suggested, in future if we let user enter their own text format, we will have to go out of this enum - but that will be some more work - and would need validation for being a valid format, otherwise error to user (else LO writing infrastructure will bleed), etc.
If we have to validate against a set of valid values anyway, we can keep adding to the enum directly instead (if we wish to offer more options to the user).
For now, in the context of this PR, I am fine with these many, and fine with the enum in general.

TITLE("Title"),
BODY_TEXT("Body Text"),
SUBTITLE("Subtitle"),
HEADING_1("Heading 1"),
HEADING_2("Heading 2"),
HEADING_3("Heading 3"),
HEADING_4("Heading 4");

public static final String DEFAULT_BIBLIOGRAPHY_BODY_PARAGRAPH_FORMAT = "Body Text";
private final String format;

Format(String format) {
this.format = format;
}

public String getFormat() {
return format;
}
}

public static final CitationStyleOutputFormat OUTPUT_FORMAT = CitationStyleOutputFormat.HTML;

public static final String DEFAULT_BIBLIOGRAPHY_BODY_PARAGRAPH_FORMAT = "Body Text";

private static String bibliographyTitle;
private static String bibliographyHeaderFormat;

private static final Pattern YEAR_IN_CITATION_PATTERN = Pattern.compile("(.)(.*), (\\d{4}.*)");

public static String getBibliographyTitle() {
return bibliographyTitle;
}

public static String getBibliographyHeaderFormat() {
return bibliographyHeaderFormat;
}

public static void setBibliographyProperties(OpenOfficePreferences openOfficePreferences) {
bibliographyTitle = openOfficePreferences.getCslBibliographyTitle();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not how we do it in JabRef.

Why would you need to store these values in a static class?

If someone needed to use cslBibliographyTitle or other values, then class should import and use OpenOfficePreferences directly, isn't it?

Copy link
Copy Markdown
Member

@subhramit subhramit Mar 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a tricky one. The thing is - the values of these preferences are being taken and set from the UI.
Then being used in the CSLCitationOOAdapter. That is indeed the obvious part. Valid question - why not directly use the preference then?

Here is some history for context:
The design of JStyles was really bad - everything including preferences, options, upstream setting of preferences, insertion point for LibreOffice instance - is stuffed together in OOBibBase.
So when coming up with the design for CSL, I wanted to have a logical separation.

This class CSLCitationOOAdapter was initially intended to only be an adapter, with every property relevant/required for a current interaction with LibreOffice document being injected directly via the methods, with no role of preferences in the layer whatsoever. Latest sync of style type, style name etc everything would be determined from preferences latest at OOBibBase, and then passed here as needed.

I had to break the design when introducing Real time style switching just to have the last used style for comparison (if a CSL style):

if (openOfficePreferences.getCurrentStyle() instanceof CitationStyle citationStyle) {
            this.currentStyle = citationStyle;
        }

All other subsequent comparisions are done by storing state in the adapter itself. Now that you point it out, I realize that the preferences there could be cleaned up completely by passing the initial style instead of openOfficePreferences via the constructor.

Like OOBibBase dealing with preferences and being the linking class between the UI layer and the adapter (logic layer), I had the same thought when putting the extraction of bibliography titles and formats, and did not want an instance of the preferences dependent on an instance of the adapter - when both already meet at a common point up in the hierarchy - OOBibBase .

In this case I made CSLFormatUtils the linking class, as everything related to the formatting of CSL was done there. We could also have similarly passed it using OOBibBase - but that would not allow direct static access - so another idea (as I can think of right now) could be passing them to CSLUpdateBibliography whenever a call for bibliography generation is made. (The design for the bibliography part seems confusing right now as I am checking while I type this, and can be improved a lot).

Preferable - either break the design completely and directly use preferences in the adapter (as you suggest), or remove preferences completely from the adapter and do the same for these properties (seems weird, and you are right to question that this is not how we do it in JabRef - and that is because no other component in JabRef (that I know of) needs to interact with a continued running instance of an external application (in my knowledge), and thus doesn't need an adapter. I introduced it.

Edit - I just realized this should go into an ADR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@InAnYan thought a lot over it, you're right.

Short summary of original intent: 1. To be able to use these preferences statically without injection of openOfficePreferences 2. To avoid dependency of the adapter on preferences.
Outcome: CSLStyleUtils became dependent on openOfficePreferences instead. A utility class (as far as possible) should not be dependent on preferences. Also caused unnecessary links between the classes introduced in this PR and the Utils class.

Hence, I shift this to use them from openOfficePreferences directly in the adapter in #12996.
Cherry on the top: Another preference was already indirectly being used there (initialStyle) via abstraction through OOBibBase, so that could also be unified with these by passing the entire oo prefs.

bibliographyHeaderFormat = openOfficePreferences.getCslBibliographyHeaderFormat();
}
Comment on lines +66 to +69
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method lacks JavaDoc documentation despite being a public API that manages important state. The method's behavior and side effects should be clearly documented.


/**
* Transforms provided HTML into a format that can be fully parsed and inserted into an OO document.
* Context: The HTML produced by {@link org.jabref.logic.citationstyle.CitationStyleGenerator#generateBibliography(List, String, CitationStyleOutputFormat, BibDatabaseContext, BibEntryTypesManager) generateBibliography} or {@link org.jabref.logic.citationstyle.CitationStyleGenerator#generateCitation(List, String, CitationStyleOutputFormat, BibDatabaseContext, BibEntryTypesManager) generateCitation} is not directly (completely) parsable by {@link OOTextIntoOO#write(XTextDocument, XTextCursor, OOText) write}.
Expand Down Expand Up @@ -124,9 +158,9 @@ public static String generateAlphanumericInTextCitation(BibEntry entry, BibDatab
String inTextCitation = generateAlphanumericCitation(List.of(entry), bibDatabaseContext);

String authorName = entry.getResolvedFieldOrAlias(StandardField.AUTHOR, bibDatabaseContext.getDatabase())
.map(AuthorList::parse)
.map(list -> BracketedPattern.joinAuthorsOnLastName(list, 1, "", " et al."))
.orElse("");
.map(AuthorList::parse)
.map(list -> BracketedPattern.joinAuthorsOnLastName(list, 1, "", " et al."))
.orElse("");

return authorName + " " + inTextCitation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ public class JabRefCliPreferences implements CliPreferences {
public static final String OO_EXTERNAL_STYLE_FILES = "ooExternalStyleFiles";
public static final String OO_CURRENT_STYLE = "ooCurrentStyle";
public static final String OO_ALWAYS_ADD_CITED_ON_PAGES = "ooAlwaysAddCitedOnPages";
public static final String OO_CSL_BIBLIOGRAPHY_TITLE = "cslBibliographyTitle";
public static final String OO_CSL_BIBLIOGRAPHY_HEADER_FORMAT = "cslBibliographyHeaderFormat";

// Prefs node for CitationKeyPatterns
public static final String CITATION_KEY_PATTERNS_NODE = "bibtexkeypatterns";
Expand Down Expand Up @@ -565,6 +567,8 @@ protected JabRefCliPreferences() {
defaults.put(OO_BIBLIOGRAPHY_STYLE_FILE, StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH);
defaults.put(OO_EXTERNAL_STYLE_FILES, "");
defaults.put(OO_CURRENT_STYLE, CitationStyle.getDefault().getPath()); // Default CSL Style is IEEE
defaults.put(OO_CSL_BIBLIOGRAPHY_TITLE, "References");
defaults.put(OO_CSL_BIBLIOGRAPHY_HEADER_FORMAT, "Heading 2");

defaults.put(FETCHER_CUSTOM_KEY_NAMES, "Springer;IEEEXplore;SAO/NASA ADS;ScienceDirect;Biodiversity Heritage");
defaults.put(FETCHER_CUSTOM_KEY_USES, "FALSE;FALSE;FALSE;FALSE;FALSE");
Expand Down Expand Up @@ -1128,7 +1132,9 @@ public OpenOfficePreferences getOpenOfficePreferences() {
getStringList(OO_EXTERNAL_STYLE_FILES),
get(OO_BIBLIOGRAPHY_STYLE_FILE),
currentStyle,
getBoolean(OO_ALWAYS_ADD_CITED_ON_PAGES));
getBoolean(OO_ALWAYS_ADD_CITED_ON_PAGES),
get(OO_CSL_BIBLIOGRAPHY_TITLE),
get(OO_CSL_BIBLIOGRAPHY_HEADER_FORMAT));

EasyBind.listen(openOfficePreferences.executablePathProperty(), (obs, oldValue, newValue) -> put(OO_EXECUTABLE_PATH, newValue));
EasyBind.listen(openOfficePreferences.useAllDatabasesProperty(), (obs, oldValue, newValue) -> putBoolean(OO_USE_ALL_OPEN_BASES, newValue));
Expand All @@ -1140,6 +1146,9 @@ public OpenOfficePreferences getOpenOfficePreferences() {
EasyBind.listen(openOfficePreferences.currentJStyleProperty(), (obs, oldValue, newValue) -> put(OO_BIBLIOGRAPHY_STYLE_FILE, newValue));
EasyBind.listen(openOfficePreferences.currentStyleProperty(), (obs, oldValue, newValue) -> put(OO_CURRENT_STYLE, newValue.getPath()));

EasyBind.listen(openOfficePreferences.cslBibliographyTitleProperty(), (obs, oldValue, newValue) -> put(OO_CSL_BIBLIOGRAPHY_TITLE, newValue));
EasyBind.listen(openOfficePreferences.cslBibliographyHeaderFormatProperty(), (obs, oldValue, newValue) -> put(OO_CSL_BIBLIOGRAPHY_HEADER_FORMAT, newValue));

return openOfficePreferences;
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2852,6 +2852,9 @@ Currently\ set\ style\:=Currently set style:
Currently\ selected\ JStyle\:\ '%0'=Currently selected JStyle: '%0'
Currently\ selected\ CSL\ Style\:\ '%0'=Currently selected CSL Style: '%0'
Store\ url\ for\ downloaded\ file=Store url for downloaded file
Modify\ bibliography\ title=Modify bibliography title
Bibliography\ title=Bibliography title
Header\ format=Header format

Compare\ with\ existing\ entry=Compare with existing entry
Library\ Entry=Library Entry
Expand Down