From f1ebec66fbf643c012c414afaf463e80e188281c Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Mon, 4 Oct 2021 21:00:51 +0200 Subject: [PATCH] Improve Drag and Drop Fixes #6338 --- CHANGELOG.md | 1 + .../CustomizeEntryTypeDialogView.java | 26 +++++++------------ 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f9d6cfbf71..511a7d51926 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java b/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java index 59b61392554..268e688720c 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java +++ b/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java @@ -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; @@ -206,27 +205,20 @@ private void handleOnDragDetected(TableRow row, FieldViewModel f } private void handleOnDragDropped(TableRow row, FieldViewModel originalItem, DragEvent event) { - boolean success = false; - - ObservableList 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(); }