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

Improve Drag and Drop in Custom Entry types dialog #8121

Merged
merged 2 commits into from
Oct 6, 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 @@ -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
21 changes: 21 additions & 0 deletions src/main/java/org/jabref/gui/Base.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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 @@ -63,7 +62,6 @@ public class CustomizeEntryTypeDialogView extends BaseDialog<Void> {
@FXML private Button addNewEntryTypeButton;
@FXML private Button addNewFieldButton;


@Inject private PreferencesService preferencesService;
@Inject private StateManager stateManager;
@Inject private DialogService dialogService;
Expand Down Expand Up @@ -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<FieldViewModel> row, FieldViewModel originalItem, DragEvent event) {
if ((event.getGestureSource() != originalItem) && event.getDragboard().hasContent(DragAndDropDataFormats.FIELD)) {
event.acceptTransferModes(TransferMode.MOVE);
ControlHelper.setDroppingPseudoClasses(row, event);
}
}

Expand All @@ -206,30 +206,27 @@ 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();
}

private void handleOnDragExited(TableRow<FieldViewModel> row, FieldViewModel fieldViewModel, DragEvent dragEvent) {
ControlHelper.removeDroppingPseudoClasses(row);
}

@FXML
void addEntryType() {
EntryTypeViewModel newlyAdded = viewModel.addNewCustomEntryType();
Expand Down