diff --git a/CHANGELOG.md b/CHANGELOG.md index 26a9271d860..d432a948b41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,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/Base.css b/src/main/java/org/jabref/gui/Base.css index bf25ba043b3..b1b6894a6da 100644 --- a/src/main/java/org/jabref/gui/Base.css +++ b/src/main/java/org/jabref/gui/Base.css @@ -1055,6 +1055,27 @@ We want to have a look that matches our icons in the tool-bar */ -fx-fill: -fx-text-background-color; } +/* Drag and drop colored indicator */ + +.table-row-cell:dragOver-bottom { + -fx-border-color: -jr-drag-target; + -fx-border-width: 0 0 2 0; + -fx-padding: 0 0 -2 0; +} + +.table-row-cell:dragOver-center { + -fx-border-color: -jr-drag-target; + -fx-border-width: 1 1 1 1; + -fx-padding: -1 -1 -1 -1; + -fx-background-color: -jr-drag-target-hover; +} + +.table-row-cell:dragOver-top { + -fx-border-color: -jr-drag-target; + -fx-border-width: 2 0 0 0; + -fx-padding: -2 0 0 0; +} + /* Improve the context menu of the main toolbar, when icons don't fit and you have to press the little arrow to see them */ .mainToolbar .context-menu .glyph-icon { -fx-fill: -jr-theme-text; diff --git a/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java b/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java index 59b61392554..a376fd1acb0 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; @@ -63,7 +62,6 @@ public class CustomizeEntryTypeDialogView extends BaseDialog { @FXML private Button addNewEntryTypeButton; @FXML private Button addNewFieldButton; - @Inject private PreferencesService preferencesService; @Inject private StateManager stateManager; @Inject private DialogService dialogService; @@ -184,12 +182,14 @@ private void setupTable() { .setOnDragDetected(this::handleOnDragDetected) .setOnDragDropped(this::handleOnDragDropped) .setOnDragOver(this::handleOnDragOver) + .setOnDragExited(this::handleOnDragExited) .install(fields); } - private void handleOnDragOver(FieldViewModel originalItem, DragEvent event) { + private void handleOnDragOver(TableRow row, FieldViewModel originalItem, DragEvent event) { if ((event.getGestureSource() != originalItem) && event.getDragboard().hasContent(DragAndDropDataFormats.FIELD)) { event.acceptTransferModes(TransferMode.MOVE); + ControlHelper.setDroppingPseudoClasses(row, event); } } @@ -206,30 +206,27 @@ 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(); } + private void handleOnDragExited(TableRow row, FieldViewModel fieldViewModel, DragEvent dragEvent) { + ControlHelper.removeDroppingPseudoClasses(row); + } + @FXML void addEntryType() { EntryTypeViewModel newlyAdded = viewModel.addNewCustomEntryType();