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 settings not saved due to l10n #7077

Merged
merged 2 commits into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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) {
Comment on lines +94 to +95
Copy link
Member

Choose a reason for hiding this comment

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

Does patternmatching with instanceof already work?

            if (getCurrentLayout() instanceof TextBasedPreviewLayout currentLayout) {

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately in jdk14 it's still a preview feature.

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