Skip to content

Commit

Permalink
Update source tab when an entry is changed (#3019)
Browse files Browse the repository at this point in the history
* Update source tab when an entry is changed

* Fix checkstyle errors

* Fix more checkstyle errors
  • Loading branch information
lenhard authored and Siedlerchr committed Jul 18, 2017
1 parent 7d31fa2 commit 3028d47
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We fixed a bug where the language files for Brazilian Portugese could not be loaded and the GUI localization remained in English [#1128](https://github.com/JabRef/jabref/issues/1182)
- We fixed a bug where the database was not marked as dirty when entries or groups were changed [#2787](https://github.com/JabRef/jabref/issues/2787)
- We restored the original functionality that when browsing through the MainTable, the Entry Editor remembers which tab was opened before [#2896](https://github.com/JabRef/jabref/issues/2896)
- We fixed a bug where the source tab was not updated when one the fields was changed [#2888](https://github.com/JabRef/jabref/issues/2888)

### Removed


Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ private void addTabs(String lastTabName) {
tabs.add(new RelatedArticlesTab(entry));

// Source tab
SourceTab sourceTab = new SourceTab(panel.getBibDatabaseContext().getMode(), entry);
SourceTab sourceTab = new SourceTab(panel.getBibDatabaseContext(), entry);
tabs.add(sourceTab);

tabbed.getTabs().clear();
Expand Down
23 changes: 21 additions & 2 deletions src/main/java/org/jabref/gui/entryeditor/SourceTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@
import org.jabref.logic.importer.fileformat.BibtexParser;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.InternalBibtexFields;
import org.jabref.model.entry.event.EntryChangedEvent;

import com.google.common.eventbus.Subscribe;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.fxmisc.easybind.EasyBind;
Expand All @@ -40,14 +43,30 @@ public class SourceTab extends EntryEditorTab {
private final BibEntry entry;
private CodeArea codeArea;

public SourceTab(BibDatabaseMode mode, BibEntry entry) {
this.mode = mode;
public SourceTab(BibDatabaseContext context, BibEntry entry) {
this.mode = context.getMode();
this.entry = entry;
context.getDatabase().registerListener(this);
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());
}

@Subscribe
public void listen(EntryChangedEvent event) {
if (this.entry.equals(event.getBibEntry())) {
try {
codeArea.clear();
codeArea.appendText(getSourceString(entry, mode));
} catch (IOException ex) {
codeArea.appendText(ex.getMessage() + "\n\n" +
Localization.lang("Correct the entry, and reopen editor to display/edit source."));
codeArea.setEditable(false);
LOGGER.debug("Incorrect entry", ex);
}
}
}

private static String getSourceString(BibEntry entry, BibDatabaseMode type) throws IOException {
StringWriter stringWriter = new StringWriter(200);
LatexFieldFormatter formatter = LatexFieldFormatter
Expand Down

0 comments on commit 3028d47

Please sign in to comment.