Skip to content

Commit

Permalink
Add external drag'n'drop feature
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor committed Sep 28, 2024
1 parent b4bbb56 commit cf650ca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We improved [cleanup](https://docs.jabref.org/finding-sorting-and-cleaning-entries/cleanupentries) of `arXiv` IDs in distributed in the fields `note`, `version`, `institution`, and `eid` fields. [#11306](https://github.com/JabRef/jabref/issues/11306)
- We added a switch not to store the linked file URL, because it caused troubles at other apps. [#11735](https://github.com/JabRef/jabref/pull/11735)
- When starting a new SLR, the selected catalogs now persist within and across JabRef sessions. [koppor#614](https://github.com/koppor/jabref/issues/614)
- One can drag'n'drop an entry from the maintable to an external application to get the entry preview dropped.
- We added a different background color to the search bar to indicate when the search syntax is wrong. [#11658](https://github.com/JabRef/jabref/pull/11658)
- We added a setting which always adds the literal "Cited on pages" text before each JStyle citation. [#11691](https://github.com/JabRef/jabref/pull/11732)

Expand Down
20 changes: 16 additions & 4 deletions src/main/java/org/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jabref.gui.maintable;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -39,12 +40,14 @@
import org.jabref.gui.maintable.columns.LibraryColumn;
import org.jabref.gui.maintable.columns.MainTableColumn;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.gui.preview.ClipboardContentGenerator;
import org.jabref.gui.search.MatchCategory;
import org.jabref.gui.util.ControlHelper;
import org.jabref.gui.util.CustomLocalDragboard;
import org.jabref.gui.util.UiTaskExecutor;
import org.jabref.gui.util.ViewModelTableRowFactory;
import org.jabref.logic.FilePreferences;
import org.jabref.logic.citationstyle.CitationStyleOutputFormat;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.util.TaskExecutor;
import org.jabref.model.database.BibDatabaseContext;
Expand Down Expand Up @@ -75,6 +78,8 @@ public class MainTable extends TableView<BibEntryTableViewModel> {
private final UndoManager undoManager;
private final FilePreferences filePreferences;
private final ImportHandler importHandler;
private final ClipboardContentGenerator clipboardContentGenerator;

private long lastKeyPressTime;
private String columnSearchTerm;

Expand All @@ -100,6 +105,7 @@ public MainTable(MainTableDataModel model,
this.undoManager = libraryTab.getUndoManager();
this.filePreferences = preferences.getFilePreferences();
this.importHandler = importHandler;
this.clipboardContentGenerator = new ClipboardContentGenerator(preferences.getPreviewPreferences(), preferences.getLayoutFormatterPreferences(), Injector.instantiateModelOrService(JournalAbbreviationRepository.class));

MainTablePreferences mainTablePreferences = preferences.getMainTablePreferences();

Expand Down Expand Up @@ -392,12 +398,18 @@ private void handleOnDragDetected(TableRow<BibEntryTableViewModel> row, BibEntry

List<BibEntry> entries = getSelectionModel().getSelectedItems().stream().map(BibEntryTableViewModel::getEntry).collect(Collectors.toList());

// The following is necessary to initiate the drag and drop in JavaFX,
// although we don't need the contents, it does not work without
ClipboardContent content;
try {
content = clipboardContentGenerator.generate(entries, CitationStyleOutputFormat.HTML, database);
} catch (IOException e) {
LOGGER.warn("Could not generate clipboard content. Falling back to empty clipboard", e);
content = new ClipboardContent();
}
// Required to be able to drop the entries inside JabRef
content.put(DragAndDropDataFormats.ENTRIES, "");

// Drag'n'drop to other tabs use COPY TransferMode, drop to group sidepane use MOVE
ClipboardContent content = new ClipboardContent();
Dragboard dragboard = startDragAndDrop(TransferMode.COPY_OR_MOVE);
content.put(DragAndDropDataFormats.ENTRIES, "");
dragboard.setContent(content);

if (!entries.isEmpty()) {
Expand Down

0 comments on commit cf650ca

Please sign in to comment.