Skip to content

Add support for LibreOffice's default bibliography styles #13050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv

### Changed

- Added support for selecting bibliography heading and body text styles in LibreOffice integration. The heading now uses "Bibliography Heading" by default and body text uses "Bibliography 1" by default, matching LibreOffice's default styles. [#12784](https://github.com/JabRef/jabref/issues/12784)
- Added "Text body" as an additional style option for bibliography entries in LibreOffice integration. [#12784](https://github.com/JabRef/jabref/issues/12784)
- We merged the 'New Entry', 'Import by ID', and 'New Entry from Plain Text' tools into a single 'Create New Entry' tool. [#8808](https://github.com/JabRef/jabref/issues/8808)

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
public class ModifyCSLBibliographyTitleDialogView extends BaseDialog<Void> {

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

private final ModifyCSLBibliographyTitleDialogViewModel viewModel;

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

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

Expand All @@ -44,8 +45,14 @@ public void initialize() {

new ViewModelListCellFactory<String>()
.withText(format -> format)
.install(formats);
formats.itemsProperty().bind(viewModel.formatListProperty());
formats.valueProperty().bindBidirectional(viewModel.cslBibliographySelectedHeaderFormatProperty());
.install(headerFormats);
headerFormats.itemsProperty().bind(viewModel.formatListProperty());
headerFormats.valueProperty().bindBidirectional(viewModel.cslBibliographySelectedHeaderFormatProperty());

new ViewModelListCellFactory<String>()
.withText(format -> format)
.install(bodyFormats);
bodyFormats.itemsProperty().bind(viewModel.formatListProperty());
bodyFormats.valueProperty().bindBidirectional(viewModel.cslBibliographySelectedBodyFormatProperty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class ModifyCSLBibliographyTitleDialogViewModel {

private final StringProperty cslBibliographyTitle = new SimpleStringProperty();
private final StringProperty cslBibliographySelectedHeaderFormat = new SimpleStringProperty();
private final StringProperty cslBibliographySelectedBodyFormat = new SimpleStringProperty();
private final ReadOnlyListProperty<String> formatListProperty =
new ReadOnlyListWrapper<>(FXCollections.observableArrayList(
Arrays.stream(CSLFormatUtils.Format.values()).map(CSLFormatUtils.Format::getFormat).toList()
Expand All @@ -23,9 +24,11 @@ public class ModifyCSLBibliographyTitleDialogViewModel {
public ModifyCSLBibliographyTitleDialogViewModel(OpenOfficePreferences openOfficePreferences) {
this.cslBibliographyTitle.set(openOfficePreferences.getCslBibliographyTitle());
this.cslBibliographySelectedHeaderFormat.set(openOfficePreferences.getCslBibliographyHeaderFormat());
this.cslBibliographySelectedBodyFormat.set(openOfficePreferences.getCslBibliographyBodyFormat());

cslBibliographyTitle.bindBidirectional(openOfficePreferences.cslBibliographyTitleProperty());
cslBibliographySelectedHeaderFormat.bindBidirectional(openOfficePreferences.cslBibliographyHeaderFormatProperty());
cslBibliographySelectedBodyFormat.bindBidirectional(openOfficePreferences.cslBibliographyBodyFormatProperty());
}

public StringProperty cslBibliographyTitleProperty() {
Expand All @@ -36,6 +39,10 @@ public StringProperty cslBibliographySelectedHeaderFormatProperty() {
return cslBibliographySelectedHeaderFormat;
}

public StringProperty cslBibliographySelectedBodyFormatProperty() {
return cslBibliographySelectedBodyFormat;
}

public ReadOnlyListProperty<String> formatListProperty() {
return formatListProperty;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
<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" />
<ComboBox fx:id="headerFormats" prefWidth="300.0" GridPane.rowIndex="1" GridPane.columnIndex="1" />
<Label text="%Body format" GridPane.rowIndex="2" GridPane.columnIndex="0" />
<ComboBox fx:id="bodyFormats" prefWidth="300.0" GridPane.rowIndex="2" GridPane.columnIndex="1" />
</GridPane>
</content>
<ButtonType fx:constant="OK"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

import org.jabref.logic.openoffice.oocsltext.CSLFormatUtils;
import org.jabref.logic.openoffice.style.OOStyle;

public class OpenOfficePreferences {
Expand All @@ -34,6 +35,7 @@ public class OpenOfficePreferences {
private final BooleanProperty alwaysAddCitedOnPages;
private final StringProperty cslBibliographyTitle;
private final StringProperty cslBibliographyHeaderFormat;
private final StringProperty cslBibliographyBodyFormat;
private final ObservableList<String> externalCslStyles;

public OpenOfficePreferences(String executablePath,
Expand All @@ -45,6 +47,7 @@ public OpenOfficePreferences(String executablePath,
boolean alwaysAddCitedOnPages,
String cslBibliographyTitle,
String cslBibliographyHeaderFormat,
String cslBibliographyBodyFormat,
List<String> externalCslStyles) {
this.executablePath = new SimpleStringProperty(executablePath);
this.useAllDatabases = new SimpleBooleanProperty(useAllDatabases);
Expand All @@ -55,6 +58,9 @@ public OpenOfficePreferences(String executablePath,
this.alwaysAddCitedOnPages = new SimpleBooleanProperty(alwaysAddCitedOnPages);
this.cslBibliographyTitle = new SimpleStringProperty(cslBibliographyTitle);
this.cslBibliographyHeaderFormat = new SimpleStringProperty(cslBibliographyHeaderFormat);
this.cslBibliographyBodyFormat = new SimpleStringProperty(cslBibliographyBodyFormat != null ?
cslBibliographyBodyFormat :
CSLFormatUtils.DEFAULT_BIBLIOGRAPHY_BODY_PARAGRAPH_FORMAT);
this.externalCslStyles = FXCollections.observableArrayList(externalCslStyles);
}

Expand Down Expand Up @@ -178,6 +184,19 @@ public String getCslBibliographyHeaderFormat() {
return cslBibliographyHeaderFormat.get();
}

public StringProperty cslBibliographyBodyFormatProperty() {
return cslBibliographyBodyFormat;
}

public String getCslBibliographyBodyFormat() {
String format = cslBibliographyBodyFormat.get();
return format != null ? format : CSLFormatUtils.DEFAULT_BIBLIOGRAPHY_BODY_PARAGRAPH_FORMAT;
}

public void setCslBibliographyBodyFormat(String format) {
this.cslBibliographyBodyFormat.set(format);
}

public ObservableList<String> getExternalCslStyles() {
return externalCslStyles;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void insertBibliography(XTextCursor cursor, CitationStyle selectedStyle,

OOText title = OOFormat.paragraph(OOText.fromString(openOfficePreferences.getCslBibliographyTitle()), openOfficePreferences.getCslBibliographyHeaderFormat());
OOTextIntoOO.write(document, cursor, OOText.fromString(title.toString()));
OOText ooBreak = OOFormat.paragraph(OOText.fromString(""), CSLFormatUtils.DEFAULT_BIBLIOGRAPHY_BODY_PARAGRAPH_FORMAT);
OOText ooBreak = OOFormat.paragraph(OOText.fromString(""), openOfficePreferences.getCslBibliographyBodyFormat());
OOTextIntoOO.write(document, cursor, ooBreak);

String style = selectedStyle.getSource();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public enum Format {
HEADING_1("Heading 1"),
HEADING_2("Heading 2"),
HEADING_3("Heading 3"),
HEADING_4("Heading 4");
HEADING_4("Heading 4"),
BIBLIOGRAPHY_HEADING("Bibliography Heading"),
BIBLIOGRAPHY_1("Bibliography 1"),
TEXT_BODY("Text body");
Comment on lines +35 to +38
Copy link
Member

Choose a reason for hiding this comment

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

Did you read the issue properly? Did you understand the difference between formatting of the bibliography header and the bibliography text?


private final String format;

Expand All @@ -45,7 +48,7 @@ public String getFormat() {
}
}

public static final String DEFAULT_BIBLIOGRAPHY_BODY_PARAGRAPH_FORMAT = "Body Text";
public static final String DEFAULT_BIBLIOGRAPHY_BODY_PARAGRAPH_FORMAT = "Bibliography 1";

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ public class JabRefCliPreferences implements CliPreferences {
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";
public static final String OO_CSL_BIBLIOGRAPHY_BODY_FORMAT = "cslBibliographyBodyFormat";

// Prefs node for CitationKeyPatterns
public static final String CITATION_KEY_PATTERNS_NODE = "bibtexkeypatterns";
Expand Down Expand Up @@ -573,7 +574,8 @@ protected JabRefCliPreferences() {
defaults.put(OO_EXTERNAL_STYLE_FILES, "");
defaults.put(OO_CURRENT_STYLE, CSLStyleLoader.getDefaultStyle().getPath()); // Default CSL Style is IEEE
defaults.put(OO_CSL_BIBLIOGRAPHY_TITLE, "References");
defaults.put(OO_CSL_BIBLIOGRAPHY_HEADER_FORMAT, "Heading 2");
defaults.put(OO_CSL_BIBLIOGRAPHY_HEADER_FORMAT, "Bibliography Heading");
defaults.put(OO_CSL_BIBLIOGRAPHY_BODY_FORMAT, "Bibliography 1");
defaults.put(OO_EXTERNAL_CSL_STYLES, "");

defaults.put(FETCHER_CUSTOM_KEY_NAMES, "Springer;IEEEXplore;SAO/NASA ADS;ScienceDirect;Biodiversity Heritage");
Expand Down Expand Up @@ -2243,6 +2245,7 @@ public OpenOfficePreferences getOpenOfficePreferences(JournalAbbreviationReposit
getBoolean(OO_ALWAYS_ADD_CITED_ON_PAGES),
get(OO_CSL_BIBLIOGRAPHY_TITLE),
get(OO_CSL_BIBLIOGRAPHY_HEADER_FORMAT),
get(OO_CSL_BIBLIOGRAPHY_BODY_FORMAT),
getStringList(OO_EXTERNAL_CSL_STYLES));

EasyBind.listen(openOfficePreferences.executablePathProperty(), (obs, oldValue, newValue) -> put(OO_EXECUTABLE_PATH, newValue));
Expand All @@ -2259,6 +2262,7 @@ public OpenOfficePreferences getOpenOfficePreferences(JournalAbbreviationReposit

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));
EasyBind.listen(openOfficePreferences.cslBibliographyBodyFormatProperty(), (obs, oldValue, newValue) -> put(OO_CSL_BIBLIOGRAPHY_BODY_FORMAT, newValue));

return openOfficePreferences;
}
Expand Down
3 changes: 2 additions & 1 deletion jablib/src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2848,7 +2848,8 @@ Warning\:\ The\ selected\ directory\ is\ not\ a\ valid\ directory.=Warning: The
Store\ url\ for\ downloaded\ file=Store url for downloaded file
Modify\ bibliography\ title=Modify bibliography title
Bibliography\ title=Bibliography title
Header\ format=Header format
Body\ format=Body format
Modify\ bibliography\ properties=Modify bibliography properties

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