diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a0202f45b9..5e43533d6ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - We improved font rendering of the Entry Editor for Linux based systems [#3295](https://github.com/JabRef/jabref/issues/3295) - We fixed an issue where JabRef would freeze when trying to replace the original entry after a merge with new information from identifiers like DOI/ISBN etc. [3294](https://github.com/JabRef/jabref/issues/3294) - We fixed an issue where JabRef would not show the translated content at some points, although there existed a translation + - We fixed an issue where editing in the source tab would override content of other entries [#3352](https://github.com/JabRef/jabref/issues/3352#issue-268580818) ### Removed diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index 27c823bde94..b663ace6e7f 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -346,7 +346,7 @@ private List createTabs() { tabs.add(new RelatedArticlesTab(Globals.prefs)); // Source tab - sourceTab = new SourceTab(panel, movingToDifferentEntry); + sourceTab = new SourceTab(panel); tabs.add(sourceTab); return tabs; } diff --git a/src/main/java/org/jabref/gui/entryeditor/SourceTab.java b/src/main/java/org/jabref/gui/entryeditor/SourceTab.java index c90591db99f..53ca21e8f98 100644 --- a/src/main/java/org/jabref/gui/entryeditor/SourceTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/SourceTab.java @@ -8,7 +8,6 @@ import javax.swing.undo.UndoManager; -import javafx.beans.property.BooleanProperty; import javafx.scene.Node; import javafx.scene.control.Tooltip; @@ -20,7 +19,6 @@ import org.jabref.gui.undo.NamedCompound; import org.jabref.gui.undo.UndoableChangeType; import org.jabref.gui.undo.UndoableFieldChange; -import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.logic.bibtex.BibEntryWriter; import org.jabref.logic.bibtex.InvalidFieldValueException; import org.jabref.logic.bibtex.LatexFieldFormatter; @@ -44,13 +42,11 @@ public class SourceTab extends EntryEditorTab { private final BibDatabaseMode mode; private final BasePanel panel; private CodeArea codeArea; - private BooleanProperty movingToDifferentEntry; private UndoManager undoManager; - public SourceTab(BasePanel panel, BooleanProperty movingToDifferentEntry) { + public SourceTab(BasePanel panel) { this.mode = panel.getBibDatabaseContext().getMode(); this.panel = panel; - this.movingToDifferentEntry = movingToDifferentEntry; this.setText(Localization.lang("%0 source", mode.getFormattedName())); this.setTooltip(new Tooltip(Localization.lang("Show/edit %0 source", mode.getFormattedName()))); this.setGraphic(IconTheme.JabRefIcon.SOURCE.getGraphicNode()); @@ -80,7 +76,7 @@ public void updateSourcePane(BibEntry entry) { } } - private Node createSourceEditor(BibEntry entry, BibDatabaseMode mode) { + private Node createSourceEditor(BibDatabaseMode mode) { codeArea = new CodeArea(); codeArea.setWrapText(true); codeArea.lookup(".styled-text-area").setStyle( @@ -88,19 +84,12 @@ private Node createSourceEditor(BibEntry entry, BibDatabaseMode mode) { // store source if new tab is selected (if this one is not focused anymore) EasyBind.subscribe(codeArea.focusedProperty(), focused -> { if (!focused) { - storeSource(entry); - } - }); - - // store source if new entry is selected in the maintable and the source tab is focused - EasyBind.subscribe(movingToDifferentEntry, newEntrySelected -> { - if (newEntrySelected && codeArea.focusedProperty().get()) { - DefaultTaskExecutor.runInJavaFXThread(() -> storeSource(entry)); + storeSource(); } }); try { - String srcString = getSourceString(entry, mode); + String srcString = getSourceString(this.currentEntry, mode); codeArea.appendText(srcString); } catch (IOException ex) { codeArea.appendText(ex.getMessage() + "\n\n" + @@ -126,10 +115,10 @@ public boolean shouldShow(BibEntry entry) { @Override protected void bindToEntry(BibEntry entry) { - this.setContent(createSourceEditor(entry, mode)); + this.setContent(createSourceEditor(mode)); } - private void storeSource(BibEntry entry) { + private void storeSource() { if (codeArea.getText().isEmpty()) { return; } @@ -157,42 +146,42 @@ private void storeSource(BibEntry entry) { String newKey = newEntry.getCiteKeyOptional().orElse(null); if (newKey != null) { - entry.setCiteKey(newKey); + currentEntry.setCiteKey(newKey); } else { - entry.clearCiteKey(); + currentEntry.clearCiteKey(); } // First, remove fields that the user has removed. - for (Map.Entry field : entry.getFieldMap().entrySet()) { + for (Map.Entry field : currentEntry.getFieldMap().entrySet()) { String fieldName = field.getKey(); String fieldValue = field.getValue(); if (InternalBibtexFields.isDisplayableField(fieldName) && !newEntry.hasField(fieldName)) { compound.addEdit( - new UndoableFieldChange(entry, fieldName, fieldValue, null)); - entry.clearField(fieldName); + new UndoableFieldChange(currentEntry, fieldName, fieldValue, null)); + currentEntry.clearField(fieldName); } } // Then set all fields that have been set by the user. for (Map.Entry field : newEntry.getFieldMap().entrySet()) { String fieldName = field.getKey(); - String oldValue = entry.getField(fieldName).orElse(null); + String oldValue = currentEntry.getField(fieldName).orElse(null); String newValue = field.getValue(); if (!Objects.equals(oldValue, newValue)) { // Test if the field is legally set. new LatexFieldFormatter(Globals.prefs.getLatexFieldFormatterPreferences()) .format(newValue, fieldName); - compound.addEdit(new UndoableFieldChange(entry, fieldName, oldValue, newValue)); - entry.setField(fieldName, newValue); + compound.addEdit(new UndoableFieldChange(currentEntry, fieldName, oldValue, newValue)); + currentEntry.setField(fieldName, newValue); } } // See if the user has changed the entry type: - if (!Objects.equals(newEntry.getType(), entry.getType())) { - compound.addEdit(new UndoableChangeType(entry, entry.getType(), newEntry.getType())); - entry.setType(newEntry.getType()); + if (!Objects.equals(newEntry.getType(), currentEntry.getType())) { + compound.addEdit(new UndoableChangeType(currentEntry, currentEntry.getType(), newEntry.getType())); + currentEntry.setType(newEntry.getType()); } compound.end(); undoManager.addEdit(compound); @@ -213,7 +202,7 @@ private void storeSource(BibEntry entry) { if (!keepEditing) { // Revert try { - codeArea.replaceText(0, codeArea.getText().length(), getSourceString(entry, mode)); + codeArea.replaceText(0, codeArea.getText().length(), getSourceString(this.currentEntry, mode)); } catch (IOException e) { LOGGER.debug("Incorrect source", e); }