From d6462bcd35809f4593f138080c2ec107914e624e Mon Sep 17 00:00:00 2001 From: Chelsey Ong Date: Sat, 26 Jan 2019 13:19:32 +0700 Subject: [PATCH 1/2] Modify prefsTab to save the selected preview style in preferences --- src/main/java/org/jabref/gui/PreviewPanel.java | 9 +++++++-- .../java/org/jabref/gui/preferences/PreviewPrefsTab.java | 3 +++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/PreviewPanel.java b/src/main/java/org/jabref/gui/PreviewPanel.java index bffcb4e2bd3..fe9509079d8 100644 --- a/src/main/java/org/jabref/gui/PreviewPanel.java +++ b/src/main/java/org/jabref/gui/PreviewPanel.java @@ -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 = Optional.empty(); @@ -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())); } @@ -299,6 +301,9 @@ public void update() { .doLayout(entry, databaseContext.getDatabase()))); setPreviewLabel(sb.toString()); } else if (basePanel.isPresent() && bibEntry.isPresent()) { + if (citationStyle != null && previewStyle != defaultPreviewStyle) { + basePanel.get().getCitationStyleCache().setCitationStyle(citationStyle); + } Future citationStyleWorker = BackgroundTask .wrap(() -> basePanel.get().getCitationStyleCache().getCitationFor(bibEntry.get())) .onRunning(() -> { diff --git a/src/main/java/org/jabref/gui/preferences/PreviewPrefsTab.java b/src/main/java/org/jabref/gui/preferences/PreviewPrefsTab.java index 071aa23cd0a..76fc314f1b8 100644 --- a/src/main/java/org/jabref/gui/preferences/PreviewPrefsTab.java +++ b/src/main/java/org/jabref/gui/preferences/PreviewPrefsTab.java @@ -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 From e960816e6d17b235b1dee9fcdf824f06dbb1393f Mon Sep 17 00:00:00 2001 From: Chelsey Ong Date: Mon, 28 Jan 2019 22:27:29 +0700 Subject: [PATCH 2/2] Fix codacy by changing to equals --- src/main/java/org/jabref/gui/PreviewPanel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/PreviewPanel.java b/src/main/java/org/jabref/gui/PreviewPanel.java index fe9509079d8..95323116271 100644 --- a/src/main/java/org/jabref/gui/PreviewPanel.java +++ b/src/main/java/org/jabref/gui/PreviewPanel.java @@ -301,7 +301,7 @@ public void update() { .doLayout(entry, databaseContext.getDatabase()))); setPreviewLabel(sb.toString()); } else if (basePanel.isPresent() && bibEntry.isPresent()) { - if (citationStyle != null && previewStyle != defaultPreviewStyle) { + if (citationStyle != null && !previewStyle.equals(defaultPreviewStyle)) { basePanel.get().getCitationStyleCache().setCitationStyle(citationStyle); } Future citationStyleWorker = BackgroundTask