Skip to content

Commit

Permalink
Merge pull request #5218 from JabRef/preview-in-entryeditor
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusDietz authored Aug 24, 2019
2 parents 8f463e4 + 66fcbb1 commit cb4b011
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 146 deletions.
103 changes: 14 additions & 89 deletions src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
import org.jabref.gui.mergeentries.MergeEntriesAction;
import org.jabref.gui.mergeentries.MergeWithFetchedEntryAction;
import org.jabref.gui.preview.CitationStyleToClipboardWorker;
import org.jabref.gui.preview.PreviewPanel;
import org.jabref.gui.specialfields.SpecialFieldDatabaseChangeListener;
import org.jabref.gui.specialfields.SpecialFieldValueViewModel;
import org.jabref.gui.specialfields.SpecialFieldViewModel;
Expand Down Expand Up @@ -122,7 +121,6 @@ public class BasePanel extends StackPane {
// Keeps track of the string dialog if it is open.
private final Map<Actions, BaseAction> actions = new HashMap<>();
private final SidePaneManager sidePaneManager;
private final PreviewPanel preview;
private final BasePanelPreferences preferences;
private final ExternalFileTypes externalFileTypes;

Expand Down Expand Up @@ -179,8 +177,6 @@ public BasePanel(JabRefFrame frame, BasePanelPreferences preferences, BibDatabas
this.getDatabase().registerListener(new UpdateTimestampListener(Globals.prefs));

this.entryEditor = new EntryEditor(this, externalFileTypes);

this.preview = new PreviewPanel(getBibDatabaseContext(), this, dialogService, externalFileTypes, Globals.getKeyPrefs(), preferences.getPreviewPreferences());
}

@Subscribe
Expand Down Expand Up @@ -263,8 +259,6 @@ private void setupActions() {
// The action for copying selected entries.
actions.put(Actions.COPY, this::copy);

actions.put(Actions.PRINT_PREVIEW, new PrintPreviewAction());

actions.put(Actions.CUT, this::cut);

actions.put(Actions.DELETE, () -> delete(false));
Expand Down Expand Up @@ -358,19 +352,6 @@ private void setupActions() {
new SpecialFieldViewModel(SpecialField.READ_STATUS, undoManager).getSpecialFieldAction(status, this.frame));
}

actions.put(Actions.TOGGLE_PREVIEW, () -> {
PreviewPreferences previewPreferences = Globals.prefs.getPreviewPreferences();
boolean enabled = !previewPreferences.isPreviewPanelEnabled();
PreviewPreferences newPreviewPreferences = previewPreferences.getBuilder()
.withPreviewPanelEnabled(enabled)
.build();
Globals.prefs.storePreviewPreferences(newPreviewPreferences);
setPreviewActive(enabled);
});

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 @@ -679,7 +660,6 @@ private void createMainTable() {
.stream()
.findFirst()
.ifPresent(entry -> {
preview.setEntry(entry);
entryEditor.setEntry(entry);
}));

Expand Down Expand Up @@ -816,9 +796,7 @@ private void instantiateSearchAutoCompleter() {
}

private void adjustSplitter() {
if (mode == BasePanelMode.SHOWING_PREVIEW) {
splitPane.setDividerPositions(Globals.prefs.getPreviewPreferences().getPreviewPanelDividerPosition().doubleValue());
} else if (mode == BasePanelMode.SHOWING_EDITOR) {
if (mode == BasePanelMode.SHOWING_EDITOR) {
splitPane.setDividerPositions(preferences.getEntryEditorDividerPosition());
}
}
Expand All @@ -844,17 +822,11 @@ public void showAndEdit(BibEntry entry) {
}

private void showBottomPane(BasePanelMode newMode) {
Node pane;
switch (newMode) {
case SHOWING_PREVIEW:
pane = preview;
break;
case SHOWING_EDITOR:
pane = entryEditor;
break;
default:
throw new UnsupportedOperationException("new mode not recognized: " + newMode.name());
if (newMode != BasePanelMode.SHOWING_EDITOR) {
throw new UnsupportedOperationException("new mode not recognized: " + newMode.name());
}
Node pane = entryEditor;

if (splitPane.getItems().size() == 2) {
splitPane.getItems().set(1, pane);
} else {
Expand All @@ -870,23 +842,6 @@ private void showAndEdit() {
}
}

/**
* Sets the given preview panel as the bottom component in the split panel. Updates the mode to SHOWING_PREVIEW.
*
* @param entry The entry to show in the preview.
*/
private void showPreview(BibEntry entry) {
showBottomPane(BasePanelMode.SHOWING_PREVIEW);

preview.setEntry(entry);
}

private void showPreview() {
if (!mainTable.getSelectedEntries().isEmpty()) {
showPreview(mainTable.getSelectedEntries().get(0));
}
}

public void nextPreviewStyle() {
cyclePreview(Globals.prefs.getPreviewPreferences().getPreviewCyclePosition() + 1);
}
Expand All @@ -901,16 +856,15 @@ private void cyclePreview(int newPosition) {
.withPreviewCyclePosition(newPosition)
.build();
Globals.prefs.storePreviewPreferences(previewPreferences);

preview.updateLayout(previewPreferences);
entryEditor.updatePreviewInTabs(previewPreferences);
}

/**
* Removes the bottom component.
*/
public void closeBottomPane() {
mode = BasePanelMode.SHOWING_NOTHING;
splitPane.getItems().removeAll(entryEditor, preview);
splitPane.getItems().remove(entryEditor);
}

/**
Expand All @@ -932,23 +886,17 @@ public void selectNextEntry() {
/**
* This method is called from an EntryEditor when it should be closed. We relay to the selection listener, which
* takes care of the rest.
*
* @param editor The entry editor to close.
*/
public void entryEditorClosing(EntryEditor editor) {
if (Globals.prefs.getPreviewPreferences().isPreviewPanelEnabled()) {
showPreview(editor.getEntry());
} else {
closeBottomPane();
}
public void entryEditorClosing() {
closeBottomPane();
mainTable.requestFocus();
}

/**
* Closes the entry editor or preview panel if it is showing the given entry.
* Closes the entry editor if it is showing the given entry.
*/
public void ensureNotShowingBottomPanel(BibEntry entry) {
if (((mode == BasePanelMode.SHOWING_EDITOR) && (entryEditor.getEntry() == entry)) || ((mode == BasePanelMode.SHOWING_PREVIEW))) {
private void ensureNotShowingBottomPanel(BibEntry entry) {
if (((mode == BasePanelMode.SHOWING_EDITOR) && (entryEditor.getEntry() == entry))) {
closeBottomPane();
}
}
Expand Down Expand Up @@ -996,7 +944,7 @@ public BibDatabase getDatabase() {
return bibDatabaseContext.getDatabase();
}

public boolean showDeleteConfirmationDialog(int numberOfEntries) {
private boolean showDeleteConfirmationDialog(int numberOfEntries) {
if (Globals.prefs.getBoolean(JabRefPreferences.CONFIRM_DELETE)) {
String title = Localization.lang("Delete entry");
String message = Localization.lang("Really delete the selected entry?");
Expand Down Expand Up @@ -1029,13 +977,7 @@ private void saveDividerLocation(Number position) {
return;
}

if (mode == BasePanelMode.SHOWING_PREVIEW) {
PreviewPreferences previewPreferences = Globals.prefs.getPreviewPreferences()
.getBuilder()
.withPreviewPanelDividerPosition(position)
.build();
Globals.prefs.storePreviewPreferences(previewPreferences);
} else if (mode == BasePanelMode.SHOWING_EDITOR) {
if (mode == BasePanelMode.SHOWING_EDITOR) {
preferences.setEntryEditorDividerPosition(position.doubleValue());
}
}
Expand Down Expand Up @@ -1093,14 +1035,6 @@ public String formatOutputMessage(String start, int count) {
return String.format("%s %d %s.", start, count, (count > 1 ? Localization.lang("entries") : Localization.lang("entry")));
}

private void setPreviewActive(boolean enabled) {
if (enabled) {
showPreview();
} else {
preview.close();
}
}

public CountingUndoManager getUndoManager() {
return undoManager;
}
Expand Down Expand Up @@ -1353,13 +1287,4 @@ public void action() {
markChangedOrUnChanged();
}
}

private class PrintPreviewAction implements BaseAction {

@Override
public void action() {
showPreview();
preview.print();
}
}
}
1 change: 0 additions & 1 deletion src/main/java/org/jabref/gui/BasePanelMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

public enum BasePanelMode {
SHOWING_NOTHING,
SHOWING_PREVIEW,
SHOWING_EDITOR,
WILL_SHOW_EDITOR
}
1 change: 0 additions & 1 deletion src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,6 @@ private MenuBar createMenu() {

new SeparatorMenuItem(),

factory.createCheckMenuItem(StandardActions.TOGGLE_PREVIEW, new OldDatabaseCommandWrapper(Actions.TOGGLE_PREVIEW, this, stateManager), Globals.prefs.getPreviewPreferences().isPreviewPanelEnabled()),
factory.createMenuItem(StandardActions.NEXT_PREVIEW_STYLE, new OldDatabaseCommandWrapper(Actions.NEXT_PREVIEW_STYLE, this, stateManager)),
factory.createMenuItem(StandardActions.PREVIOUS_PREVIEW_STYLE, new OldDatabaseCommandWrapper(Actions.PREVIOUS_PREVIEW_STYLE, this, stateManager)),

Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/jabref/gui/actions/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public enum Actions {
SELECT_ALL,
SEND_AS_EMAIL,
TOGGLE_GROUPS,
TOGGLE_PREVIEW,
UNABBREVIATE,
UNDO,
WRITE_XMP,
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/jabref/gui/actions/StandardActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ public enum StandardActions implements Action {

EDIT_ENTRY(Localization.lang("Open entry editor"), IconTheme.JabRefIcons.EDIT_ENTRY, KeyBinding.EDIT_ENTRY),
SHOW_PDF_VIEWER(Localization.lang("Open document viewer"), IconTheme.JabRefIcons.PDF_FILE),
TOGGLE_PREVIEW(Localization.lang("Entry preview"), IconTheme.JabRefIcons.TOGGLE_ENTRY_PREVIEW, KeyBinding.TOGGLE_ENTRY_PREVIEW),
NEXT_PREVIEW_STYLE(Localization.lang("Next citation style"), KeyBinding.NEXT_PREVIEW_LAYOUT),
PREVIOUS_PREVIEW_STYLE(Localization.lang("Previous citation style"), KeyBinding.PREVIOUS_PREVIEW_LAYOUT),
SELECT_ALL(Localization.lang("Select all"), KeyBinding.SELECT_ALL),
Expand Down
37 changes: 23 additions & 14 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
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 @@ -88,6 +89,7 @@ public class EntryEditor extends BorderPane {
@Inject private StateManager stateManager;
@Inject private FileUpdateMonitor fileMonitor;
@Inject private CountingUndoManager undoManager;
private final List<EntryEditorTab> entryEditorTabs = new LinkedList<>();

public EntryEditor(BasePanel panel, ExternalFileTypes externalFileTypes) {
this.panel = panel;
Expand Down Expand Up @@ -235,7 +237,7 @@ private void setupKeyBindings() {

@FXML
public void close() {
panel.entryEditorClosing(EntryEditor.this);
panel.entryEditorClosing();
}

@FXML
Expand All @@ -261,40 +263,39 @@ private void navigateToNextEntry() {
}

private List<EntryEditorTab> createTabs() {
List<EntryEditorTab> tabs = new LinkedList<>();

// Required fields
tabs.add(new RequiredFieldsTab(databaseContext, panel.getSuggestionProviders(), undoManager, dialogService));
entryEditorTabs.add(new RequiredFieldsTab(databaseContext, panel.getSuggestionProviders(), undoManager, dialogService));

// Optional fields
tabs.add(new OptionalFieldsTab(databaseContext, panel.getSuggestionProviders(), undoManager, dialogService));
tabs.add(new OptionalFields2Tab(databaseContext, panel.getSuggestionProviders(), undoManager, dialogService));
tabs.add(new DeprecatedFieldsTab(databaseContext, panel.getSuggestionProviders(), undoManager, dialogService));
entryEditorTabs.add(new OptionalFieldsTab(databaseContext, panel.getSuggestionProviders(), undoManager, dialogService));
entryEditorTabs.add(new OptionalFields2Tab(databaseContext, panel.getSuggestionProviders(), undoManager, dialogService));
entryEditorTabs.add(new DeprecatedFieldsTab(databaseContext, panel.getSuggestionProviders(), undoManager, dialogService));

// Other fields
tabs.add(new OtherFieldsTab(databaseContext, panel.getSuggestionProviders(), undoManager,
entryEditorTabs.add(new OtherFieldsTab(databaseContext, panel.getSuggestionProviders(), undoManager,
entryEditorPreferences.getCustomTabFieldNames(), dialogService));

// General fields from preferences
for (Map.Entry<String, Set<Field>> tab : entryEditorPreferences.getEntryEditorTabList().entrySet()) {
tabs.add(new UserDefinedFieldsTab(tab.getKey(), tab.getValue(), databaseContext, panel.getSuggestionProviders(), undoManager, dialogService));
entryEditorTabs.add(new UserDefinedFieldsTab(tab.getKey(), tab.getValue(), databaseContext, panel.getSuggestionProviders(), undoManager, dialogService));
}

// Special tabs
tabs.add(new MathSciNetTab());
tabs.add(new FileAnnotationTab(panel.getAnnotationCache()));
tabs.add(new RelatedArticlesTab(this, entryEditorPreferences, dialogService));
entryEditorTabs.add(new MathSciNetTab());
entryEditorTabs.add(new FileAnnotationTab(panel.getAnnotationCache()));
entryEditorTabs.add(new RelatedArticlesTab(this, entryEditorPreferences, dialogService));

// Source tab
sourceTab = new SourceTab(databaseContext, undoManager,
entryEditorPreferences.getLatexFieldFormatterPreferences(),
entryEditorPreferences.getImportFormatPreferences(), fileMonitor, dialogService, stateManager);
tabs.add(sourceTab);
entryEditorTabs.add(sourceTab);

// LaTeX citations tab
tabs.add(new LatexCitationsTab(databaseContext, preferencesService, taskExecutor, dialogService));
entryEditorTabs.add(new LatexCitationsTab(databaseContext, preferencesService, taskExecutor, dialogService));

return tabs;
return entryEditorTabs;
}

private void recalculateVisibleTabs() {
Expand Down Expand Up @@ -402,4 +403,12 @@ public void setFocusToField(Field field) {
}
});
}

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

0 comments on commit cb4b011

Please sign in to comment.