Skip to content

Commit 42c39cb

Browse files
lenhardSiedlerchr
authored andcommitted
Move event processing from source tab into entry editor (#3116)
1 parent 2763f51 commit 42c39cb

File tree

3 files changed

+18
-26
lines changed

3 files changed

+18
-26
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
1616
- Added 'Filter All' and 'Filter None' buttons with corresponding functionality to Quality Check tool.
1717

1818
### Fixed
19+
- We fixed a memory leak in the source tab of the entry editor [#3113](https://github.com/JabRef/jabref/issues/3113)
1920

2021
### Removed
2122

src/main/java/org/jabref/gui/entryeditor/EntryEditor.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
import org.jabref.model.database.BibDatabase;
7878
import org.jabref.model.entry.BibEntry;
7979
import org.jabref.model.entry.EntryType;
80+
import org.jabref.model.entry.event.EntryChangedEvent;
8081
import org.jabref.model.entry.event.FieldAddedOrRemovedEvent;
8182
import org.jabref.preferences.JabRefPreferences;
8283

@@ -225,6 +226,11 @@ public synchronized void listen(FieldAddedOrRemovedEvent event) {
225226
}
226227
}
227228

229+
@Subscribe
230+
public synchronized void listen(EntryChangedEvent event) {
231+
sourceTab.updateSourcePane();
232+
}
233+
228234
private void rebuildOtherFieldsTab() {
229235
int index = -1;
230236
boolean isOtherFieldsTabSelected = false;
@@ -526,9 +532,6 @@ public void setMovingToDifferentEntry() {
526532

527533
private void unregisterListeners() {
528534
this.entry.unregisterListener(this);
529-
if (sourceTab != null) {
530-
this.sourceTab.deregisterListeners();
531-
}
532535
removeSearchListeners();
533536

534537
}

src/main/java/org/jabref/gui/entryeditor/SourceTab.java

+11-23
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929
import org.jabref.model.database.BibDatabaseMode;
3030
import org.jabref.model.entry.BibEntry;
3131
import org.jabref.model.entry.InternalBibtexFields;
32-
import org.jabref.model.entry.event.EntryChangedEvent;
3332

34-
import com.google.common.eventbus.Subscribe;
3533
import org.apache.commons.logging.Log;
3634
import org.apache.commons.logging.LogFactory;
3735
import org.fxmisc.easybind.EasyBind;
@@ -52,7 +50,6 @@ public SourceTab(BasePanel panel, BibEntry entry, BooleanProperty movingToDiffer
5250
this.entry = entry;
5351
this.panel = panel;
5452
this.movingToDifferentEntry = movingToDifferentEntry;
55-
panel.getBibDatabaseContext().getDatabase().registerListener(this);
5653
this.setText(Localization.lang("%0 source", mode.getFormattedName()));
5754
this.setTooltip(new Tooltip(Localization.lang("Show/edit %0 source", mode.getFormattedName())));
5855
this.setGraphic(IconTheme.JabRefIcon.SOURCE.getGraphicNode());
@@ -67,26 +64,17 @@ private static String getSourceString(BibEntry entry, BibDatabaseMode type) thro
6764
return stringWriter.getBuffer().toString();
6865
}
6966

70-
@Subscribe
71-
public void listen(EntryChangedEvent event) {
72-
if (codeArea != null && this.entry.equals(event.getBibEntry())) {
73-
DefaultTaskExecutor.runInJavaFXThread(() -> updateSourcePane());
74-
}
75-
}
76-
77-
public void deregisterListeners() {
78-
this.entry.unregisterListener(this);
79-
}
80-
81-
private void updateSourcePane() {
82-
try {
83-
codeArea.clear();
84-
codeArea.appendText(getSourceString(entry, mode));
85-
} catch (IOException ex) {
86-
codeArea.appendText(ex.getMessage() + "\n\n" +
87-
Localization.lang("Correct the entry, and reopen editor to display/edit source."));
88-
codeArea.setEditable(false);
89-
LOGGER.debug("Incorrect entry", ex);
67+
public void updateSourcePane() {
68+
if (codeArea != null) {
69+
try {
70+
codeArea.clear();
71+
codeArea.appendText(getSourceString(entry, mode));
72+
} catch (IOException ex) {
73+
codeArea.appendText(ex.getMessage() + "\n\n" +
74+
Localization.lang("Correct the entry, and reopen editor to display/edit source."));
75+
codeArea.setEditable(false);
76+
LOGGER.debug("Incorrect entry", ex);
77+
}
9078
}
9179
}
9280

0 commit comments

Comments
 (0)