Skip to content

Commit

Permalink
Improve Drag and Drop
Browse files Browse the repository at this point in the history
Fixes #6338
  • Loading branch information
Siedlerchr committed Oct 4, 2021
1 parent bac8304 commit f1ebec6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We reworked the export order in the preferences and the save order in the library preferences. You can now set more than three sort criteria in your library preferences. [#7935](https://github.com/JabRef/jabref/pull/7935)
- The metadata-to-pdf actions now also embeds the bibfile to the PDF. [#8037](https://github.com/JabRef/jabref/pull/8037)
- The snap was updated to use the core20 base and to use lzo compression for better startup performance [#8109](https://github.com/JabRef/jabref/pull/8109)
- We improved the Drag and Drop behavior in the "Customize Entry Types" Dialog [#6338](https://github.com/JabRef/jabref/issues/6338)

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import javafx.application.Platform;
import javafx.beans.property.ReadOnlyStringWrapper;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBar.ButtonData;
Expand Down Expand Up @@ -206,27 +205,20 @@ private void handleOnDragDetected(TableRow<FieldViewModel> row, FieldViewModel f
}

private void handleOnDragDropped(TableRow<FieldViewModel> row, FieldViewModel originalItem, DragEvent event) {
boolean success = false;

ObservableList<FieldViewModel> items = fields.itemsProperty().get();

if (localDragboard.hasType(FieldViewModel.class)) {
FieldViewModel field = localDragboard.getValue(FieldViewModel.class);
int draggedIdx = 0;
for (int i = 0; i < items.size(); i++) {
if (items.get(i).equals(field)) {
draggedIdx = i;
field = items.get(i);
break;
}
fields.getItems().remove(field);

if (row.isEmpty()) {
fields.getItems().add(field);
} else {
// decide based on drop position whether to add the element before or after
int offset = event.getY() > (row.getHeight() / 2) ? 1 : 0;
fields.getItems().add(row.getIndex() + offset, field);
}
int thisIdx = items.indexOf(originalItem);
items.set(draggedIdx, originalItem);
items.set(thisIdx, field);
success = true;
}

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

Expand Down

0 comments on commit f1ebec6

Please sign in to comment.