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
Show file tree
Hide file tree
Changes from 5 commits
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We fixed an exception which occured when trying to open a non existing file from the "Recent files"-menu [#5334](https://github.com/JabRef/jabref/issues/5334)
- The context menu for fields in the entry editor is back. [#5254](https://github.com/JabRef/jabref/issues/5254)
- We fixed an exception which occurred when trying to open a non existing file from the "Recent files"-menu [#5334](https://github.com/JabRef/jabref/issues/5334)
- We re-introduced the feature to switch between different preview styles. [#5221](https://github.com/JabRef/jabref/issues/5221)





### Removed

Expand Down
17 changes: 5 additions & 12 deletions src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
import org.jabref.model.entry.field.SpecialFieldValue;
import org.jabref.model.entry.field.StandardField;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.preferences.PreviewPreferences;

import com.google.common.eventbus.Subscribe;
import org.fxmisc.easybind.EasyBind;
Expand Down Expand Up @@ -352,6 +351,9 @@ private void setupActions() {
new SpecialFieldViewModel(SpecialField.READ_STATUS, undoManager).getSpecialFieldAction(status, this.frame));
}

actions.put(Actions.NEXT_PREVIEW_STYLE, this::nextPreviewStyle);
actions.put(Actions.PREVIOUS_PREVIEW_STYLE, this::previousPreviewStyle);

actions.put(Actions.SEND_AS_EMAIL, new SendAsEMailAction(frame));

actions.put(Actions.WRITE_XMP, new WriteXMPAction(this)::execute);
Expand Down Expand Up @@ -845,20 +847,11 @@ private void showAndEdit() {
}

public void nextPreviewStyle() {
cyclePreview(Globals.prefs.getPreviewPreferences().getPreviewCyclePosition() + 1);
entryEditor.nextPreviewStyle();
matthiasgeiger marked this conversation as resolved.
Show resolved Hide resolved
}

public void previousPreviewStyle() {
cyclePreview(Globals.prefs.getPreviewPreferences().getPreviewCyclePosition() - 1);
}

private void cyclePreview(int newPosition) {
PreviewPreferences previewPreferences = Globals.prefs.getPreviewPreferences()
.getBuilder()
.withPreviewCyclePosition(newPosition)
.build();
Globals.prefs.storePreviewPreferences(previewPreferences);
entryEditor.updatePreviewInTabs(previewPreferences);
entryEditor.previousPreviewStyle();
}

/**
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,4 +411,20 @@ public void updatePreviewInTabs(PreviewPreferences previewPreferences) {
}
}
}

public void nextPreviewStyle() {
for (Tab tab : this.entryEditorTabs) {
if (tab instanceof FieldsEditorTab) {
((FieldsEditorTab) tab).previewPanel.nextPreviewStyle();
matthiasgeiger marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

public void previousPreviewStyle() {
for (Tab tab : this.entryEditorTabs) {
if (tab instanceof FieldsEditorTab) {
((FieldsEditorTab) tab).previewPanel.previousPreviewStyle();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private void initPanel() {
gridPane = new GridPane();
gridPane.getStyleClass().add("editorPane");

previewPanel = new PreviewPanel(databaseContext, null, dialogService, ExternalFileTypes.getInstance(), Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences());
previewPanel = new PreviewPanel(databaseContext, dialogService, ExternalFileTypes.getInstance(), Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences());

// Warp everything in a scroll-pane
ScrollPane scrollPane = new ScrollPane();
Expand Down
39 changes: 21 additions & 18 deletions src/main/java/org/jabref/gui/preview/PreviewPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import javafx.scene.layout.VBox;

import org.jabref.Globals;
import org.jabref.gui.BasePanel;
import org.jabref.gui.DialogService;
import org.jabref.gui.externalfiles.ExternalFilesEntryLinker;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
Expand All @@ -41,11 +40,9 @@ public class PreviewPanel extends VBox {
private final KeyBindingRepository keyBindingRepository;
private final PreviewViewer previewView;
private BibEntry entry;
private BasePanel basePanel;
private DialogService dialogService;

public PreviewPanel(BibDatabaseContext database, BasePanel basePanel, DialogService dialogService, ExternalFileTypes externalFileTypes, KeyBindingRepository keyBindingRepository, PreviewPreferences preferences) {
this.basePanel = basePanel;
public PreviewPanel(BibDatabaseContext database, DialogService dialogService, ExternalFileTypes externalFileTypes, KeyBindingRepository keyBindingRepository, PreviewPreferences preferences) {
this.keyBindingRepository = keyBindingRepository;
this.dialogService = dialogService;
fileLinker = new ExternalFilesEntryLinker(externalFileTypes, Globals.prefs.getFilePreferences(), database);
Expand Down Expand Up @@ -100,10 +97,6 @@ public PreviewPanel(BibDatabaseContext database, BasePanel basePanel, DialogServ
updateLayout(preferences, true);
}

public void close() {
basePanel.closeBottomPane();
}

public void updateLayout(PreviewPreferences previewPreferences) {
updateLayout(previewPreferences, false);
}
Expand All @@ -125,10 +118,6 @@ private void createKeyBindings() {
previewView.copyPreviewToClipBoard();
event.consume();
break;
case CLOSE:
close();
event.consume();
break;
default:
}
}
Expand All @@ -141,21 +130,19 @@ private ContextMenu createPopupMenu() {
copyPreview.setOnAction(event -> previewView.copyPreviewToClipBoard());
MenuItem printEntryPreview = new MenuItem(Localization.lang("Print entry preview"), IconTheme.JabRefIcons.PRINTED.getGraphicNode());
printEntryPreview.setOnAction(event -> previewView.print());
/* Deleted since it does not work anymore. Needs refactoring.
MenuItem previousPreviewLayout = new MenuItem(Localization.lang("Previous preview layout"));
previousPreviewLayout.setAccelerator(keyBindingRepository.getKeyCombination(KeyBinding.PREVIOUS_PREVIEW_LAYOUT));
previousPreviewLayout.setOnAction(event -> basePanel.previousPreviewStyle());
previousPreviewLayout.setOnAction(event -> this.previousPreviewStyle());
MenuItem nextPreviewLayout = new MenuItem(Localization.lang("Next preview layout"));
nextPreviewLayout.setAccelerator(keyBindingRepository.getKeyCombination(KeyBinding.NEXT_PREVIEW_LAYOUT));
nextPreviewLayout.setOnAction(event -> basePanel.nextPreviewStyle());
*/
nextPreviewLayout.setOnAction(event -> this.nextPreviewStyle());

ContextMenu menu = new ContextMenu();
menu.getItems().add(copyPreview);
menu.getItems().add(printEntryPreview);
menu.getItems().add(new SeparatorMenuItem());
// menu.getItems().add(nextPreviewLayout);
// menu.getItems().add(previousPreviewLayout);
menu.getItems().add(nextPreviewLayout);
menu.getItems().add(previousPreviewLayout);
return menu;
}

Expand All @@ -167,4 +154,20 @@ public void setEntry(BibEntry entry) {
public void print() {
previewView.print();
}

public void nextPreviewStyle() {
cyclePreview(Globals.prefs.getPreviewPreferences().getPreviewCyclePosition() + 1);
matthiasgeiger marked this conversation as resolved.
Show resolved Hide resolved
}

public void previousPreviewStyle() {
cyclePreview(Globals.prefs.getPreviewPreferences().getPreviewCyclePosition() - 1);
}

private void cyclePreview(int newPosition) {
PreviewPreferences previewPreferences = Globals.prefs.getPreviewPreferences()
.getBuilder()
.withPreviewCyclePosition(newPosition)
.build();
updateLayout(previewPreferences);
matthiasgeiger marked this conversation as resolved.
Show resolved Hide resolved
}
}
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