Skip to content

Commit

Permalink
Add a "view as BibTeX" option before importing an entry from the cita…
Browse files Browse the repository at this point in the history
…tion relation tab JabRef#11826
  • Loading branch information
Martin Mochnacký committed Sep 29, 2024
1 parent bd5439a commit a9b5423
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
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
5 changes: 5 additions & 0 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
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 @@ -474,4 +475,8 @@ public void nextPreviewStyle() {
public void previousPreviewStyle() {
this.previewTabs.forEach(OffersPreview::previousPreviewStyle);
}

public CodeArea getEntrySource(BibEntry entry) {
return sourceTab.getEntryCodeArea(entry);
}
}
12 changes: 12 additions & 0 deletions src/main/java/org/jabref/gui/entryeditor/SourceTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,4 +347,16 @@ 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
Expand Up @@ -4,6 +4,7 @@
import java.net.URI;
import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;

import javax.swing.undo.UndoManager;

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,11 +34,14 @@
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.undo.RedoAction;
import org.jabref.gui.undo.UndoAction;
import org.jabref.gui.util.NoSelectionModel;
import org.jabref.gui.util.ViewModelListCellFactory;
import org.jabref.logic.database.DuplicateCheck;
Expand All @@ -51,6 +59,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 +84,9 @@ public class CitationRelationsTab extends EntryEditorTab {
private final BibEntryRelationsRepository bibEntryRelationsRepository;
private final CitationsRelationsTabViewModel citationsRelationsTabViewModel;
private final DuplicateCheck duplicateCheck;
private EntryEditor entryEditor;

private StateManager stateManager;

public CitationRelationsTab(DialogService dialogService,
BibDatabaseContext databaseContext,
Expand All @@ -87,6 +100,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 +268,15 @@ private void styleFetchedListView(CheckListView<CitationRelationItem> listView)
vContainer.getChildren().addLast(openWeb);
}

Button showEntrySource = IconTheme.JabRefIcons.SOURCE.asButton();
showEntrySource.setTooltip(new Tooltip(Localization.lang("Show %0 source", databaseContext.getMode().getFormattedName())));
showEntrySource.setOnMouseClicked(event -> {
this.entryEditor = createEntryEditor();
showEntrySourceDialog(this.entryEditor.getEntrySource(entry.entry()));
});

vContainer.getChildren().addLast(showEntrySource);

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

Expand All @@ -270,6 +293,37 @@ 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 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");

codeArea.setWrapText(true);
codeArea.setPadding(new Insets(0, 10, 0, 10));
codeArea.showParagraphAtTop(0);

ScrollPane scrollPane = new ScrollPane();
scrollPane.setFitToWidth(true);
scrollPane.setFitToHeight(true);
scrollPane.setContent(new VirtualizedScrollPane<>(codeArea));

DialogPane dialogPane = new DialogPane();
dialogPane.setPrefSize(800, 400);
dialogPane.setContent(scrollPane);

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

/**
* Method to style heading labels
*
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2782,3 +2782,8 @@ 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 a9b5423

Please sign in to comment.