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

Fix preview style configuration #4613

Merged
merged 3 commits into from
Jan 31, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 7 additions & 2 deletions src/main/java/org/jabref/gui/PreviewPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class PreviewPanel extends ScrollPane implements SearchQueryHighlightList
private final KeyBindingRepository keyBindingRepository;

private String previewStyle;
private CitationStyle citationStyle;
private final String defaultPreviewStyle = "Preview";
private Optional<BasePanel> basePanel = Optional.empty();

Expand Down Expand Up @@ -224,13 +225,14 @@ private void updateLayout(PreviewPreferences previewPreferences, boolean init) {
String style = previewPreferences.getCurrentPreviewStyle();
if (previewStyle == null) {
previewStyle = style;
CitationStyle.createCitationStyleFromFile(style).ifPresent(cs -> citationStyle = cs);
}
if (basePanel.isPresent() && !previewStyle.equals(style)) {
if (CitationStyle.isCitationStyleFile(style)) {
layout = Optional.empty();
CitationStyle.createCitationStyleFromFile(style)
.ifPresent(citationStyle -> {
basePanel.get().getCitationStyleCache().setCitationStyle(citationStyle);
.ifPresent(cs -> {
citationStyle = cs;
if (!init) {
basePanel.get().output(Localization.lang("Preview style changed to: %0", citationStyle.getTitle()));
}
Expand Down Expand Up @@ -299,6 +301,9 @@ public void update() {
.doLayout(entry, databaseContext.getDatabase())));
setPreviewLabel(sb.toString());
} else if (basePanel.isPresent() && bibEntry.isPresent()) {
if (citationStyle != null && !previewStyle.equals(defaultPreviewStyle)) {
basePanel.get().getCitationStyleCache().setCitationStyle(citationStyle);
}
Future<?> citationStyleWorker = BackgroundTask
.wrap(() -> basePanel.get().getCitationStyleCache().getCitationFor(bibEntry.get()))
.onRunning(() -> {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/gui/preferences/PreviewPrefsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ public void storeSettings() {
.withPreviewCycle(styles)
.withPreviewStyle(layout.getText().replace("\n", "__NEWLINE__"))
.build();
if (!chosen.getSelectionModel().isEmpty()) {
previewPreferences = previewPreferences.getBuilder().withPreviewCyclePosition(chosen.getSelectionModel().getSelectedIndex()).build();
}
Globals.prefs.storePreviewPreferences(previewPreferences);

// update preview
Expand Down