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 drag and drop in EntryEditor #9965

Merged
merged 18 commits into from
Jun 5, 2023
17 changes: 17 additions & 0 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import javafx.scene.layout.BorderPane;

import org.jabref.gui.DialogService;
import org.jabref.gui.DragAndDropDataFormats;
import org.jabref.gui.LibraryTab;
import org.jabref.gui.StateManager;
import org.jabref.gui.citationkeypattern.GenerateCitationKeySingleAction;
Expand Down Expand Up @@ -53,6 +54,7 @@
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.PreferencesService;

Expand Down Expand Up @@ -135,6 +137,9 @@ public EntryEditor(LibraryTab libraryTab) {
this.tabs = createTabs();

this.setOnDragOver(event -> {
if (event.getDragboard().hasContent(DragAndDropDataFormats.GROUP)) {
event.acceptTransferModes(TransferMode.MOVE);
}
if (event.getDragboard().hasFiles()) {
event.acceptTransferModes(TransferMode.COPY, TransferMode.MOVE, TransferMode.LINK);
}
Expand All @@ -143,6 +148,18 @@ public EntryEditor(LibraryTab libraryTab) {

this.setOnDragDropped(event -> {
BibEntry entry = this.getEntry();
if (event.getDragboard().hasContent(DragAndDropDataFormats.GROUP)) {
List<String> group = (List<String>) event.getDragboard().getContent(DragAndDropDataFormats.GROUP);
String changedGroup = null;
if (entry.getField(StandardField.GROUPS).isPresent()) {
changedGroup = entry.getField(StandardField.GROUPS).get() + "," + group.get(0);
k3KAW8Pnf7mkmdSMPHz27 marked this conversation as resolved.
Show resolved Hide resolved
} else {
changedGroup = group.get(0);
}

entry.setField(StandardField.GROUPS, changedGroup);
}

boolean success = false;

if (event.getDragboard().hasContent(DataFormat.FILES)) {
Expand Down