Skip to content

Commit

Permalink
Fix preview settings not saved due to l10n (#7077)
Browse files Browse the repository at this point in the history
* Fix preview settings not saved due to l10n

Introduce internal name for finding layout
Fixes #6447

* rename getInternalName
  • Loading branch information
Siedlerchr authored Nov 6, 2020
1 parent 09f8098 commit 2f27dd3
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 15 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
6 changes: 3 additions & 3 deletions src/main/java/org/jabref/gui/preferences/PreviewTabView.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void initialize() {
availableListView.itemsProperty().bindBidirectional(viewModel.availableListProperty());
viewModel.availableSelectionModelProperty().setValue(availableListView.getSelectionModel());
new ViewModelListCellFactory<PreviewLayout>()
.withText(PreviewLayout::getName)
.withText(PreviewLayout::getDisplayName)
.install(availableListView);
availableListView.setOnDragOver(this::dragOver);
availableListView.setOnDragDetected(this::dragDetectedInAvailable);
Expand All @@ -129,7 +129,7 @@ public void initialize() {
chosenListView.itemsProperty().bindBidirectional(viewModel.chosenListProperty());
viewModel.chosenSelectionModelProperty().setValue(chosenListView.getSelectionModel());
new ViewModelListCellFactory<PreviewLayout>()
.withText(PreviewLayout::getName)
.withText(PreviewLayout::getDisplayName)
.setOnDragDropped(this::dragDroppedInChosenCell)
.install(chosenListView);
chosenListView.setOnDragOver(this::dragOver);
Expand Down Expand Up @@ -197,7 +197,7 @@ private void jumpToSearchKey(ListView<PreviewLayout> list, KeyEvent keypressed)

lastKeyPressTime = System.currentTimeMillis();

list.getItems().stream().filter(item -> item.getName().toLowerCase().startsWith(listSearchTerm))
list.getItems().stream().filter(item -> item.getDisplayName().toLowerCase().startsWith(listSearchTerm))
.findFirst().ifPresent(list::scrollTo);
}

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 @@ -174,13 +176,14 @@ private PreviewLayout findLayoutByName(String name) {
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 Expand Up @@ -257,7 +260,7 @@ public void removeFromChosen() {
chosenSelectionModelProperty.getValue().clearSelection();
chosenListProperty.removeAll(selected);
availableListProperty.addAll(selected);
availableListProperty.sort((a, b) -> a.getName().compareToIgnoreCase(b.getName()));
availableListProperty.sort((a, b) -> a.getDisplayName().compareToIgnoreCase(b.getDisplayName()));
}

public void selectedInChosenUp() {
Expand Down Expand Up @@ -413,7 +416,7 @@ public boolean dragDropped(ListProperty<PreviewLayout> targetList, Dragboard dra
success = true;

if (targetList == availableListProperty) {
targetList.getValue().sort((a, b) -> a.getName().compareToIgnoreCase(b.getName()));
targetList.getValue().sort((a, b) -> a.getDisplayName().compareToIgnoreCase(b.getDisplayName()));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/preview/PreviewPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private void updateLayout(PreviewPreferences previewPreferences, boolean init) {
previewView.setLayout(currentPreviewStyle);
preferences.storePreviewPreferences(previewPreferences);
if (!init) {
dialogService.notify(Localization.lang("Preview style changed to: %0", currentPreviewStyle.getName()));
dialogService.notify(Localization.lang("Preview style changed to: %0", currentPreviewStyle.getDisplayName()));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/preview/PreviewViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private void update() {

BackgroundTask
.wrap(() -> layout.generatePreview(entry.get(), database.getDatabase()))
.onRunning(() -> setPreviewText("<i>" + Localization.lang("Processing %0", Localization.lang("Citation Style")) + ": " + layout.getName() + " ..." + "</i>"))
.onRunning(() -> setPreviewText("<i>" + Localization.lang("Processing %0", Localization.lang("Citation Style")) + ": " + layout.getDisplayName() + " ..." + "</i>"))
.onSuccess(this::setPreviewText)
.onFailure(exception -> {
LOGGER.error("Error while generating citation style", exception);
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 @@ -76,6 +76,11 @@ public String generatePreview(BibEntry originalEntry, BibDatabase database) {
return result;
}

@Override
public String getDisplayName() {
return name;
}

@Override
public String getName() {
return name;
Expand Down
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 @@ -17,7 +17,7 @@ public String generatePreview(BibEntry entry, BibDatabase database) {
}

@Override
public String getName() {
public String getDisplayName() {
return citationStyle.getTitle();
}

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

@Override
public String getName() {
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 @@ -56,6 +57,11 @@ public String getText() {

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

@Override
public String getDisplayName() {
return Localization.lang("Customized preview style");
}
}
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 @@ -10,5 +10,7 @@ public interface PreviewLayout {

String generatePreview(BibEntry entry, BibDatabase database);

String getDisplayName();

String getName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2409,7 +2409,7 @@ public void storePreviewPreferences(PreviewPreferences previewPreferences) {
if (layout instanceof CitationStylePreviewLayout) {
return ((CitationStylePreviewLayout) layout).getFilePath();
} else {
return layout.getName();
return layout.getDisplayName();
}
}).collect(Collectors.toList()));
putDouble(PREVIEW_PANEL_HEIGHT, previewPreferences.getPreviewPanelDividerPosition().doubleValue());
Expand Down

0 comments on commit 2f27dd3

Please sign in to comment.