Skip to content

Commit

Permalink
Fix adding and removing selected entries to group context menu (#10408)
Browse files Browse the repository at this point in the history
* Fix adding and removing selected entries to group context menu

Fixes #10403
Fixes #10317
Fixes #10374

* remove globals
fix checkstyle
  • Loading branch information
Siedlerchr committed Sep 25, 2023
1 parent c498324 commit b06e443
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We added the option to automatically replaces illegal characters in the filename when adding a file to JabRef. [#10182](https://github.com/JabRef/jabref/issues/10182)
- We added a privacy policy. [#10064](https://github.com/JabRef/jabref/issues/10064)
- We added a tooltip to show the number of entries in a group [#10208](https://github.com/JabRef/jabref/issues/10208)
- We fixed an issue where it was no longer possible to add or remove selected entries to groups via context menu [#10404](https://github.com/JabRef/jabref/issues/10404), [#10317](https://github.com/JabRef/jabref/issues/10317) [#10374](https://github.com/JabRef/jabref/issues/10374)

### Changed

Expand Down
9 changes: 6 additions & 3 deletions src/main/java/org/jabref/gui/groups/GroupTreeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.DragEvent;
import javafx.scene.input.Dragboard;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.BorderPane;
Expand All @@ -44,7 +45,6 @@

import org.jabref.gui.DialogService;
import org.jabref.gui.DragAndDropDataFormats;
import org.jabref.gui.Globals;
import org.jabref.gui.StateManager;
import org.jabref.gui.actions.ActionFactory;
import org.jabref.gui.actions.SimpleCommand;
Expand Down Expand Up @@ -225,7 +225,10 @@ private void initialize() {
new ViewModelTreeTableRowFactory<GroupNodeViewModel>()
.withContextMenu(this::createContextMenuForGroup)
.withEventFilter(MouseEvent.MOUSE_PRESSED, (row, event) -> {
if (event.getTarget() instanceof StackPane pane) {
if (((MouseEvent) event).getButton() == MouseButton.SECONDARY && !stateManager.getSelectedEntries().isEmpty()) {
// Prevent right-click to select group whe we have selected entries
event.consume();
} else if (event.getTarget() instanceof StackPane pane) {
if (pane.getStyleClass().contains("arrow") || pane.getStyleClass().contains("tree-disclosure-node")) {
event.consume();
}
Expand Down Expand Up @@ -481,7 +484,7 @@ private ContextMenu createContextMenuForGroup(GroupNodeViewModel group) {
}

ContextMenu contextMenu = new ContextMenu();
ActionFactory factory = new ActionFactory(Globals.getKeyPrefs());
ActionFactory factory = new ActionFactory(preferencesService.getKeyBindingRepository());

MenuItem removeGroup;
if (group.hasSubgroups() && group.canAddGroupsIn() && !group.isRoot()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ViewModelTreeTableRowFactory<S> implements Callback<TreeTableView<S
private TriConsumer<TreeTableRow<S>, S, ? super DragEvent> toOnDragExited;
private TriConsumer<TreeTableRow<S>, S, ? super DragEvent> toOnDragOver;
private TriConsumer<TreeTableRow<S>, S, ? super MouseDragEvent> toOnMouseDragEntered;
private final Map<EventType<?>, BiConsumer<S, ? super Event>> eventFilters = new HashMap<>();
private final Map<EventType<? extends Event>, BiConsumer<S, ? super Event>> eventFilters = new HashMap<>();
private final Map<PseudoClass, Callback<TreeTableRow<S>, ObservableValue<Boolean>>> pseudoClasses = new HashMap<>();

public ViewModelTreeTableRowFactory<S> withOnMouseClickedEvent(BiConsumer<S, ? super MouseEvent> event) {
Expand Down Expand Up @@ -117,7 +117,7 @@ public ViewModelTreeTableRowFactory<S> withPseudoClass(PseudoClass pseudoClass,
return this;
}

public ViewModelTreeTableRowFactory<S> withEventFilter(EventType<?> event, BiConsumer<S, ? super Event> toCondition) {
public ViewModelTreeTableRowFactory<S> withEventFilter(EventType<? extends Event> event, BiConsumer<S, ? super Event> toCondition) {
this.eventFilters.putIfAbsent(event, toCondition);
return this;
}
Expand Down

0 comments on commit b06e443

Please sign in to comment.