diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index 3a55ae29395..7e99897cadb 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -69,7 +69,6 @@ import com.tobiasdiez.easybind.EasyBind; import com.tobiasdiez.easybind.Subscription; import jakarta.inject.Inject; -import org.fxmisc.richtext.CodeArea; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -475,8 +474,4 @@ public void nextPreviewStyle() { public void previousPreviewStyle() { this.previewTabs.forEach(OffersPreview::previousPreviewStyle); } - - public CodeArea getEntrySource(BibEntry entry) { - return sourceTab.getEntryCodeArea(entry); - } } diff --git a/src/main/java/org/jabref/gui/entryeditor/SourceTab.java b/src/main/java/org/jabref/gui/entryeditor/SourceTab.java index d01c9eee7d1..6161e3a24ed 100644 --- a/src/main/java/org/jabref/gui/entryeditor/SourceTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/SourceTab.java @@ -347,16 +347,4 @@ private void listenForSaveKeybinding(KeyEvent event) { } }); } - - public CodeArea getEntryCodeArea(BibEntry entry) { - CodeArea ca = new CodeArea(); - try { - ca.appendText(getSourceString(entry, mode, fieldPreferences)); - } catch ( - IOException ex) { - ca = null; - LOGGER.debug("Incorrect entry", ex); - } - return ca; - } } diff --git a/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java b/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java index ddedebf31ca..b40be634892 100644 --- a/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java @@ -1,10 +1,10 @@ package org.jabref.gui.entryeditor.citationrelationtab; import java.io.IOException; +import java.io.StringWriter; import java.net.URI; import java.util.Arrays; import java.util.List; -import java.util.function.Supplier; import javax.swing.undo.UndoManager; @@ -40,15 +40,18 @@ import org.jabref.gui.entryeditor.citationrelationtab.semanticscholar.SemanticScholarFetcher; import org.jabref.gui.icon.IconTheme; import org.jabref.gui.preferences.GuiPreferences; -import org.jabref.gui.undo.RedoAction; -import org.jabref.gui.undo.UndoAction; import org.jabref.gui.util.NoSelectionModel; import org.jabref.gui.util.ViewModelListCellFactory; +import org.jabref.logic.bibtex.BibEntryWriter; +import org.jabref.logic.bibtex.FieldWriter; import org.jabref.logic.database.DuplicateCheck; +import org.jabref.logic.exporter.BibWriter; import org.jabref.logic.l10n.Localization; +import org.jabref.logic.os.OS; import org.jabref.logic.util.BackgroundTask; import org.jabref.logic.util.TaskExecutor; import org.jabref.model.database.BibDatabaseContext; +import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.database.BibDatabaseModeDetection; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.BibEntryTypesManager; @@ -269,10 +272,9 @@ private void styleFetchedListView(CheckListView listView) } Button showEntrySource = IconTheme.JabRefIcons.SOURCE.asButton(); - showEntrySource.setTooltip(new Tooltip(Localization.lang("Show %0 source", databaseContext.getMode().getFormattedName()))); + showEntrySource.setTooltip(new Tooltip(Localization.lang("%0 source", databaseContext.getMode().getFormattedName()))); showEntrySource.setOnMouseClicked(event -> { - this.entryEditor = createEntryEditor(); - showEntrySourceDialog(this.entryEditor.getEntrySource(entry.entry())); + showEntrySourceDialog(entry.entry()); }); vContainer.getChildren().addLast(showEntrySource); @@ -293,35 +295,38 @@ private void styleFetchedListView(CheckListView listView) listView.setSelectionModel(new NoSelectionModel<>()); } - private EntryEditor createEntryEditor() { - Supplier tabSupplier = () -> this.libraryTab; - return new EntryEditor(this.libraryTab, - // Actions are recreated here since this avoids passing more parameters and the amount of additional memory consumption is neglegtable. - new UndoAction(tabSupplier, dialogService, stateManager), - new RedoAction(tabSupplier, dialogService, stateManager)); + private String getSourceString(BibEntry entry, BibDatabaseMode type) throws IOException { + StringWriter writer = new StringWriter(); + BibWriter bibWriter = new BibWriter(writer, OS.NEWLINE); + FieldWriter fieldWriter = FieldWriter.buildIgnoreHashes(this.preferences.getFieldPreferences()); + new BibEntryWriter(fieldWriter, new BibEntryTypesManager()).write(entry, bibWriter, type); + return writer.toString(); } - private void showEntrySourceDialog(CodeArea codeArea) { - if (codeArea == null) { - dialogService.showWarningDialogAndWait(Localization.lang("BibTeX source", databaseContext.getMode().getFormattedName()), Localization.lang("Could not load %0 source", databaseContext.getMode().getFormattedName())); - } else { - String title = Localization.lang("BibTeX of that entry"); + private void showEntrySourceDialog(BibEntry entry) { + CodeArea ca = new CodeArea(); + try { + ca.appendText(getSourceString(entry, databaseContext.getMode())); + } catch (IOException e) { + LOGGER.warn("Incorrect entry, could not load source:", e); + return; + } - codeArea.setWrapText(true); - codeArea.setPadding(new Insets(0, 10, 0, 10)); - codeArea.showParagraphAtTop(0); + ca.setWrapText(true); + ca.setPadding(new Insets(0, 10, 0, 10)); + ca.showParagraphAtTop(0); - ScrollPane scrollPane = new ScrollPane(); - scrollPane.setFitToWidth(true); - scrollPane.setFitToHeight(true); - scrollPane.setContent(new VirtualizedScrollPane<>(codeArea)); + ScrollPane scrollPane = new ScrollPane(); + scrollPane.setFitToWidth(true); + scrollPane.setFitToHeight(true); + scrollPane.setContent(new VirtualizedScrollPane<>(ca)); - DialogPane dialogPane = new DialogPane(); - dialogPane.setPrefSize(800, 400); - dialogPane.setContent(scrollPane); + DialogPane dialogPane = new DialogPane(); + dialogPane.setPrefSize(800, 400); + dialogPane.setContent(scrollPane); + String title = Localization.lang("%0 source", "Show BibTeX"); - dialogService.showCustomDialogAndWait(title, dialogPane, ButtonType.OK); - } + dialogService.showCustomDialogAndWait(title, dialogPane, ButtonType.OK); } /** diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index b5df5c1e3e2..2ec8827add2 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2782,8 +2782,3 @@ Warning\:\ The\ selected\ directory\ is\ not\ a\ valid\ directory.=Warning: The Currently\ selected\ JStyle\:\ '%0' = Currently selected JStyle: '%0' Currently\ selected\ CSL\ Style\:\ '%0' = Currently selected CSL Style: '%0' Store\ url\ for\ downloaded\ file=Store url for downloaded file - -BibTeX\ of\ that\ entry=BibTeX of that entry -Could\ not\ load\ %0\ source=Could not load %0 source -BibTeX\ source=BibTeX source -Show\ %0\ source=Show %0 source