Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a "view as BibTeX" option before importing an entry from the cita… #11847

Merged
merged 8 commits into from
Oct 3, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv

### Added

- We added a "view as BibTeX" option before importing an entry from the citation relation tab. [#11826](https://github.com/JabRef/jabref/issues/11826)
- We added probable search hits instead of exact matches. Sorting by hit score can be done by the new score table column. [#11542](https://github.com/JabRef/jabref/pull/11542)
- We added support finding LaTeX-encoded special characters based on plain Unicode and vice versa. [#11542](https://github.com/JabRef/jabref/pull/11542)
- When a search hits a file, the file icon of that entry is changed accordingly. [#11542](https://github.com/JabRef/jabref/pull/11542)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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;
Expand All @@ -12,11 +13,15 @@
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.css.PseudoClass;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.DialogPane;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.SplitPane;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.Tooltip;
Expand All @@ -29,18 +34,24 @@
import org.jabref.gui.LibraryTab;
import org.jabref.gui.StateManager;
import org.jabref.gui.desktop.os.NativeDesktop;
import org.jabref.gui.entryeditor.EntryEditor;
import org.jabref.gui.entryeditor.EntryEditorTab;
import org.jabref.gui.entryeditor.citationrelationtab.semanticscholar.CitationFetcher;
import org.jabref.gui.entryeditor.citationrelationtab.semanticscholar.SemanticScholarFetcher;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.preferences.GuiPreferences;
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 All @@ -51,6 +62,8 @@

import com.tobiasdiez.easybind.EasyBind;
import org.controlsfx.control.CheckListView;
import org.fxmisc.flowless.VirtualizedScrollPane;
import org.fxmisc.richtext.CodeArea;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -74,6 +87,9 @@ public class CitationRelationsTab extends EntryEditorTab {
private final BibEntryRelationsRepository bibEntryRelationsRepository;
private final CitationsRelationsTabViewModel citationsRelationsTabViewModel;
private final DuplicateCheck duplicateCheck;
private EntryEditor entryEditor;
JamseBonde007 marked this conversation as resolved.
Show resolved Hide resolved

private StateManager stateManager;
JamseBonde007 marked this conversation as resolved.
Show resolved Hide resolved

public CitationRelationsTab(DialogService dialogService,
BibDatabaseContext databaseContext,
Expand All @@ -87,6 +103,7 @@ public CitationRelationsTab(DialogService dialogService,
this.databaseContext = databaseContext;
this.preferences = preferences;
this.libraryTab = libraryTab;
this.stateManager = stateManager;
this.taskExecutor = taskExecutor;
setText(Localization.lang("Citation relations"));
setTooltip(new Tooltip(Localization.lang("Show articles related by citation")));
Expand Down Expand Up @@ -254,6 +271,14 @@ private void styleFetchedListView(CheckListView<CitationRelationItem> listView)
vContainer.getChildren().addLast(openWeb);
}

Button showEntrySource = IconTheme.JabRefIcons.SOURCE.asButton();
showEntrySource.setTooltip(new Tooltip(Localization.lang("%0 source", databaseContext.getMode().getFormattedName())));
JamseBonde007 marked this conversation as resolved.
Show resolved Hide resolved
showEntrySource.setOnMouseClicked(event -> {
showEntrySourceDialog(entry.entry());
});

vContainer.getChildren().addLast(showEntrySource);

hContainer.getChildren().addAll(entryNode, separator, vContainer);
hContainer.getStyleClass().add("entry-container");

Expand All @@ -270,6 +295,40 @@ private void styleFetchedListView(CheckListView<CitationRelationItem> listView)
listView.setSelectionModel(new NoSelectionModel<>());
}

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);
JamseBonde007 marked this conversation as resolved.
Show resolved Hide resolved
return writer.toString();
}

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;
}

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<>(ca));

DialogPane dialogPane = new DialogPane();
dialogPane.setPrefSize(800, 400);
dialogPane.setContent(scrollPane);
String title = Localization.lang("%0 source", "Show BibTeX");
JamseBonde007 marked this conversation as resolved.
Show resolved Hide resolved

dialogService.showCustomDialogAndWait(title, dialogPane, ButtonType.OK);
}

/**
* Method to style heading labels
*
Expand Down
Loading