Skip to content

Commit 818436d

Browse files
committed
Merge remote-tracking branch 'upstream/main' into feature/journal-abbreviation-toggle
2 parents a57193f + 95dcbe6 commit 818436d

22 files changed

+386
-281
lines changed

.github/ghprcomment.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,13 @@
8888
- jobName: no-force-push
8989
always: true
9090
message: >
91-
Do not force-push!
92-
Force pushing is a very bad practice when working together on a project (mainly because it is [not supported well by GitHub itself](https://github.com/orgs/community/discussions/3478)).
91+
Hey, we noticed that you **force-pushed** your changes.
92+
Force pushing is a bad practice when working together on a project (mainly because it is [not supported well by GitHub itself](https://github.com/orgs/community/discussions/3478)).
9393
Commits are lost and comments on commits lose their context, thus making it harder to review changes.
9494
At the end, all commits will be [squashed](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/incorporating-changes-from-a-pull-request/about-pull-request-merges#squash-and-merge-your-commits) anyway before being merged into the `main` branch.
95+
96+
97+
In future, **please avoid that**. For now, you can continue working.
9598
- jobName: 'Conflicts with target branch'
9699
message: >
97100
Your pull request conflicts with the target branch.

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
3737
- We added path validation to file directories in library properties dialog. [#11840](https://github.com/JabRef/jabref/issues/11840)
3838
- We now support usage of custom CSL styles in the Open/LibreOffice integration. [#12337](https://github.com/JabRef/jabref/issues/12337)
3939
- We added ability to toggle journal abbreviation lists (including built-in and external CSV files) on/off in preferences. [#12468](https://github.com/JabRef/jabref/pull/12468)
40+
- We added support for citation-only CSL styles which don't specify bibliography formatting. [#12996](https://github.com/JabRef/jabref/pull/12996)
4041

4142
### Changed
4243

src/main/java/org/jabref/gui/openoffice/ModifyCSLBibliographyTitleDialogView.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ public ModifyCSLBibliographyTitleDialogView(OpenOfficePreferences openOfficePref
3333
.setAsDialogPane(this);
3434

3535
Button okButton = (Button) getDialogPane().lookupButton(ButtonType.OK);
36-
okButton.setOnAction(event -> {
37-
viewModel.updateSettings();
36+
okButton.setOnAction(_ -> {
3837
this.close();
3938
});
4039
}

src/main/java/org/jabref/gui/openoffice/ModifyCSLBibliographyTitleDialogViewModel.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ public class ModifyCSLBibliographyTitleDialogViewModel {
1919
new ReadOnlyListWrapper<>(FXCollections.observableArrayList(
2020
Arrays.stream(CSLFormatUtils.Format.values()).map(CSLFormatUtils.Format::getFormat).toList()
2121
));
22-
private final OpenOfficePreferences openOfficePreferences;
2322

2423
public ModifyCSLBibliographyTitleDialogViewModel(OpenOfficePreferences openOfficePreferences) {
25-
this.openOfficePreferences = openOfficePreferences;
2624
this.cslBibliographyTitle.set(openOfficePreferences.getCslBibliographyTitle());
2725
this.cslBibliographySelectedHeaderFormat.set(openOfficePreferences.getCslBibliographyHeaderFormat());
2826

@@ -41,8 +39,4 @@ public StringProperty cslBibliographySelectedHeaderFormatProperty() {
4139
public ReadOnlyListProperty<String> formatListProperty() {
4240
return formatListProperty;
4341
}
44-
45-
public void updateSettings() {
46-
CSLFormatUtils.setBibliographyProperties(openOfficePreferences);
47-
}
4842
}

src/main/java/org/jabref/gui/openoffice/OOBibBase.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.jabref.gui.openoffice;
22

3-
import java.io.IOException;
43
import java.nio.file.Path;
54
import java.util.ArrayList;
65
import java.util.Arrays;
@@ -26,7 +25,6 @@
2625
import org.jabref.logic.openoffice.frontend.OOFrontend;
2726
import org.jabref.logic.openoffice.frontend.RangeForOverlapCheck;
2827
import org.jabref.logic.openoffice.oocsltext.CSLCitationOOAdapter;
29-
import org.jabref.logic.openoffice.oocsltext.CSLFormatUtils;
3028
import org.jabref.logic.openoffice.oocsltext.CSLUpdateBibliography;
3129
import org.jabref.logic.openoffice.style.JStyle;
3230
import org.jabref.logic.openoffice.style.OOStyle;
@@ -73,11 +71,11 @@ public class OOBibBase {
7371

7472
private final OOBibBaseConnect connection;
7573

74+
private final OpenOfficePreferences openOfficePreferences;
75+
7676
private CSLCitationOOAdapter cslCitationOOAdapter;
7777
private CSLUpdateBibliography cslUpdateBibliography;
7878

79-
private OpenOfficePreferences openOfficePreferences;
80-
8179
public OOBibBase(Path loPath, DialogService dialogService, OpenOfficePreferences openOfficePreferences)
8280
throws
8381
BootstrapException,
@@ -92,10 +90,8 @@ private void initializeCitationAdapter(XTextDocument doc) throws WrappedTargetEx
9290
if (cslCitationOOAdapter == null) {
9391
StateManager stateManager = Injector.instantiateModelOrService(StateManager.class);
9492
Supplier<List<BibDatabaseContext>> databasesSupplier = stateManager::getOpenDatabases;
95-
OOStyle initialStyle = openOfficePreferences.getCurrentStyle(); // may be a jstyle, can still be used for detecting subsequent style changes in context of CSL
96-
cslCitationOOAdapter = new CSLCitationOOAdapter(doc, databasesSupplier, initialStyle);
93+
cslCitationOOAdapter = new CSLCitationOOAdapter(doc, databasesSupplier, openOfficePreferences);
9794
cslUpdateBibliography = new CSLUpdateBibliography();
98-
CSLFormatUtils.setBibliographyProperties(openOfficePreferences);
9995
}
10096
}
10197

@@ -614,7 +610,9 @@ public void guiActionInsertEntry(List<BibEntry> entries,
614610
}
615611

616612
// If "Automatically sync bibliography when inserting citations" is enabled
617-
syncOptions.ifPresent(options -> guiActionUpdateDocument(options.databases, citationStyle));
613+
if (citationStyle.hasBibliography()) {
614+
syncOptions.ifPresent(options -> guiActionUpdateDocument(options.databases, citationStyle));
615+
}
618616
} finally {
619617
// Release controller lock
620618
doc.unlockControllers();
@@ -641,7 +639,6 @@ public void guiActionInsertEntry(List<BibEntry> entries,
641639
OOError.from(ex).setTitle(errorTitle).showErrorDialog(dialogService);
642640
} catch (CreationException
643641
| WrappedTargetException
644-
| IOException
645642
| PropertyVetoException
646643
| IllegalTypeException
647644
| NotRemoveableException ex) {
@@ -900,8 +897,10 @@ public void guiActionUpdateDocument(List<BibDatabase> databases, OOStyle style)
900897
OOError.fromMisc(ex).setTitle(errorTitle).showErrorDialog(dialogService);
901898
}
902899
} else if (style instanceof CitationStyle citationStyle) {
900+
if (!citationStyle.hasBibliography()) {
901+
return;
902+
}
903903
try {
904-
905904
OOResult<XTextDocument, OOError> odoc = getXTextDocument();
906905
if (testDialog(errorTitle, odoc.asVoidResult())) {
907906
return;

src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ private void updateButtonAvailability() {
417417
boolean canCite = isConnectedToDocument && hasStyle && hasDatabase;
418418
boolean canRefreshDocument = isConnectedToDocument && hasStyle;
419419
boolean cslStyleSelected = currentStyle instanceof CitationStyle;
420+
boolean canGenerateBibliography = currentStyle instanceof CitationStyle citationStyle && citationStyle.hasBibliography();
420421

421422
selectDocument.setDisable(!isConnectedToDocument);
422423

@@ -425,7 +426,7 @@ private void updateButtonAvailability() {
425426
pushEntriesEmpty.setDisable(!canCite);
426427
pushEntriesAdvanced.setDisable(!canCite || cslStyleSelected);
427428

428-
update.setDisable(!canRefreshDocument);
429+
update.setDisable(!canRefreshDocument || !canGenerateBibliography);
429430
merge.setDisable(!canRefreshDocument || cslStyleSelected);
430431
unmerge.setDisable(!canRefreshDocument || cslStyleSelected);
431432
manageCitations.setDisable(!canRefreshDocument || cslStyleSelected);

src/main/java/org/jabref/gui/preview/ClipboardContentGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private List<String> generateCitations(List<BibEntry> selectedEntries, CitationS
6666
}
6767

6868
if (styleSource != null) {
69-
return CitationStyleGenerator.generateBibliographies(
69+
return CitationStyleGenerator.generateBibliography(
7070
selectedEntries,
7171
styleSource,
7272
outputFormat,

src/main/java/org/jabref/logic/citationstyle/CSLStyleLoader.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static CitationStyle getDefaultStyle() {
5252
.filter(style -> DEFAULT_STYLE.equals(style.getFilePath()))
5353
.findFirst()
5454
.orElseGet(() -> CSLStyleUtils.createCitationStyleFromFile(DEFAULT_STYLE)
55-
.orElse(new CitationStyle("", "Empty", false, "", true)));
55+
.orElse(new CitationStyle("", "Empty", false, false, "", true)));
5656
}
5757

5858
/**
@@ -78,20 +78,21 @@ public static void loadInternalStyles() {
7878
String path = (String) info.get("path");
7979
String title = (String) info.get("title");
8080
boolean isNumeric = (boolean) info.get("isNumeric");
81+
boolean hasBibliography = (boolean) info.get("hasBibliography");
8182

8283
// We use these metadata and just load the content instead of re-parsing for them
8384
try (InputStream styleStream = CSLStyleLoader.class.getResourceAsStream(STYLES_ROOT + "/" + path)) {
8485
if (styleStream != null) {
8586
String source = new String(styleStream.readAllBytes());
86-
CitationStyle style = new CitationStyle(path, title, isNumeric, source, true);
87+
CitationStyle style = new CitationStyle(path, title, isNumeric, hasBibliography, source, true);
8788
INTERNAL_STYLES.add(style);
8889
}
8990
} catch (IOException e) {
9091
LOGGER.error("Error loading style file: {}", path, e);
9192
styleCount--;
9293
}
9394
}
94-
LOGGER.info("Loaded {} CSL styles", styleCount);
95+
LOGGER.info("Loaded {} CSL styles", styleCount);
9596
} else {
9697
LOGGER.error("Citation style catalog is empty");
9798
}

src/main/java/org/jabref/logic/citationstyle/CSLStyleUtils.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121
* Utility class for handling Citation Style Language (CSL) files.
2222
* Contains shared functionality used by both runtime ({@link CSLStyleLoader}) and build-time ({@link CitationStyleCatalogGenerator}) components.
2323
*/
24-
public class CSLStyleUtils {
24+
public final class CSLStyleUtils {
2525
private static final String STYLES_ROOT = "/csl-styles";
2626
private static final XMLInputFactory XML_INPUT_FACTORY = XMLInputFactory.newInstance();
2727

2828
private static final Logger LOGGER = LoggerFactory.getLogger(CSLStyleUtils.class);
2929

3030
/**
31-
* Style information record (title, isNumericStyle) pair for a citation style.
31+
* Style information record (title, isNumericStyle, hasBibliography) triad for a citation style.
3232
*/
33-
public record StyleInfo(String title, boolean isNumericStyle) {
33+
public record StyleInfo(String title, boolean isNumericStyle, boolean hasBibliography) {
3434
}
3535

3636
static {
@@ -56,7 +56,7 @@ public static boolean isCitationStyleFile(String styleFile) {
5656
*/
5757
public static Optional<CitationStyle> createCitationStyleFromFile(String styleFile) {
5858
if (!isCitationStyleFile(styleFile)) {
59-
LOGGER.error("Can only load style files: {}", styleFile);
59+
LOGGER.error("Not a .csl style file: {}", styleFile);
6060
return Optional.empty();
6161
}
6262

@@ -95,7 +95,7 @@ private static Optional<CitationStyle> createCitationStyleFromSource(InputStream
9595
String content = new String(source.readAllBytes());
9696

9797
Optional<StyleInfo> styleInfo = parseStyleInfo(filename, content);
98-
return styleInfo.map(info -> new CitationStyle(filename, info.title(), info.isNumericStyle(), content, isInternal));
98+
return styleInfo.map(info -> new CitationStyle(filename, info.title(), info.isNumericStyle(), info.hasBibliography(), content, isInternal));
9999
} catch (IOException e) {
100100
LOGGER.error("Error while parsing source", e);
101101
return Optional.empty();
@@ -115,6 +115,7 @@ public static Optional<StyleInfo> parseStyleInfo(String filename, String content
115115

116116
boolean inInfo = false;
117117
boolean hasBibliography = false;
118+
boolean hasCitation = false;
118119
String title = "";
119120
boolean isNumericStyle = false;
120121

@@ -126,6 +127,7 @@ public static Optional<StyleInfo> parseStyleInfo(String filename, String content
126127

127128
switch (elementName) {
128129
case "bibliography" -> hasBibliography = true;
130+
case "citation" -> hasCitation = true;
129131
case "info" -> inInfo = true;
130132
case "title" -> {
131133
if (inInfo) {
@@ -146,10 +148,10 @@ public static Optional<StyleInfo> parseStyleInfo(String filename, String content
146148
}
147149
}
148150

149-
if (hasBibliography && title != null) {
150-
return Optional.of(new StyleInfo(title, isNumericStyle));
151+
if (hasCitation && title != null) {
152+
return Optional.of(new StyleInfo(title, isNumericStyle, hasBibliography));
151153
} else {
152-
LOGGER.debug("No valid title or bibliography found for file {}", filename);
154+
LOGGER.debug("No valid title or citation found for file {}", filename);
153155
return Optional.empty();
154156
}
155157
} catch (XMLStreamException e) {

src/main/java/org/jabref/logic/citationstyle/CitationStyle.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,24 @@ public class CitationStyle implements OOStyle {
1717
private final String filePath;
1818
private final String title;
1919
private final boolean isNumericStyle;
20+
private final boolean hasBibliography;
2021
private final String source;
2122
private final boolean isInternalStyle;
2223

23-
public CitationStyle(String filePath, String title, boolean isNumericStyle, String source, boolean isInternalStyle) {
24+
public CitationStyle(String filePath, String title, boolean isNumericStyle, boolean hasBibliography, String source, boolean isInternalStyle) {
2425
this.filePath = Path.of(Objects.requireNonNull(filePath)).toString(); // wrapping with Path.of takes care of extra slashes in path due to subsequent storage and retrieval (observed on Windows)
2526
this.title = Objects.requireNonNull(title);
2627
this.isNumericStyle = isNumericStyle;
28+
this.hasBibliography = hasBibliography;
2729
this.source = Objects.requireNonNull(source);
2830
this.isInternalStyle = isInternalStyle;
2931
}
3032

3133
/**
3234
* Creates a new citation style with an auto-determined internal/external state.
3335
*/
34-
public CitationStyle(String filePath, String title, boolean isNumericStyle, String source) {
35-
this(filePath, title, isNumericStyle, source, !Path.of(filePath).isAbsolute());
36+
public CitationStyle(String filePath, String title, boolean isNumericStyle, boolean hasBibliography, String source) {
37+
this(filePath, title, isNumericStyle, hasBibliography, source, !Path.of(filePath).isAbsolute());
3638
}
3739

3840
public String getTitle() {
@@ -43,6 +45,10 @@ public boolean isNumericStyle() {
4345
return isNumericStyle;
4446
}
4547

48+
public boolean hasBibliography() {
49+
return hasBibliography;
50+
}
51+
4652
/**
4753
* Currently, we have support for one alphanumeric CSL style.
4854
* There is no tag or field in .csl style files that can be parsed to determine if it is an alphanumeric style.

0 commit comments

Comments
 (0)