Skip to content

Commit

Permalink
Added a method to create a new link manually JabRef#11017
Browse files Browse the repository at this point in the history
- Deleted fxml and java files which were handling edit and add action separately and added a unified way which handles edit and add action dynamically
  • Loading branch information
Kunal77689 committed Jul 27, 2024
1 parent 86bfc75 commit 782e5ae
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.jabref.gui.icon.JabRefIcon;
import org.jabref.gui.linkedfile.DeleteFileAction;
import org.jabref.gui.linkedfile.DownloadLinkedFileAction;
import org.jabref.gui.linkedfile.LinkedFileEditDialogView;
import org.jabref.gui.linkedfile.LinkedFileDialogController;
import org.jabref.gui.mergeentries.MultiMergeEntriesView;
import org.jabref.gui.util.ControlHelper;
import org.jabref.gui.util.TaskExecutor;
Expand Down Expand Up @@ -375,7 +375,7 @@ public boolean delete() {
}

public void edit() {
Optional<LinkedFile> editedFile = dialogService.showCustomDialogAndWait(new LinkedFileEditDialogView(this.linkedFile));
Optional<LinkedFile> editedFile = dialogService.showCustomDialogAndWait(new LinkedFileDialogController(this.linkedFile, true));
editedFile.ifPresent(file -> {
this.linkedFile.setLink(file.getLink());
this.linkedFile.setDescription(file.getDescription());
Expand Down
13 changes: 4 additions & 9 deletions src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.jabref.gui.fieldeditors;

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

import javax.swing.undo.UndoManager;
Expand All @@ -11,10 +9,8 @@
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 @@ -35,8 +31,6 @@
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 @@ -51,7 +45,7 @@
import org.jabref.gui.keyboard.KeyBinding;
import org.jabref.gui.linkedfile.DeleteFileAction;

import org.jabref.gui.linkedfile.LinkedFileAddDialogController;
import org.jabref.gui.linkedfile.LinkedFileDialogController;
import org.jabref.gui.util.BindingsHelper;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.gui.util.ViewModelListCellFactory;
Expand Down Expand Up @@ -293,8 +287,9 @@ public Parent getNode() {

@FXML
private void addNewFile() {
LinkedFileAddDialogController dialog = new LinkedFileAddDialogController();
dialog.showAndWait().ifPresent(result -> {
LinkedFileDialogController controller = new LinkedFileDialogController(null, false);

controller.showAndWait().ifPresent(result -> {
// Handle adding the new file
viewModel.addNewManualFile(result);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void execute() {
databaseContext.getFileDirectories(filePreferences),
filePreferences);

LinkedFileEditDialogView dialog = new LinkedFileEditDialogView(linkedFile);
LinkedFileDialogController dialog = new LinkedFileDialogController(linkedFile, true);

dialogService.showCustomDialogAndWait(dialog)
.ifPresent(editedLinkedFile -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.DialogPane?>
Expand All @@ -11,7 +12,7 @@
<?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">
fx:controller="org.jabref.gui.linkedfile.LinkedFileDialogController">
<content>
<GridPane vgap="4" hgap="4">
<columnConstraints>
Expand All @@ -23,6 +24,7 @@
<RowConstraints/>
<RowConstraints/>
<RowConstraints/>
<RowConstraints/>
</rowConstraints>

<Label text="Link"/>
Expand Down Expand Up @@ -53,4 +55,3 @@
</GridPane>
</content>
</DialogPane>

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.airhacks.afterburner.views.ViewLoader;
import jakarta.inject.Inject;

public class LinkedFileAddDialogController extends BaseDialog<LinkedFile> {
public class LinkedFileDialogController extends BaseDialog<LinkedFile> {

@FXML private TextField link;
@FXML private TextField description;
Expand All @@ -31,21 +31,23 @@ public class LinkedFileAddDialogController extends BaseDialog<LinkedFile> {

private LinkedFilesEditDialogViewModel viewModel;
private final LinkedFile linkedFile;
private final boolean isEditMode;

public LinkedFileAddDialogController() {
this.linkedFile = new LinkedFile("", "", "");
public LinkedFileDialogController(LinkedFile linkedFile, boolean isEditMode) {
this.linkedFile = linkedFile != null ? linkedFile : new LinkedFile("", "", "");
this.isEditMode = isEditMode;

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

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

this.setResultConverter(button -> {
if (button == addButtonType) {
if (button == primaryButtonType) {
return viewModel.getNewLinkedFile();
} else {
return null;
Expand Down
56 changes: 0 additions & 56 deletions src/main/java/org/jabref/gui/linkedfile/LinkedFileEditDialog.fxml

This file was deleted.

This file was deleted.

0 comments on commit 782e5ae

Please sign in to comment.