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

Reenable prevcycle #5385

Merged
merged 8 commits into from
Oct 6, 2019
Merged
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
Next Next commit
fixes 5369 - fallback to 0 in case stored preview cycle pos does no l…
…onger exist
matthiasgeiger committed Oct 3, 2019
commit 8b80dcf9ca37fc70ccb9517decaccf3ffb4ffce6
9 changes: 8 additions & 1 deletion src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
@@ -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);
@@ -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);
}

18 changes: 9 additions & 9 deletions src/main/java/org/jabref/preferences/PreviewPreferences.java
Original file line number Diff line number Diff line change
@@ -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();
@@ -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;
}
@@ -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);
}
}