Skip to content

Commit

Permalink
Fixes issue JabRef#6851
Browse files Browse the repository at this point in the history
	Fixes issue preventing files from being drag & dropped into an
	empty library

	Added a drag/drop handlers on the table-view to allow for files
	to be drag & drop into an empty library
  • Loading branch information
tp-1000 committed Mar 21, 2021
1 parent f1d3003 commit 5ce7656
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve

### Fixed

- We fixed an issue preventing files from being drag & dropeed into an empty library. [#6851](https://github.com/JabRef/jabref/issues/6851)
- We fixed an issue where entry preview tab has no name in drop down list. [#6591](https://github.com/JabRef/jabref/issues/6591)
- We fixed to only search file links in the BIB file location directory when preferences has corresponding checkbox checked. [#5891](https://github.com/JabRef/jabref/issues/5891)
- We fixed wrong button order (Apply and Cancel) in ManageProtectedTermsDialog.
Expand Down
27 changes: 25 additions & 2 deletions src/main/java/org/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ public MainTable(MainTableDataModel model,

localDragboard = stateManager.getLocalDragboard();

this.setOnDragOver(this::handleOnDragOverTableView);
this.setOnDragDropped(this::handleOnDragDroppedTableView);

this.getColumns().addAll(
new MainTableColumnFactory(
database,
Expand Down Expand Up @@ -174,8 +177,7 @@ public MainTable(MainTableDataModel model,
}

/**
* This is called, if a user starts typing some characters into the keyboard with focus on main table. The {@link
* MainTable} will scroll to the cell with the same starting column value and typed string
* This is called, if a user starts typing some characters into the keyboard with focus on main table. The {@link MainTable} will scroll to the cell with the same starting column value and typed string
*
* @param sortedColumn The sorted column in {@link MainTable}
* @param keyEvent The pressed character
Expand Down Expand Up @@ -311,6 +313,13 @@ private void handleOnDragOver(TableRow<BibEntryTableViewModel> row, BibEntryTabl
event.consume();
}

private void handleOnDragOverTableView(DragEvent event) {
if (event.getDragboard().hasFiles()) {
event.acceptTransferModes(TransferMode.ANY);
}
event.consume();
}

private void handleOnDragEntered(TableRow<BibEntryTableViewModel> row, BibEntryTableViewModel entry, MouseDragEvent event) {
// Support the following gesture to select entries: click on one row -> hold mouse button -> move over other rows
// We need to select all items between the starting row and the row where the user currently hovers the mouse over
Expand Down Expand Up @@ -382,6 +391,20 @@ private void handleOnDragDropped(TableRow<BibEntryTableViewModel> row, BibEntryT
event.consume();
}

private void handleOnDragDroppedTableView(DragEvent event) {
boolean success = false;

if (event.getDragboard().hasFiles()) {
List<Path> files = event.getDragboard().getFiles().stream().map(File::toPath).collect(Collectors.toList());
importHandler.importFilesInBackground(files).executeWith(Globals.TASK_EXECUTOR);

success = true;
}

event.setDropCompleted(success);
event.consume();
}

public void addSelectionListener(ListChangeListener<? super BibEntryTableViewModel> listener) {
getSelectionModel().getSelectedItems().addListener(listener);
}
Expand Down

0 comments on commit 5ce7656

Please sign in to comment.