diff --git a/CHANGELOG.md b/CHANGELOG.md index 49785c7fc89..967c615792e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We added a switch not to store the linked file URL, because it caused troubles at other apps. [#11735](https://github.com/JabRef/jabref/pull/11735) - When starting a new SLR, the selected catalogs now persist within and across JabRef sessions. [koppor#614](https://github.com/koppor/jabref/issues/614) - We added a different background color to the search bar to indicate when the search syntax is wrong. [#11658](https://github.com/JabRef/jabref/pull/11658) +- We added a setting which always adds the literal "Cited on pages" text before each JStyle citation. [#11691](https://github.com/JabRef/jabref/pull/11732) ### Changed diff --git a/src/main/java/org/jabref/gui/openoffice/OOBibBase.java b/src/main/java/org/jabref/gui/openoffice/OOBibBase.java index 40a37a69d9f..637c729a720 100644 --- a/src/main/java/org/jabref/gui/openoffice/OOBibBase.java +++ b/src/main/java/org/jabref/gui/openoffice/OOBibBase.java @@ -15,6 +15,7 @@ import org.jabref.logic.citationstyle.CitationStyle; import org.jabref.logic.l10n.Localization; import org.jabref.logic.openoffice.NoDocumentFoundException; +import org.jabref.logic.openoffice.OpenOfficePreferences; import org.jabref.logic.openoffice.action.EditInsert; import org.jabref.logic.openoffice.action.EditMerge; import org.jabref.logic.openoffice.action.EditSeparate; @@ -68,14 +69,13 @@ public class OOBibBase { private final DialogService dialogService; - // Shall we add "Cited on pages: ..." to resolved bibliography entries? - private final boolean alwaysAddCitedOnPages; // TODO (see comment above) + private final boolean alwaysAddCitedOnPages; private final OOBibBaseConnect connection; private CSLCitationOOAdapter cslCitationOOAdapter; - public OOBibBase(Path loPath, DialogService dialogService) + public OOBibBase(Path loPath, DialogService dialogService, OpenOfficePreferences openOfficePreferences) throws BootstrapException, CreationException { @@ -83,7 +83,7 @@ public OOBibBase(Path loPath, DialogService dialogService) this.dialogService = dialogService; this.connection = new OOBibBaseConnect(loPath, dialogService); - this.alwaysAddCitedOnPages = false; + this.alwaysAddCitedOnPages = openOfficePreferences.getAlwaysAddCitedOnPages(); } private void initializeCitationAdapter(XTextDocument doc) throws WrappedTargetException, NoSuchElementException { @@ -583,7 +583,7 @@ public void guiActionInsertEntry(List entries, } } - syncOptions.map(e -> e.setAlwaysAddCitedOnPages(this.alwaysAddCitedOnPages)); // TODO: Provide option to user: this is always false + syncOptions.map(e -> e.setAlwaysAddCitedOnPages(this.alwaysAddCitedOnPages)); try { diff --git a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java index cff14afe648..fa38b9a385b 100644 --- a/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java +++ b/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java @@ -8,6 +8,7 @@ import javax.swing.undo.UndoManager; +import javafx.beans.property.SimpleObjectProperty; import javafx.concurrent.Task; import javafx.geometry.Insets; import javafx.geometry.Side; @@ -65,6 +66,7 @@ import com.sun.star.comp.helper.BootstrapException; import com.sun.star.container.NoSuchElementException; import com.sun.star.lang.WrappedTargetException; +import com.tobiasdiez.easybind.EasyBind; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -102,9 +104,12 @@ public class OpenOfficePanel { private final LibraryTabContainer tabContainer; private final FileUpdateMonitor fileUpdateMonitor; private final BibEntryTypesManager entryTypesManager; + private final OpenOfficePreferences openOfficePreferences; private OOBibBase ooBase; private OOStyle currentStyle; + private final SimpleObjectProperty currentStyleProperty; + public OpenOfficePanel(LibraryTabContainer tabContainer, PreferencesService preferencesService, KeyBindingRepository keyBindingRepository, @@ -126,6 +131,7 @@ public OpenOfficePanel(LibraryTabContainer tabContainer, this.clipBoardManager = clipBoardManager; this.undoManager = undoManager; this.currentStyle = preferencesService.getOpenOfficePreferences().getCurrentStyle(); + this.openOfficePreferences = preferencesService.getOpenOfficePreferences(); ActionFactory factory = new ActionFactory(); @@ -157,6 +163,8 @@ public OpenOfficePanel(LibraryTabContainer tabContainer, preferencesService.getLayoutFormatterPreferences(), abbreviationRepository); + currentStyleProperty = new SimpleObjectProperty<>(currentStyle); + initPanel(); } @@ -170,6 +178,7 @@ public Node getContent() { */ private boolean getOrUpdateTheStyle(String title) { currentStyle = loader.getUsedStyleUnified(); + currentStyleProperty.set(currentStyle); final boolean FAIL = true; final boolean PASS = false; @@ -215,6 +224,8 @@ private void initPanel() { dialogService.showCustomDialogAndWait(styleDialog) .ifPresent(selectedStyle -> { currentStyle = selectedStyle; + currentStyleProperty.set(currentStyle); + if (currentStyle instanceof JStyle jStyle) { try { jStyle.ensureUpToDate(); @@ -472,7 +483,7 @@ protected OOBibBase call() throws BootstrapException, CreationException { } private OOBibBase createBibBase(Path loPath) throws BootstrapException, CreationException { - return new OOBibBase(loPath, dialogService); + return new OOBibBase(loPath, dialogService, openOfficePreferences); } /** @@ -614,12 +625,27 @@ private boolean checkThatEntriesHaveKeys(List entries) { } private ContextMenu createSettingsPopup() { - OpenOfficePreferences openOfficePreferences = preferencesService.getOpenOfficePreferences(); - ContextMenu contextMenu = new ContextMenu(); CheckMenuItem autoSync = new CheckMenuItem(Localization.lang("Automatically sync bibliography when inserting citations")); - autoSync.selectedProperty().set(preferencesService.getOpenOfficePreferences().getSyncWhenCiting()); + autoSync.selectedProperty().set(openOfficePreferences.getSyncWhenCiting()); + + CheckMenuItem alwaysAddCitedOnPagesText = new CheckMenuItem(Localization.lang("Automatically add \"Cited on pages...\" at the end of bibliographic entries")); + alwaysAddCitedOnPagesText.selectedProperty().set(openOfficePreferences.getAlwaysAddCitedOnPages()); + alwaysAddCitedOnPagesText.setOnAction(e -> openOfficePreferences.setAlwaysAddCitedOnPages(alwaysAddCitedOnPagesText.isSelected())); + + EasyBind.listen(currentStyleProperty, (obs, oldValue, newValue) -> { + switch (newValue) { + case JStyle ignored -> { + if (!contextMenu.getItems().contains(alwaysAddCitedOnPagesText)) { + contextMenu.getItems().add(1, alwaysAddCitedOnPagesText); + } + } + case CitationStyle ignored -> + contextMenu.getItems().remove(alwaysAddCitedOnPagesText); + default -> { } + } + }); ToggleGroup toggleGroup = new ToggleGroup(); RadioMenuItem useActiveBase = new RadioMenuItem(Localization.lang("Look up BibTeX entries in the active tab only")); @@ -651,6 +677,10 @@ private ContextMenu createSettingsPopup() { new SeparatorMenuItem(), clearConnectionSettings); + if (currentStyle instanceof JStyle) { + contextMenu.getItems().add(1, alwaysAddCitedOnPagesText); + } + return contextMenu; } } diff --git a/src/main/java/org/jabref/logic/openoffice/OpenOfficePreferences.java b/src/main/java/org/jabref/logic/openoffice/OpenOfficePreferences.java index 7b0f4a2c287..b536fd48e0f 100644 --- a/src/main/java/org/jabref/logic/openoffice/OpenOfficePreferences.java +++ b/src/main/java/org/jabref/logic/openoffice/OpenOfficePreferences.java @@ -31,19 +31,22 @@ public class OpenOfficePreferences { private final ObservableList externalStyles; private final StringProperty currentJStyle; private final ObjectProperty currentStyle; + private final BooleanProperty alwaysAddCitedOnPages; public OpenOfficePreferences(String executablePath, boolean useAllDatabases, boolean syncWhenCiting, List externalStyles, String currentJStyle, - OOStyle currentStyle) { + OOStyle currentStyle, + boolean alwaysAddCitedOnPages) { 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); } public void clearConnectionSettings() { @@ -137,4 +140,16 @@ public ObjectProperty currentStyleProperty() { public void setCurrentStyle(OOStyle style) { this.currentStyle.set(style); } + + public boolean getAlwaysAddCitedOnPages() { + return this.alwaysAddCitedOnPages.get(); + } + + public BooleanProperty alwaysAddCitedOnPagesProperty() { + return this.alwaysAddCitedOnPages; + } + + public void setAlwaysAddCitedOnPages(boolean alwaysAddCitedOnPages) { + this.alwaysAddCitedOnPages.set(alwaysAddCitedOnPages); + } } diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 71010a99881..1c4506e45a2 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -371,6 +371,7 @@ public class JabRefPreferences implements PreferencesService { public static final String OO_BIBLIOGRAPHY_STYLE_FILE = "ooBibliographyStyleFile"; 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"; // Special field preferences public static final String SPECIALFIELDSENABLED = "specialFieldsEnabled"; @@ -759,6 +760,7 @@ private JabRefPreferences() { } defaults.put(OO_SYNC_WHEN_CITING, Boolean.TRUE); + defaults.put(OO_ALWAYS_ADD_CITED_ON_PAGES, Boolean.FALSE); defaults.put(OO_SHOW_PANEL, Boolean.FALSE); defaults.put(OO_USE_ALL_OPEN_BASES, Boolean.TRUE); defaults.put(OO_BIBLIOGRAPHY_STYLE_FILE, StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH); @@ -1383,10 +1385,12 @@ public OpenOfficePreferences getOpenOfficePreferences() { getBoolean(OO_SYNC_WHEN_CITING), getStringList(OO_EXTERNAL_STYLE_FILES), get(OO_BIBLIOGRAPHY_STYLE_FILE), - currentStyle); + currentStyle, + getBoolean(OO_ALWAYS_ADD_CITED_ON_PAGES)); 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)); + EasyBind.listen(openOfficePreferences.alwaysAddCitedOnPagesProperty(), (obs, oldValue, newValue) -> putBoolean(OO_ALWAYS_ADD_CITED_ON_PAGES, newValue)); EasyBind.listen(openOfficePreferences.syncWhenCitingProperty(), (obs, oldValue, newValue) -> putBoolean(OO_SYNC_WHEN_CITING, newValue)); openOfficePreferences.getExternalStyles().addListener((InvalidationListener) change -> diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 80d0c559891..ed0d5a7f9a1 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -1132,6 +1132,7 @@ Unable\ to\ reload\ style\ file=Unable to reload style file Problem\ during\ separating\ cite\ markers=Problem during separating cite markers +Automatically\ add\ "Cited\ on\ pages..."\ at\ the\ end\ of\ bibliographic\ entries=Automatically add "Cited on pages..." at the end of bibliographic entries Automatically\ sync\ bibliography\ when\ inserting\ citations=Automatically sync bibliography when inserting citations Look\ up\ BibTeX\ entries\ in\ the\ active\ tab\ only=Look up BibTeX entries in the active tab only Look\ up\ BibTeX\ entries\ in\ all\ open\ libraries=Look up BibTeX entries in all open libraries