Skip to content

Commit

Permalink
BibTeX information in web search import screen. (JabRef#560)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMachiei committed Jan 14, 2024
1 parent b7990ea commit e6ec8b4
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
## [Unreleased]

### Added
- BibTeX information in web search import screen. [#560](https://github.com/koppor/jabref/issues/560)

### Changed

Expand Down
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>
<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 Down
48 changes: 44 additions & 4 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,11 +20,11 @@
import javafx.scene.control.Label;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;

import org.fxmisc.richtext.CodeArea;
import org.jabref.gui.DialogService;
import org.jabref.gui.StateManager;
import org.jabref.gui.icon.IconTheme;
Expand All @@ -31,9 +34,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 @@ -57,6 +64,7 @@ public class ImportEntriesDialog extends BaseDialog<Boolean> {
public Label totalItems;
public Label selectedItems;
public CheckBox downloadLinkedOnlineFiles;
public CodeArea bibTeXData;
private final BackgroundTask<ParserResult> task;
private ImportEntriesViewModel viewModel;
@Inject private TaskExecutor taskExecutor;
Expand Down Expand Up @@ -167,13 +175,45 @@ 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));
}

private String getSourceString(BibEntry entry) throws IOException {
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
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1991,6 +1991,7 @@ 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\:
Add\ new\ String=Add new String
Must\ not\ be\ empty\!=Must not be empty\!
Open\ Help\ page=Open Help page
Expand Down

0 comments on commit e6ec8b4

Please sign in to comment.