Skip to content

Commit

Permalink
Fix drag and drop into empty library (#7555)
Browse files Browse the repository at this point in the history
* Fixes issue #6851

	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

* Update CHANGELOG.md

* Fixes style issue in CHANGELOG.md

	Lined added to wrong section

	Line move to fix issue

* Another style fix

	extra space removed
  • Loading branch information
tp-1000 committed Mar 24, 2021
1 parent 8fe77dd commit 2ee9767
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 @@ -36,6 +36,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve

### Fixed

- We fixed an issue preventing files from being dragged & dropped into an empty library. [#6851](https://github.com/JabRef/jabref/issues/6851)
- We fixed an issue where double-click onto PDF in file list under the 'General' tab section should just open the file. [#7465](https://github.com/JabRef/jabref/issues/7465)
- We fixed an issue where the dark theme did not extend to a group's custom color picker. [#7481](https://github.com/JabRef/jabref/issues/7481)
- We fixed an issue where choosing the fields on which autocompletion should not work in "Entry editor" preferences had no effect. [#7320](https://github.com/JabRef/jabref/issues/7320)
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 2ee9767

Please sign in to comment.