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 method to create a new file link manually #11539

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We added support for selecting and using CSL Styles in JabRef's OpenOffice/LibreOffice integration for inserting bibliographic and in-text citations into a document. [#2146](https://github.com/JabRef/jabref/issues/2146), [#8893](https://github.com/JabRef/jabref/issues/8893)
- Added minimal support for [biblatex data annotation](https://mirrors.ctan.org/macros/latex/contrib/biblatex/doc/biblatex.pdf#subsection.3.7) fields in .layout files. [#11505](https://github.com/JabRef/jabref/issues/11505)
- Added saving of selected options in the [Lookup -> Search for unlinked local files dialog](https://docs.jabref.org/collect/findunlinkedfiles#link-the-pdfs-to-your-bib-library). [#11439](https://github.com/JabRef/jabref/issues/11439)
- Added a method to create a new link manually. [#11017](...)

### Changed

Expand Down
14 changes: 13 additions & 1 deletion src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jabref.gui.fieldeditors;

import java.io.IOException;
import java.net.URL;
import java.util.Optional;

import javax.swing.undo.UndoManager;
Expand All @@ -9,8 +11,10 @@
import javafx.collections.ObservableList;
import javafx.css.PseudoClass;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.Label;
Expand All @@ -31,6 +35,8 @@
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.text.Text;
import javafx.stage.Modality;
import javafx.stage.Stage;

import org.jabref.gui.DialogService;
import org.jabref.gui.DragAndDropDataFormats;
Expand All @@ -44,6 +50,8 @@
import org.jabref.gui.importer.GrobidOptInDialogHelper;
import org.jabref.gui.keyboard.KeyBinding;
import org.jabref.gui.linkedfile.DeleteFileAction;

import org.jabref.gui.linkedfile.LinkedFileAddDialogController;
import org.jabref.gui.util.BindingsHelper;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.gui.util.ViewModelListCellFactory;
Expand Down Expand Up @@ -285,7 +293,11 @@ public Parent getNode() {

@FXML
private void addNewFile() {
viewModel.addNewFile();
LinkedFileAddDialogController dialog = new LinkedFileAddDialogController();
dialog.showAndWait().ifPresent(result -> {
// Handle adding the new file
viewModel.addNewManualFile(result);
});
}

@FXML
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,17 @@ public void addNewFile() {
}
}

public void addNewManualFile(LinkedFile linkedFile) {

files.add(new LinkedFileViewModel(
linkedFile,
entry,
databaseContext,
taskExecutor,
dialogService,
preferences));
}

private void addNewLinkedFile(Path correctPath, List<Path> fileDirectories) {
LinkedFile newLinkedFile = fromFile(correctPath, fileDirectories, preferences.getFilePreferences());
files.add(new LinkedFileViewModel(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.DialogPane?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.Tooltip?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import org.jabref.gui.icon.JabRefIconView?>
<DialogPane minHeight="140.0" minWidth="550.0"
xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="org.jabref.gui.linkedfile.LinkedFileAddDialogController">
<content>
<GridPane vgap="4" hgap="4">
<columnConstraints>
<ColumnConstraints hgrow="NEVER" minWidth="10.0" prefWidth="100.0"/>
<ColumnConstraints hgrow="ALWAYS" minWidth="10.0"/>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0"/>
</columnConstraints>
<rowConstraints>
<RowConstraints/>
<RowConstraints/>
<RowConstraints/>
</rowConstraints>

<Label text="Link"/>
<TextField fx:id="link" prefHeight="25.0"
GridPane.columnIndex="1" GridPane.hgrow="ALWAYS"/>
<Button id="browse" onAction="#openBrowseDialog"
styleClass="icon-button,narrow"
prefHeight="20.0" prefWidth="20.0" GridPane.columnIndex="2">
<graphic>
<JabRefIconView glyph="OPEN"/>
</graphic>
<tooltip>
<Tooltip text="Browse"/>
</tooltip>
</Button>

<Label text="Description" GridPane.rowIndex="1"/>
<TextField fx:id="description" prefHeight="25.0"
GridPane.columnIndex="1" GridPane.hgrow="ALWAYS" GridPane.rowIndex="1"/>

<Label text="Filetype" GridPane.rowIndex="2"/>
<ComboBox fx:id="fileType"
GridPane.columnIndex="1" GridPane.hgrow="ALWAYS" GridPane.rowIndex="2"/>

<Label text="Source URL" GridPane.rowIndex="3"/>
<TextField fx:id="sourceUrl" prefHeight="25.0"
GridPane.columnIndex="1" GridPane.hgrow="ALWAYS" GridPane.rowIndex="3"/>
</GridPane>
</content>
</DialogPane>

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.jabref.gui.linkedfile;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.ButtonType;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;

import org.jabref.gui.DialogService;
import org.jabref.gui.StateManager;
import org.jabref.gui.externalfiletype.ExternalFileType;
import org.jabref.gui.util.BaseDialog;
import org.jabref.gui.util.ViewModelListCellFactory;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.entry.LinkedFile;
import org.jabref.preferences.PreferencesService;

import com.airhacks.afterburner.views.ViewLoader;
import jakarta.inject.Inject;

public class LinkedFileAddDialogController extends BaseDialog<LinkedFile> {

@FXML private TextField link;
@FXML private TextField description;
@FXML private ComboBox<ExternalFileType> fileType;
@FXML private TextField sourceUrl;

@Inject private DialogService dialogService;
@Inject private StateManager stateManager;
@Inject private PreferencesService preferences;

private LinkedFilesEditDialogViewModel viewModel;
private final LinkedFile linkedFile;

public LinkedFileAddDialogController() {
this.linkedFile = new LinkedFile("", "", "");

ViewLoader.view(this)
.load()
.setAsContent(this.getDialogPane());

ButtonType addButtonType = new ButtonType(Localization.lang("Add"), ButtonType.OK.getButtonData());
this.getDialogPane().getButtonTypes().addAll(addButtonType, ButtonType.CANCEL);
this.setResizable(false);
this.setTitle(Localization.lang("Add file link"));

this.setResultConverter(button -> {
if (button == addButtonType) {
return viewModel.getNewLinkedFile();
} else {
return null;
}
});
}

@FXML
private void initialize() {
viewModel = new LinkedFilesEditDialogViewModel(linkedFile, stateManager.getActiveDatabase().get(), dialogService, preferences.getFilePreferences());
fileType.itemsProperty().bindBidirectional(viewModel.externalFileTypeProperty());
new ViewModelListCellFactory<ExternalFileType>()
.withIcon(ExternalFileType::getIcon)
.withText(ExternalFileType::getName)
.install(fileType);

description.textProperty().bindBidirectional(viewModel.descriptionProperty());
link.textProperty().bindBidirectional(viewModel.linkProperty());
fileType.valueProperty().bindBidirectional(viewModel.selectedExternalFileTypeProperty());
sourceUrl.textProperty().bindBidirectional(viewModel.sourceUrlProperty());
}

@FXML
private void openBrowseDialog(ActionEvent event) {
viewModel.openBrowseDialog();
link.requestFocus();
}
}
Loading