Skip to content

Commit

Permalink
Add setting: always add "Cited on pages" text to JStyles. (JabRef#11732)
Browse files Browse the repository at this point in the history
* Add setting to always add "Cited on pages" text in JStyle Citations.

* Add setting: always add "Cited on pages" text to JStyles.

* Add changelog.

* Add change to Changelog.

* Fix translation key. Ensure checkstyle conformity.

* Correct option text, position, & hiding behavior.

The new option's presence now based on selected style, with presence
being ensured only if the style is a JStyle. The option now appears
always first from the top, using index based insertion to achieve this.

The text has been updated to reference bibliographic entries as opposed
to citations, which was factually incorrect.

* Cited on pages... text now appears.

Reference existing preference in OOBibBase to properly propagate
setting, so that "Cited on pages" text literal will appear when user has
it configured.

Remove accomplished TODOs.

* Shift changelog entry, fix setting string, misc. formatting

* Attempt to update submodules to origin/master state.

* Attempt to fix submodule hashes.

* Re-ignore submodules.

* Fix spacing.

---------

Co-authored-by: Subhramit Basu Bhowmick <[email protected]>
  • Loading branch information
heyitsdross and subhramit authored Sep 13, 2024
1 parent 939f696 commit 35b0516
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/jabref/gui/openoffice/OOBibBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,22 +69,21 @@ 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 {

this.dialogService = dialogService;
this.connection = new OOBibBaseConnect(loPath, dialogService);

this.alwaysAddCitedOnPages = false;
this.alwaysAddCitedOnPages = openOfficePreferences.getAlwaysAddCitedOnPages();
}

private void initializeCitationAdapter(XTextDocument doc) throws WrappedTargetException, NoSuchElementException {
Expand Down Expand Up @@ -583,7 +583,7 @@ public void guiActionInsertEntry(List<BibEntry> 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 {

Expand Down
38 changes: 34 additions & 4 deletions src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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<OOStyle> currentStyleProperty;

public OpenOfficePanel(LibraryTabContainer tabContainer,
PreferencesService preferencesService,
KeyBindingRepository keyBindingRepository,
Expand All @@ -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();

Expand Down Expand Up @@ -157,6 +163,8 @@ public OpenOfficePanel(LibraryTabContainer tabContainer,
preferencesService.getLayoutFormatterPreferences(),
abbreviationRepository);

currentStyleProperty = new SimpleObjectProperty<>(currentStyle);

initPanel();
}

Expand All @@ -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;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -614,12 +625,27 @@ private boolean checkThatEntriesHaveKeys(List<BibEntry> 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"));
Expand Down Expand Up @@ -651,6 +677,10 @@ private ContextMenu createSettingsPopup() {
new SeparatorMenuItem(),
clearConnectionSettings);

if (currentStyle instanceof JStyle) {
contextMenu.getItems().add(1, alwaysAddCitedOnPagesText);
}

return contextMenu;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,22 @@ public class OpenOfficePreferences {
private final ObservableList<String> externalStyles;
private final StringProperty currentJStyle;
private final ObjectProperty<OOStyle> currentStyle;
private final BooleanProperty alwaysAddCitedOnPages;

public OpenOfficePreferences(String executablePath,
boolean useAllDatabases,
boolean syncWhenCiting,
List<String> 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() {
Expand Down Expand Up @@ -137,4 +140,16 @@ public ObjectProperty<OOStyle> 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);
}
}
6 changes: 5 additions & 1 deletion src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 ->
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 35b0516

Please sign in to comment.