Skip to content

Commit

Permalink
Fix: Sync bibliography for JStyle, refactoring, todo comments for alw…
Browse files Browse the repository at this point in the history
…aysCitedOnPages
  • Loading branch information
subhramit committed Aug 31, 2024
1 parent 70d7c9c commit 5e270eb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
20 changes: 6 additions & 14 deletions src/main/java/org/jabref/gui/openoffice/OOBibBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,8 @@ public class OOBibBase {

private final DialogService dialogService;

// After inserting a citation, if ooPrefs.getSyncWhenCiting() returns true, shall we also update the bibliography?
private final boolean refreshBibliographyDuringSyncWhenCiting;

// Shall we add "Cited on pages: ..." to resolved bibliography entries?
private final boolean alwaysAddCitedOnPages;
private final boolean alwaysAddCitedOnPages; // TODO (see comment above)

private final OOBibBaseConnect connection;

Expand All @@ -86,7 +83,6 @@ public OOBibBase(Path loPath, DialogService dialogService)
this.dialogService = dialogService;
this.connection = new OOBibBaseConnect(loPath, dialogService);

this.refreshBibliographyDuringSyncWhenCiting = false;
this.alwaysAddCitedOnPages = false;
}

Expand Down Expand Up @@ -576,27 +572,23 @@ public void guiActionInsertEntry(List<BibEntry> entries,
}

/*
* For sync we need a FunctionalTextViewCursor.
* For sync we need a FunctionalTextViewCursor and an open database.
*/
OOResult<FunctionalTextViewCursor, OOError> fcursor = null;
if (syncOptions.isPresent()) {
fcursor = getFunctionalTextViewCursor(doc, errorTitle);
if (testDialog(errorTitle, fcursor.asVoidResult())) {
return;
}
}

syncOptions
.map(e -> e.setUpdateBibliography(this.refreshBibliographyDuringSyncWhenCiting))
.map(e -> e.setAlwaysAddCitedOnPages(this.alwaysAddCitedOnPages));

if (syncOptions.isPresent()) {
if (testDialog(databaseIsRequired(syncOptions.get().databases,
OOError::noDataBaseIsOpenForSyncingAfterCitation))) {
return;
}
}

syncOptions
.map(e -> e.setAlwaysAddCitedOnPages(this.alwaysAddCitedOnPages)); // TODO: Provide option to user: this is always false

try {

UnoUndo.enterUndoContext(doc, "Insert citation");
Expand Down Expand Up @@ -873,7 +865,7 @@ public void guiActionUpdateDocument(List<BibDatabase> databases, OOStyle style)
Update.SyncOptions syncOptions = new Update.SyncOptions(databases);
syncOptions
.setUpdateBibliography(true)
.setAlwaysAddCitedOnPages(this.alwaysAddCitedOnPages);
.setAlwaysAddCitedOnPages(this.alwaysAddCitedOnPages); // TODO: Provide option to user: this is always false

unresolvedKeys = Update.synchronizeDocument(doc, frontend, jStyle, fcursor.get(), syncOptions);
} finally {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,10 @@ private void pushEntries(CitationType citationType, boolean addPageInfo) {
? Optional.of(new Update.SyncOptions(getBaseList()))
: Optional.empty();

// Sync options are non-null only when "Automatically sync bibliography when inserting citations" is enabled
if (syncOptions.isPresent() && preferencesService.getOpenOfficePreferences().getSyncWhenCiting()) {
syncOptions.get().setUpdateBibliography(true);
}
ooBase.guiActionInsertEntry(entries,
bibDatabaseContext,
entryTypesManager,
Expand Down

0 comments on commit 5e270eb

Please sign in to comment.