Skip to content
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

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

Merged
Show file tree
Hide file tree
Changes from 13 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
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[submodule "abbrv.jabref.org"]
path = buildres/abbrv.jabref.org
url = https://github.com/JabRef/abbrv.jabref.org.git
ignore = all
# ignore = all
Copy link
Member

Choose a reason for hiding this comment

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

see my latest comment for a TL;DR (git submodules are a pain in the a**)

shallow = true
[submodule "csl-styles"]
path = src/main/resources/csl-styles
url = https://github.com/citation-style-language/styles.git
ignore = all
# ignore = all
shallow = true
[submodule "csl-locales"]
path = src/main/resources/csl-locales
url = https://github.com/citation-style-language/locales.git
ignore = all
# ignore = all
shallow = true
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();
subhramit marked this conversation as resolved.
Show resolved Hide resolved
}

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();

Comment on lines -617 to -618
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any reason why this was moved? Initializations are usually done at the beginning of the scope.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Personal practice is to initialize as close to first usage as possible to increase refactorability, but if it's project standard to initialize at the beginning, then I will gladly undo.

Copy link
Collaborator

@subhramit subhramit Sep 9, 2024

Choose a reason for hiding this comment

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

Yes, there is no general hard-and-fast best practice regarding this. Beginning-of-scope-initialization is preferred when a dependency is used throughout the scope multiple times in logically segregated segments. Near-first-use-initialization is used if the usage is confined, and refactorability is indeed the argument.

I would have requested you to change back, but since moving it to the class level (my comment below on refactoring) will anyway do it at a more global level, this line will just be removed from here.

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
Loading