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

Fix drag and drop into empty library #7555

Merged
merged 4 commits into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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