diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index 9a02d5adeca..f9663dfec8d 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -339,7 +339,7 @@ private List createTabs() { tabs.add(new RelatedArticlesTab(Globals.prefs)); // Source tab - sourceTab = new SourceTab(panel); + sourceTab = new SourceTab(panel.getBibDatabaseContext(), panel.getUndoManager(), Globals.prefs.getLatexFieldFormatterPreferences()); 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 07c28472823..6b61f9ccead 100644 --- a/src/main/java/org/jabref/gui/entryeditor/SourceTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/SourceTab.java @@ -14,8 +14,8 @@ import javafx.scene.control.Tooltip; import org.jabref.Globals; -import org.jabref.gui.BasePanel; import org.jabref.gui.IconTheme; +import org.jabref.gui.undo.CountingUndoManager; import org.jabref.gui.undo.NamedCompound; import org.jabref.gui.undo.UndoableChangeType; import org.jabref.gui.undo.UndoableFieldChange; @@ -24,10 +24,12 @@ import org.jabref.logic.bibtex.BibEntryWriter; import org.jabref.logic.bibtex.InvalidFieldValueException; import org.jabref.logic.bibtex.LatexFieldFormatter; +import org.jabref.logic.bibtex.LatexFieldFormatterPreferences; import org.jabref.logic.importer.ParserResult; 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; @@ -43,23 +45,24 @@ public class SourceTab extends EntryEditorTab { private static final Log LOGGER = LogFactory.getLog(SourceTab.class); + private final LatexFieldFormatterPreferences fieldFormatterPreferences; private final BibDatabaseMode mode; private UndoManager undoManager; private final ObjectProperty sourceIsValid = new SimpleObjectProperty<>(); private final ObservableRuleBasedValidator sourceValidator = new ObservableRuleBasedValidator(sourceIsValid); - public SourceTab(BasePanel panel) { - this.mode = panel.getBibDatabaseContext().getMode(); + public SourceTab(BibDatabaseContext bibDatabaseContext, CountingUndoManager undoManager, LatexFieldFormatterPreferences fieldFormatterPreferences) { + this.mode = bibDatabaseContext.getMode(); 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()); - this.undoManager = panel.getUndoManager(); + this.undoManager = undoManager; + this.fieldFormatterPreferences = fieldFormatterPreferences; } - private static String getSourceString(BibEntry entry, BibDatabaseMode type) throws IOException { + private static String getSourceString(BibEntry entry, BibDatabaseMode type, LatexFieldFormatterPreferences fieldFormatterPreferences) throws IOException { StringWriter stringWriter = new StringWriter(200); - LatexFieldFormatter formatter = LatexFieldFormatter - .buildIgnoreHashes(Globals.prefs.getLatexFieldFormatterPreferences()); + LatexFieldFormatter formatter = LatexFieldFormatter.buildIgnoreHashes(fieldFormatterPreferences); new BibEntryWriter(formatter, false).writeWithoutPrependedNewlines(entry, stringWriter, type); return stringWriter.getBuffer().toString(); @@ -68,8 +71,7 @@ private static String getSourceString(BibEntry entry, BibDatabaseMode type) thro private CodeArea createSourceEditor() { CodeArea codeArea = new CodeArea(); codeArea.setWrapText(true); - codeArea.lookup(".styled-text-area").setStyle( - "-fx-font-size: " + Globals.prefs.getFontSizeFX() + "pt;"); + codeArea.lookup(".styled-text-area").setStyle("-fx-font-size: " + Globals.prefs.getFontSizeFX() + "pt;"); return codeArea; } @@ -91,7 +93,7 @@ protected void bindToEntry(BibEntry entry) { sourceValidator.getValidationStatus().getHighestMessage().ifPresent(validationMessage -> notificationPane.show(validationMessage.getMessage())); } }); - this.setContent(notificationPane); + this.setContent(codeArea); // Store source for every change in the source code // and update source code for every change of entry field values @@ -99,7 +101,7 @@ protected void bindToEntry(BibEntry entry) { DefaultTaskExecutor.runInJavaFXThread(() -> { codeArea.clear(); try { - codeArea.appendText(getSourceString(entry, mode)); + codeArea.appendText(getSourceString(entry, mode, fieldFormatterPreferences)); } catch (IOException ex) { codeArea.setEditable(false); codeArea.appendText(ex.getMessage() + "\n\n" + diff --git a/src/main/java/org/jabref/gui/util/DefaultTaskExecutor.java b/src/main/java/org/jabref/gui/util/DefaultTaskExecutor.java index b27eacdd861..c812337e1b3 100644 --- a/src/main/java/org/jabref/gui/util/DefaultTaskExecutor.java +++ b/src/main/java/org/jabref/gui/util/DefaultTaskExecutor.java @@ -28,11 +28,7 @@ public class DefaultTaskExecutor implements TaskExecutor { public static V runInJavaFXThread(Callable callable) { FutureTask task = new FutureTask<>(callable); - if (!Platform.isFxApplicationThread()) { - Platform.runLater(task); - } else { - EXECUTOR.submit(task); - } + Platform.runLater(task); try { return task.get(); @@ -43,11 +39,7 @@ public static V runInJavaFXThread(Callable callable) { } public static void runInJavaFXThread(Runnable runnable) { - if (!Platform.isFxApplicationThread()) { - Platform.runLater(runnable); - } else { - EXECUTOR.submit(runnable); - } + Platform.runLater(runnable); } @Override