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

- BibTeX information in web search 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)

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 text="%Entry BibTeX data:"/>
<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 entry information"/>
</HBox>
</VBox>
</content>
<ButtonType fx:id="importButton" buttonData="OK_DONE" text="%Import entries"/>
Expand Down
58 changes: 56 additions & 2 deletions src/main/java/org/jabref/gui/importer/ImportEntriesDialog.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.EnumSet;
import java.util.Optional;

Expand All @@ -9,6 +11,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 +20,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 All @@ -31,9 +40,13 @@
import org.jabref.gui.util.TaskExecutor;
import org.jabref.gui.util.TextFlowLimited;
import org.jabref.gui.util.ViewModelListCellFactory;
import org.jabref.logic.bibtex.BibEntryWriter;
import org.jabref.logic.bibtex.FieldWriter;
import org.jabref.logic.exporter.BibWriter;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.shared.DatabaseLocation;
import org.jabref.logic.util.OS;
import org.jabref.logic.util.io.FileUtil;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
Expand All @@ -48,6 +61,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 @@ -57,7 +71,11 @@ public class ImportEntriesDialog extends BaseDialog<Boolean> {
public Label totalItems;
public Label selectedItems;
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 +84,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 +180,50 @@ private void initialize() {

return container;
})
.withOnMouseClickedEvent((entry, event) -> entriesListView.getCheckModel().toggleCheckState(entry))
.withOnMouseClickedEvent((entry, event) -> {
entriesListView.getCheckModel().toggleCheckState(entry);
displayBibTeX(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) {
if (entriesListView.getCheckModel().isChecked(entry)) {
bibTeXData.clear();
try {
bibTeXData.appendText(getSourceString(entry));
bibTeXData.moveTo(0);
bibTeXData.requestFollowCaret();
} catch (
IOException aE) {
bibTeXData.clear();
}
} else {
bibTeXData.clear();
}
}

private void initBibTeX() {
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 String getSourceString(BibEntry entry) throws IOException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move the whole logic please to the viewModel?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

StringWriter writer = new StringWriter();
BibWriter bibWriter = new BibWriter(writer, OS.NEWLINE);
FieldWriter fieldWriter = FieldWriter.buildIgnoreHashes(preferences.getFieldPreferences());
new BibEntryWriter(fieldWriter, entryTypesManager).write(entry, bibWriter, database.getMode());
return writer.toString();
}

private Node getEntryNode(BibEntry entry) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1986,6 +1986,8 @@ Total\ items\ found\:=Total items found:
Selected\ items\:=Selected items:
Download\ linked\ online\ files=Download linked online files
Select\ the\ entries\ to\ be\ imported\:=Select the entries to be imported\:
Entry\ BibTeX\ data\:=Entry BibTeX data\:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should not be new translations for this heading. The Entry Editor uses "BibTeX". Please re-use that string. Add the : manually in the code (or just style as heading so that no : is necessary).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done:
Zrzut ekranu 2024-01-22 o 21 49 23

Show\ entry\ information=Show entry information
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be "Show BibTeX", because "information" is more general and could be more. For instance: citation data, is this entry already contained in the library, completeness of the bibtex data, ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done
Zrzut ekranu 2024-01-22 o 21 49 03

Add\ new\ String=Add new String
Must\ not\ be\ empty\!=Must not be empty\!
Open\ Help\ page=Open Help page
Expand Down
Loading