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

BibTeX information in web search import screen. (#560) #10784

Merged
merged 10 commits into from
Jan 25, 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 the possibility to show the BibTeX source in the [web search](https://docs.jabref.org/collect/import-using-online-bibliographic-database) import screen. [#560](https://github.com/koppor/jabref/issues/560)
- We added a fetcher for [ISIDORE](https://isidore.science/), simply paste in the link into the text field or the last 6 digits in the link that identify that paper. [#10423](https://github.com/JabRef/jabref/issues/10423)
- When importing entries form the "Citation relations" tab, the field [cites](https://docs.jabref.org/advanced/entryeditor/entrylinks) is now filled according to the relationship between the entries. [#10572](https://github.com/JabRef/jabref/pull/10752)
- We added a new group icon column to the main table showing the icons of the entry's groups. [#10801](https://github.com/JabRef/jabref/pull/10801)
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/org/jabref/gui/importer/ImportEntriesDialog.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ButtonType?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.ChoiceBox?>
<?import javafx.scene.control.DialogPane?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.ColumnConstraints?>
Expand All @@ -13,6 +12,7 @@
<?import javafx.scene.layout.VBox?>
<?import org.controlsfx.control.CheckListView?>
<?import javafx.scene.control.ComboBox?>
<?import org.fxmisc.richtext.CodeArea?>
<DialogPane prefHeight="700.0" prefWidth="1000.0" xmlns="http://javafx.com/javafx/10.0.2-internal"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.importer.ImportEntriesDialog">
<content>
Expand All @@ -26,6 +26,10 @@
<Button onAction="#selectAllEntries" text="%Select all entries"/>
<Button onAction="#unselectAll" text="%Unselect all"/>
</HBox>
<VBox fx:id="bibTeXDataBox" visible="false" managed="false">
<Label fx:id="bibTeXDataLabel"/>
<CodeArea fx:id="bibTeXData" editable="false" minHeight="30.0" prefHeight="200.0" prefWidth="700.0" wrapText="true"/>
</VBox>
<HBox spacing="4" alignment="CENTER_LEFT">
<Label text="%Library to import into"/>
<ComboBox fx:id="libraryListView" layoutX="16.0" layoutY="52.0"/>
Expand All @@ -48,7 +52,10 @@
<Label fx:id="selectedItems" GridPane.rowIndex="1" GridPane.columnIndex="1"/>
</GridPane>
</HBox>
<CheckBox fx:id="downloadLinkedOnlineFiles" text="%Download linked online files"/>
<HBox spacing="4">
<CheckBox fx:id="downloadLinkedOnlineFiles" text="%Download linked online files"/>
<CheckBox fx:id="showEntryInformation" text="%Show BibTeX source"/>
</HBox>
</VBox>
</content>
<ButtonType fx:id="importButton" buttonData="OK_DONE" text="%Import entries"/>
Expand Down
42 changes: 40 additions & 2 deletions src/main/java/org/jabref/gui/importer/ImportEntriesDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javafx.beans.binding.BooleanBinding;
import javafx.css.PseudoClass;
import javafx.fxml.FXML;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
Expand All @@ -17,9 +18,15 @@
import javafx.scene.control.Label;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.Border;
import javafx.scene.layout.BorderStroke;
import javafx.scene.layout.BorderStrokeStyle;
import javafx.scene.layout.BorderWidths;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;

import org.jabref.gui.DialogService;
Expand Down Expand Up @@ -48,6 +55,7 @@
import com.tobiasdiez.easybind.EasyBind;
import jakarta.inject.Inject;
import org.controlsfx.control.CheckListView;
import org.fxmisc.richtext.CodeArea;

public class ImportEntriesDialog extends BaseDialog<Boolean> {

Expand All @@ -56,8 +64,13 @@ public class ImportEntriesDialog extends BaseDialog<Boolean> {
public ButtonType importButton;
public Label totalItems;
public Label selectedItems;
public Label bibTeXDataLabel;
public CheckBox downloadLinkedOnlineFiles;
public CheckBox showEntryInformation;
public CodeArea bibTeXData;
public VBox bibTeXDataBox;
private final BackgroundTask<ParserResult> task;
private final BibDatabaseContext database;
private ImportEntriesViewModel viewModel;
@Inject private TaskExecutor taskExecutor;
@Inject private DialogService dialogService;
Expand All @@ -66,7 +79,6 @@ public class ImportEntriesDialog extends BaseDialog<Boolean> {
@Inject private StateManager stateManager;
@Inject private BibEntryTypesManager entryTypesManager;
@Inject private FileUpdateMonitor fileUpdateMonitor;
private final BibDatabaseContext database;

/**
* Imports the given entries into the given database. The entries are provided using the BackgroundTask
Expand Down Expand Up @@ -163,13 +175,38 @@ private void initialize() {

return container;
})
.withOnMouseClickedEvent((entry, event) -> entriesListView.getCheckModel().toggleCheckState(entry))
.withOnMouseClickedEvent((entry, event) -> {
entriesListView.getCheckModel().toggleCheckState(entry);
displayBibTeX(entry, viewModel.getSourceString(entry));
})
.withPseudoClass(entrySelected, entriesListView::getItemBooleanProperty)
.install(entriesListView);

selectedItems.textProperty().bind(Bindings.size(entriesListView.getCheckModel().getCheckedItems()).asString());
totalItems.textProperty().bind(Bindings.size(entriesListView.getItems()).asString());
entriesListView.setSelectionModel(new NoSelectionModel<>());
initBibTeX();
}

private void displayBibTeX(BibEntry entry, String bibTeX) {
if (entriesListView.getCheckModel().isChecked(entry)) {
bibTeXData.clear();
bibTeXData.appendText(bibTeX);
bibTeXData.moveTo(0);
bibTeXData.requestFollowCaret();
} else {
bibTeXData.clear();
}
}

private void initBibTeX() {
bibTeXDataLabel.setText(Localization.lang("%0 source", "BibTeX"));
bibTeXData.setBorder(new Border(new BorderStroke(Color.GREY, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderWidths.DEFAULT)));
bibTeXData.setPadding(new Insets(5.0));
showEntryInformation.selectedProperty().addListener((observableValue, old_val, new_val) -> {
bibTeXDataBox.setVisible(new_val);
bibTeXDataBox.setManaged(new_val);
});
}

private Node getEntryNode(BibEntry entry) {
Expand Down Expand Up @@ -218,6 +255,7 @@ public void selectAllNewEntries() {
for (BibEntry entry : entriesListView.getItems()) {
if (!viewModel.hasDuplicate(entry)) {
entriesListView.getCheckModel().check(entry);
displayBibTeX(entry, viewModel.getSourceString(entry));
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jabref.gui.importer;

import java.io.IOException;
import java.io.StringWriter;
import java.util.List;
import java.util.Optional;

Expand All @@ -20,10 +22,14 @@
import org.jabref.gui.fieldeditors.LinkedFileViewModel;
import org.jabref.gui.util.BackgroundTask;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.bibtex.BibEntryWriter;
import org.jabref.logic.bibtex.FieldWriter;
import org.jabref.logic.database.DatabaseMerger;
import org.jabref.logic.database.DuplicateCheck;
import org.jabref.logic.exporter.BibWriter;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.OS;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryTypesManager;
Expand Down Expand Up @@ -117,6 +123,19 @@ public boolean hasDuplicate(BibEntry entry) {
.containsDuplicate(selectedDb.getValue().getDatabase(), entry, selectedDb.getValue().getMode()).isPresent();
}

public String getSourceString(BibEntry entry) {
StringWriter writer = new StringWriter();
BibWriter bibWriter = new BibWriter(writer, OS.NEWLINE);
FieldWriter fieldWriter = FieldWriter.buildIgnoreHashes(preferences.getFieldPreferences());
try {
new BibEntryWriter(fieldWriter, entryTypesManager).write(entry, bibWriter, selectedDb.getValue().getMode());
} catch (
IOException ioException) {
return "";
}
return writer.toString();
}

/**
* Called after the user selected the entries to import. Does the real import stuff.
*
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ Available\ export\ formats=Available export formats
Available\ import\ formats=Available import formats

%0\ source=%0 source
Show\ BibTeX\ source=Show BibTeX source
Show/edit\ %0\ source=Show/edit %0 source

Background\ Tasks=Background Tasks

Expand Down Expand Up @@ -843,7 +845,6 @@ Settings=Settings

Shortcut=Shortcut

Show/edit\ %0\ source=Show/edit %0 source

Show\ 'Firstname\ Lastname'=Show 'Firstname Lastname'

Expand Down
Loading