diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a344fdcdaf..9a5b8c89c03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - Crossreferenced entries are now used when a BibTex key is generated for an entry with empty fields. [#2811](https://github.com/JabRef/jabref/issues/2811) - We now set the WM_CLASS of the UI to org-jabref-JabRefMain to allow certain Un*x window managers to properly identify its windows - We changed the default paths for the OpenOffice/LibreOffice binaries to the default path for LibreOffice - +- We no longer create a new entry editor when selecting a new entry to increase performance. [#3187](https://github.com/JabRef/jabref/pull/3187) ### Fixed - We fixed the translation of \textendash in the entry preview [#3307](https://github.com/JabRef/jabref/issues/3307) diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 8d31ddfb8d6..692db1be4d1 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -1486,11 +1486,14 @@ public void showEntry(final BibEntry bibEntry) { * @return A suitable entry editor. */ public EntryEditor getEntryEditor(BibEntry entry) { - String lastTabName = ""; if (currentEditor != null) { - lastTabName = currentEditor.getVisibleTabName(); + currentEditor.setEntry(entry); + return currentEditor; + } else { + EntryEditor editor = new EntryEditor(this); + editor.setEntry(entry); + return editor; } - return new EntryEditor(frame, BasePanel.this, entry, lastTabName); } public EntryEditor getCurrentEditor() { diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index 77fac58979e..9bf06e46d7b 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -114,11 +114,11 @@ public class EntryEditor extends JPanel implements EntryContainer { /** * A reference to the entry this object works on. */ - private final BibEntry entry; + private BibEntry entry; /** * The currently displayed type */ - private final String displayedBibEntryType; + private String displayedBibEntryType; /** * The action concerned with closing the window. @@ -157,71 +157,57 @@ public class EntryEditor extends JPanel implements EntryContainer { * Indicates that we are about to go to the next or previous entry */ private final BooleanProperty movingToDifferentEntry = new SimpleBooleanProperty(); - private final EntryType entryType; + private EntryType entryType; private SourceTab sourceTab; + private final BorderLayout layout; + private TypeLabel typeLabel; - public EntryEditor(JabRefFrame frame, BasePanel panel, BibEntry entry, String lastTabName) { - this.frame = frame; + public EntryEditor(BasePanel panel) { + this.frame = panel.frame(); this.panel = panel; - this.entry = Objects.requireNonNull(entry); - entry.registerListener(this); - entryType = EntryTypes.getTypeOrDefault(entry.getType(), - this.frame.getCurrentBasePanel().getBibDatabaseContext().getMode()); - - displayedBibEntryType = entry.getType(); writeXmp = new WriteXMPEntryEditorAction(panel, this); - BorderLayout borderLayout = new BorderLayout(); - setLayout(borderLayout); - setupToolBar(); + layout = new BorderLayout(); + setLayout(layout); container = OS.LINUX ? new CustomJFXPanel() : new JFXPanel(); + // Create type-label + typeLabel = new TypeLabel(""); + setupToolBar(); + DefaultTaskExecutor.runInJavaFXThread(() -> + container.setScene(new Scene(tabbed)) + ); + add(container, BorderLayout.CENTER); - container.addKeyListener(new KeyAdapter() { + DefaultTaskExecutor.runInJavaFXThread(() -> { + EasyBind.subscribe(tabbed.getSelectionModel().selectedItemProperty(), tab -> { + EntryEditorTab activeTab = (EntryEditorTab) tab; + if (activeTab != null) { + activeTab.notifyAboutFocus(); + } + }); + }); - @Override - public void keyPressed(java.awt.event.KeyEvent e) { + setupKeyBindings(); + } + + public void setEntry(BibEntry entry) { + this.entry = Objects.requireNonNull(entry); + entry.registerListener(this); + entryType = EntryTypes.getTypeOrDefault(entry.getType(), + this.frame.getCurrentBasePanel().getBibDatabaseContext().getMode()); + + displayedBibEntryType = entry.getType(); - //We need to consume this event here to prevent the propgation of keybinding events back to the JFrame - Optional keyBinding = Globals.getKeyPrefs().mapToKeyBinding(e); - if (keyBinding.isPresent()) { - switch (keyBinding.get()) { - case CUT: - case COPY: - case PASTE: - case CLOSE_ENTRY_EDITOR: - case DELETE_ENTRY: - case SELECT_ALL: - case ENTRY_EDITOR_NEXT_PANEL: - case ENTRY_EDITOR_NEXT_PANEL_2: - case ENTRY_EDITOR_PREVIOUS_PANEL: - case ENTRY_EDITOR_PREVIOUS_PANEL_2: - e.consume(); - break; - default: - //do nothing - } - } - } - }); DefaultTaskExecutor.runInJavaFXThread(() -> { - addTabs(lastTabName); + addTabs(this.getVisibleTabName()); tabbed.setStyle("-fx-font-size: " + Globals.prefs.getFontSizeFX() + "pt;"); - container.setScene(new Scene(tabbed)); }); - add(container, BorderLayout.CENTER); - - EasyBind.subscribe(tabbed.getSelectionModel().selectedItemProperty(), tab -> { - EntryEditorTab activeTab = (EntryEditorTab) tab; - if (activeTab != null) { - activeTab.notifyAboutFocus(); - } - }); - - setupKeyBindings(); + TypedBibEntry typedEntry = new TypedBibEntry(entry, panel.getBibDatabaseContext().getMode()); + typeLabel.setText(typedEntry.getTypeForDisplay()); } @Subscribe @@ -288,6 +274,34 @@ private void selectLastUsedTab(String lastTabName) { * Set-up key bindings specific for the entry editor. */ private void setupKeyBindings() { + container.addKeyListener(new KeyAdapter() { + + @Override + public void keyPressed(java.awt.event.KeyEvent e) { + + //We need to consume this event here to prevent the propgation of keybinding events back to the JFrame + Optional keyBinding = Globals.getKeyPrefs().mapToKeyBinding(e); + if (keyBinding.isPresent()) { + switch (keyBinding.get()) { + case CUT: + case COPY: + case PASTE: + case CLOSE_ENTRY_EDITOR: + case DELETE_ENTRY: + case SELECT_ALL: + case ENTRY_EDITOR_NEXT_PANEL: + case ENTRY_EDITOR_NEXT_PANEL_2: + case ENTRY_EDITOR_PREVIOUS_PANEL: + case ENTRY_EDITOR_PREVIOUS_PANEL_2: + e.consume(); + break; + default: + //do nothing + } + } + } + }); + tabbed.addEventFilter(KeyEvent.KEY_PRESSED, event -> { Optional keyBinding = Globals.getKeyPrefs().mapToKeyBinding(event); if (keyBinding.isPresent()) { @@ -387,6 +401,7 @@ public BibDatabase getDatabase() { } private void setupToolBar() { + JPanel leftPan = new JPanel(); leftPan.setLayout(new BorderLayout()); JToolBar toolBar = new OSXCompatibleToolbar(SwingConstants.VERTICAL); @@ -426,9 +441,7 @@ private void setupToolBar() { closeBut.setMargin(new Insets(8, 0, 8, 0)); leftPan.add(closeBut, BorderLayout.NORTH); - // Create type-label - TypedBibEntry typedEntry = new TypedBibEntry(entry, panel.getBibDatabaseContext().getMode()); - leftPan.add(new TypeLabel(typedEntry.getTypeForDisplay()), BorderLayout.CENTER); + leftPan.add(typeLabel, BorderLayout.CENTER); TypeButton typeButton = new TypeButton(); toolBar.add(typeButton);