Skip to content

Commit

Permalink
Reenable prevcycle (#5385)
Browse files Browse the repository at this point in the history
* fixes 5369 - fallback to 0 in case stored preview cycle pos does no longer exist

* reenable preview cycling

* remove ref to BasePanel

* unused imports

* update changelog

* incorporated suggestions

* add next/previousPreviewStyle() to EntryEditorTab

* checkstyle...
  • Loading branch information
matthiasgeiger authored Oct 6, 2019
1 parent 2160229 commit 875b48e
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 48 deletions.
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);
}
}

0 comments on commit 875b48e

Please sign in to comment.