Skip to content

Commit

Permalink
Correction of created errors JabRef#11826
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Mochnacký committed Sep 29, 2024
1 parent a9b5423 commit bfe9dc9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 51 deletions.
5 changes: 0 additions & 5 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -475,8 +474,4 @@ public void nextPreviewStyle() {
public void previousPreviewStyle() {
this.previewTabs.forEach(OffersPreview::previousPreviewStyle);
}

public CodeArea getEntrySource(BibEntry entry) {
return sourceTab.getEntryCodeArea(entry);
}
}
12 changes: 0 additions & 12 deletions src/main/java/org/jabref/gui/entryeditor/SourceTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -269,10 +272,9 @@ private void styleFetchedListView(CheckListView<CitationRelationItem> 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);
Expand All @@ -293,35 +295,38 @@ private void styleFetchedListView(CheckListView<CitationRelationItem> listView)
listView.setSelectionModel(new NoSelectionModel<>());
}

private EntryEditor createEntryEditor() {
Supplier<LibraryTab> 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);
}

/**
Expand Down
5 changes: 0 additions & 5 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit bfe9dc9

Please sign in to comment.