Skip to content

Commit

Permalink
Fix preview settings not saved due to l10n
Browse files Browse the repository at this point in the history
Introduce internal name for finding layout
Fixes #6447
  • Loading branch information
Siedlerchr committed Nov 5, 2020
1 parent fcbe9c5 commit 1bb2d72
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ inserting new citations in a OpenOffic/LibreOffice document. [#6957](https://git
- We fixed an issue, when pulling changes from shared database via shortcut caused creation of a new tech report [6867](https://github.com/JabRef/jabref/issues/6867)
- We fixed an issue where the JabRef GUI does not highlight the "All entries" group on start-up [#6691](https://github.com/JabRef/jabref/issues/6691)
- We fixed an issue where a custom dark theme was not applied to the entry preview tab [7068](https://github.com/JabRef/jabref/issues/7068)
- We fixed an issue where modifications to the Custom preview layout in the preferences were not saved [#6447](https://github.com/JabRef/jabref/issues/6447)

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ public PreviewTabViewModel(DialogService dialogService, PreferencesService prefe
initialPreviewPreferences = preferences.getPreviewPreferences();

sourceTextProperty.addListener((observable, oldValue, newValue) -> {
if (getCurrentLayout() instanceof TextBasedPreviewLayout) {
((TextBasedPreviewLayout) getCurrentLayout()).setText(sourceTextProperty.getValue().replace("\n", "__NEWLINE__"));
var currentLayout = getCurrentLayout();
if (currentLayout instanceof TextBasedPreviewLayout) {
((TextBasedPreviewLayout) currentLayout).setText(sourceTextProperty.getValue().replace("\n", "__NEWLINE__"));
}
});

Expand All @@ -112,6 +113,7 @@ public BooleanProperty showAsExtraTabProperty() {
return showAsExtraTab;
}

@Override
public void setValues() {
showAsExtraTab.set(initialPreviewPreferences.showPreviewAsExtraTab());
chosenListProperty().getValue().clear();
Expand Down Expand Up @@ -164,23 +166,24 @@ public void refreshPreview() {
}

private PreviewLayout findLayoutByName(String name) {
return availableListProperty.getValue().stream().filter(layout -> layout.getName().equals(name))
return availableListProperty.getValue().stream().filter(layout -> layout.getInternalName().equals(name))
.findAny()
.orElse(chosenListProperty.getValue().stream().filter(layout -> layout.getName().equals(name))
.orElse(chosenListProperty.getValue().stream().filter(layout -> layout.getInternalName().equals(name))
.findAny()
.orElse(null));
}

private PreviewLayout getCurrentLayout() {
if (!chosenSelectionModelProperty.getValue().getSelectedItems().isEmpty()) {
return chosenSelectionModelProperty.getValue().getSelectedItems().get(0);

}

if (!chosenListProperty.getValue().isEmpty()) {
return chosenListProperty.getValue().get(0);
}

PreviewLayout layout = findLayoutByName("Preview");
PreviewLayout layout = findLayoutByName(TextBasedPreviewLayout.NAME);
if (layout == null) {
layout = initialPreviewPreferences.getTextBasedPreviewLayout();
}
Expand All @@ -196,7 +199,7 @@ public void storeSettings() {
chosenListProperty.add(previewPreferences.getTextBasedPreviewLayout());
}

PreviewLayout previewStyle = findLayoutByName("Preview");
PreviewLayout previewStyle = findLayoutByName(TextBasedPreviewLayout.NAME);
if (previewStyle == null) {
previewStyle = previewPreferences.getTextBasedPreviewLayout();
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/jabref/logic/bst/BstPreviewLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,9 @@ public String generatePreview(BibEntry originalEntry, BibDatabase database) {
public String getName() {
return name;
}

@Override
public String getInternalName() {
return name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.jabref.model.entry.BibEntry;

public class CitationStylePreviewLayout implements PreviewLayout {
private CitationStyle citationStyle;
private final CitationStyle citationStyle;

public CitationStylePreviewLayout(CitationStyle citationStyle) {
this.citationStyle = citationStyle;
Expand All @@ -28,4 +28,9 @@ public String getSource() {
public String getFilePath() {
return citationStyle.getFilePath();
}

@Override
public String getInternalName() {
return citationStyle.getTitle();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
* Implements the preview based JabRef's <a href="https://docs.jabref.org/import-export/export/customexports">Custom export fitlters</a>.
*/
public class TextBasedPreviewLayout implements PreviewLayout {
private static final Logger LOGGER = LoggerFactory.getLogger(TextBasedPreviewLayout.class);
public static final String NAME = "PREVIEW";

private static final Logger LOGGER = LoggerFactory.getLogger(TextBasedPreviewLayout.class);
private Layout layout;
private String text;
private LayoutFormatterPreferences layoutFormatterPreferences;
Expand Down Expand Up @@ -54,6 +55,11 @@ public String getText() {
return text;
}

@Override
public String getInternalName() {
return NAME;
}

@Override
public String getName() {
return Localization.lang("Customized preview style");
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/logic/preview/PreviewLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface PreviewLayout {
String generatePreview(BibEntry entry, BibDatabase database);

String getName();

String getInternalName();
}

0 comments on commit 1bb2d72

Please sign in to comment.