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 all 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
25 changes: 7 additions & 18 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,13 @@ private void setupActions() {
new SpecialFieldViewModel(SpecialField.READ_STATUS, undoManager).getSpecialFieldAction(status, this.frame));
}

actions.put(Actions.NEXT_PREVIEW_STYLE, () -> {
entryEditor.nextPreviewStyle();
});
actions.put(Actions.PREVIOUS_PREVIEW_STYLE, () -> {
entryEditor.previousPreviewStyle();
});

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

actions.put(Actions.WRITE_XMP, new WriteXMPAction(this)::execute);
Expand Down Expand Up @@ -844,23 +850,6 @@ private void showAndEdit() {
}
}

public void nextPreviewStyle() {
cyclePreview(Globals.prefs.getPreviewPreferences().getPreviewCyclePosition() + 1);
}

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

/**
* Removes the bottom component.
*/
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import org.jabref.model.entry.field.Field;
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.PreferencesService;
import org.jabref.preferences.PreviewPreferences;

import com.airhacks.afterburner.views.ViewLoader;
import org.fxmisc.easybind.EasyBind;
Expand Down Expand Up @@ -404,11 +403,11 @@ public void setFocusToField(Field field) {
});
}

public void updatePreviewInTabs(PreviewPreferences previewPreferences) {
for (Tab tab : this.entryEditorTabs) {
if (tab instanceof FieldsEditorTab) {
((FieldsEditorTab) tab).previewPanel.updateLayout(previewPreferences);
}
}
public void nextPreviewStyle() {
this.entryEditorTabs.forEach(EntryEditorTab::nextPreviewStyle);
}

public void previousPreviewStyle() {
this.entryEditorTabs.forEach(EntryEditorTab::previousPreviewStyle);
}
}
14 changes: 14 additions & 0 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditorTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,18 @@ public void notifyAboutFocus(BibEntry entry) {
handleFocus();
}

/**
* Switch to next Preview style - should be overriden if a EntryEditorTab is actually showing a preview
*/
protected void nextPreviewStyle() {
// do nothing by default
}

/**
* Switch to previous Preview style - should be overriden if a EntryEditorTab is actually showing a preview
*/
protected void previousPreviewStyle() {
// do nothing by default
}

}
14 changes: 12 additions & 2 deletions src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
* A single tab displayed in the EntryEditor holding several FieldEditors.
*/
abstract class FieldsEditorTab extends EntryEditorTab {
public PreviewPanel previewPanel;
protected final BibDatabaseContext databaseContext;
private final Map<Field, FieldEditorFX> editors = new LinkedHashMap<>();
private final boolean isCompressed;
private final SuggestionProviders suggestionProviders;
private final DialogService dialogService;
private PreviewPanel previewPanel;
private FieldEditorFX activeField;
private UndoManager undoManager;
private Collection<Field> fields = new ArrayList<>();
Expand Down Expand Up @@ -197,6 +197,16 @@ protected void bindToEntry(BibEntry entry) {
});
}

@Override
protected void nextPreviewStyle() {
previewPanel.nextPreviewStyle();
}

@Override
protected void previousPreviewStyle() {
previewPanel.previousPreviewStyle();
}

protected abstract SortedSet<Field> determineFieldsToShow(BibEntry entry);

public Collection<Field> getShownFields() {
Expand All @@ -208,7 +218,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);

// Warp everything in a scroll-pane
ScrollPane scrollPane = new ScrollPane();
Expand Down
50 changes: 29 additions & 21 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 @@ -28,6 +27,7 @@
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.preferences.PreviewPreferences;

import org.slf4j.Logger;
Expand All @@ -40,18 +40,19 @@ public class PreviewPanel extends VBox {
private final ExternalFilesEntryLinker fileLinker;
private final KeyBindingRepository keyBindingRepository;
private final PreviewViewer previewView;
private final JabRefPreferences preferences;
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, JabRefPreferences preferences) {
this.keyBindingRepository = keyBindingRepository;
this.dialogService = dialogService;
fileLinker = new ExternalFilesEntryLinker(externalFileTypes, Globals.prefs.getFilePreferences(), database);
this.preferences = preferences;
fileLinker = new ExternalFilesEntryLinker(externalFileTypes, preferences.getFilePreferences(), database);

PreviewPreferences previewPreferences = preferences.getPreviewPreferences();
previewView = new PreviewViewer(database, dialogService, Globals.stateManager);
previewView.setLayout(preferences.getCurrentPreviewStyle());
previewView.setLayout(previewPreferences.getCurrentPreviewStyle());
previewView.setContextMenu(createPopupMenu());
previewView.setOnDragDetected(event -> {
previewView.startFullDrag();
Expand Down Expand Up @@ -97,11 +98,7 @@ public PreviewPanel(BibDatabaseContext database, BasePanel basePanel, DialogServ
this.getChildren().add(previewView);

createKeyBindings();
updateLayout(preferences, true);
}

public void close() {
basePanel.closeBottomPane();
updateLayout(previewPreferences, true);
}

public void updateLayout(PreviewPreferences previewPreferences) {
Expand All @@ -111,6 +108,7 @@ public void updateLayout(PreviewPreferences previewPreferences) {
private void updateLayout(PreviewPreferences previewPreferences, boolean init) {
PreviewLayout currentPreviewStyle = previewPreferences.getCurrentPreviewStyle();
previewView.setLayout(currentPreviewStyle);
preferences.storePreviewPreferences(previewPreferences);
if (!init) {
dialogService.notify(Localization.lang("Preview style changed to: %0", currentPreviewStyle.getName()));
}
Expand All @@ -125,10 +123,6 @@ private void createKeyBindings() {
previewView.copyPreviewToClipBoard();
event.consume();
break;
case CLOSE:
close();
event.consume();
break;
default:
}
}
Expand All @@ -141,21 +135,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 +159,20 @@ public void setEntry(BibEntry entry) {
public void print() {
previewView.print();
}

public void nextPreviewStyle() {
cyclePreview(preferences.getPreviewPreferences().getPreviewCyclePosition() + 1);
}

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

private void cyclePreview(int newPosition) {
PreviewPreferences previewPreferences = preferences.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