Skip to content

Commit b06e443

Browse files
authored
Fix adding and removing selected entries to group context menu (JabRef#10408)
* Fix adding and removing selected entries to group context menu Fixes JabRef#10403 Fixes JabRef#10317 Fixes JabRef#10374 * remove globals fix checkstyle
1 parent c498324 commit b06e443

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
7676
- 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)
7777
- We added a privacy policy. [#10064](https://github.com/JabRef/jabref/issues/10064)
7878
- We added a tooltip to show the number of entries in a group [#10208](https://github.com/JabRef/jabref/issues/10208)
79+
- 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)
7980

8081
### Changed
8182

src/main/java/org/jabref/gui/groups/GroupTreeView.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import javafx.scene.input.ClipboardContent;
3535
import javafx.scene.input.DragEvent;
3636
import javafx.scene.input.Dragboard;
37+
import javafx.scene.input.MouseButton;
3738
import javafx.scene.input.MouseEvent;
3839
import javafx.scene.input.TransferMode;
3940
import javafx.scene.layout.BorderPane;
@@ -44,7 +45,6 @@
4445

4546
import org.jabref.gui.DialogService;
4647
import org.jabref.gui.DragAndDropDataFormats;
47-
import org.jabref.gui.Globals;
4848
import org.jabref.gui.StateManager;
4949
import org.jabref.gui.actions.ActionFactory;
5050
import org.jabref.gui.actions.SimpleCommand;
@@ -225,7 +225,10 @@ private void initialize() {
225225
new ViewModelTreeTableRowFactory<GroupNodeViewModel>()
226226
.withContextMenu(this::createContextMenuForGroup)
227227
.withEventFilter(MouseEvent.MOUSE_PRESSED, (row, event) -> {
228-
if (event.getTarget() instanceof StackPane pane) {
228+
if (((MouseEvent) event).getButton() == MouseButton.SECONDARY && !stateManager.getSelectedEntries().isEmpty()) {
229+
// Prevent right-click to select group whe we have selected entries
230+
event.consume();
231+
} else if (event.getTarget() instanceof StackPane pane) {
229232
if (pane.getStyleClass().contains("arrow") || pane.getStyleClass().contains("tree-disclosure-node")) {
230233
event.consume();
231234
}
@@ -481,7 +484,7 @@ private ContextMenu createContextMenuForGroup(GroupNodeViewModel group) {
481484
}
482485

483486
ContextMenu contextMenu = new ContextMenu();
484-
ActionFactory factory = new ActionFactory(Globals.getKeyPrefs());
487+
ActionFactory factory = new ActionFactory(preferencesService.getKeyBindingRepository());
485488

486489
MenuItem removeGroup;
487490
if (group.hasSubgroups() && group.canAddGroupsIn() && !group.isRoot()) {

src/main/java/org/jabref/gui/util/ViewModelTreeTableRowFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class ViewModelTreeTableRowFactory<S> implements Callback<TreeTableView<S
3838
private TriConsumer<TreeTableRow<S>, S, ? super DragEvent> toOnDragExited;
3939
private TriConsumer<TreeTableRow<S>, S, ? super DragEvent> toOnDragOver;
4040
private TriConsumer<TreeTableRow<S>, S, ? super MouseDragEvent> toOnMouseDragEntered;
41-
private final Map<EventType<?>, BiConsumer<S, ? super Event>> eventFilters = new HashMap<>();
41+
private final Map<EventType<? extends Event>, BiConsumer<S, ? super Event>> eventFilters = new HashMap<>();
4242
private final Map<PseudoClass, Callback<TreeTableRow<S>, ObservableValue<Boolean>>> pseudoClasses = new HashMap<>();
4343

4444
public ViewModelTreeTableRowFactory<S> withOnMouseClickedEvent(BiConsumer<S, ? super MouseEvent> event) {
@@ -117,7 +117,7 @@ public ViewModelTreeTableRowFactory<S> withPseudoClass(PseudoClass pseudoClass,
117117
return this;
118118
}
119119

120-
public ViewModelTreeTableRowFactory<S> withEventFilter(EventType<?> event, BiConsumer<S, ? super Event> toCondition) {
120+
public ViewModelTreeTableRowFactory<S> withEventFilter(EventType<? extends Event> event, BiConsumer<S, ? super Event> toCondition) {
121121
this.eventFilters.putIfAbsent(event, toCondition);
122122
return this;
123123
}

0 commit comments

Comments
 (0)