Skip to content

Commit

Permalink
fixes 5369 - fallback to 0 in case stored preview cycle pos does no l…
Browse files Browse the repository at this point in the history
…onger exist (#5382)
  • Loading branch information
matthiasgeiger authored and Siedlerchr committed Oct 3, 2019
1 parent 0988e2f commit 79f9c86
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
9 changes: 8 additions & 1 deletion src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -1603,7 +1603,6 @@ public JabRefPreferences storePreviewPreferences(PreviewPreferences previewPrefe

@Override
public PreviewPreferences getPreviewPreferences() {
int cyclePos = getInt(CYCLE_PREVIEW_POS);
List<String> cycle = getStringList(CYCLE_PREVIEW);
double panelHeight = getDouble(PREVIEW_PANEL_HEIGHT);
String style = get(PREVIEW_STYLE);
Expand All @@ -1628,6 +1627,14 @@ public PreviewPreferences getPreviewPreferences() {
.filter(Objects::nonNull)
.collect(Collectors.toList());

int cyclePos;
int storedCyclePos = getInt(CYCLE_PREVIEW_POS);
if (storedCyclePos < layouts.size()) {
cyclePos = storedCyclePos;
} else {
cyclePos = 0; // fallback if stored position is no longer valid
}

return new PreviewPreferences(layouts, cyclePos, panelHeight, enabled, style, styleDefault);
}

Expand Down
18 changes: 9 additions & 9 deletions src/main/java/org/jabref/preferences/PreviewPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ public PreviewLayout getTextBasedPreviewLayout() {
public static class Builder {

private List<PreviewLayout> previewCycle;
private int previeCyclePosition;
private int previewCyclePosition;
private Number previewPanelDividerPosition;
private boolean previewPanelEnabled;
private String previewStyle;
private final String previewStyleDefault;

public Builder(PreviewPreferences previewPreferences) {
this.previewCycle = previewPreferences.getPreviewCycle();
this.previeCyclePosition = previewPreferences.getPreviewCyclePosition();
this.previewCyclePosition = previewPreferences.getPreviewCyclePosition();
this.previewPanelDividerPosition = previewPreferences.getPreviewPanelDividerPosition();
this.previewPanelEnabled = previewPreferences.isPreviewPanelEnabled();
this.previewStyle = previewPreferences.getPreviewStyle();
Expand All @@ -85,18 +85,18 @@ public Builder(PreviewPreferences previewPreferences) {

public Builder withPreviewCycle(List<PreviewLayout> previewCycle) {
this.previewCycle = previewCycle;
return withPreviewCyclePosition(previeCyclePosition);
return withPreviewCyclePosition(previewCyclePosition);
}

public Builder withPreviewCyclePosition(int position) {
if (previewCycle.isEmpty()) {
previeCyclePosition = 0;
previewCyclePosition = 0;
} else {
previeCyclePosition = position;
while (previeCyclePosition < 0) {
previeCyclePosition += previewCycle.size();
previewCyclePosition = position;
while (previewCyclePosition < 0) {
previewCyclePosition += previewCycle.size();
}
previeCyclePosition %= previewCycle.size();
previewCyclePosition %= previewCycle.size();
}
return this;
}
Expand All @@ -117,7 +117,7 @@ public Builder withPreviewStyle(String previewStyle) {
}

public PreviewPreferences build() {
return new PreviewPreferences(previewCycle, previeCyclePosition, previewPanelDividerPosition, previewPanelEnabled, previewStyle, previewStyleDefault);
return new PreviewPreferences(previewCycle, previewCyclePosition, previewPanelDividerPosition, previewPanelEnabled, previewStyle, previewStyleDefault);
}
}

Expand Down

0 comments on commit 79f9c86

Please sign in to comment.