Skip to content

Commit 026b018

Browse files
committed
Changes in the fix
1 parent 2a244a3 commit 026b018

File tree

2 files changed

+11
-55
lines changed

2 files changed

+11
-55
lines changed

jabgui/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java

Lines changed: 11 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
import java.util.Locale;
44
import java.util.Optional;
55

6-
import javafx.application.Platform;
76
import javafx.fxml.FXML;
87
import javafx.scene.control.ButtonType;
98
import javafx.scene.control.ListView;
109
import javafx.scene.control.ScrollPane;
10+
import javafx.scene.control.TableView;
1111
import javafx.scene.control.ToggleButton;
12+
import javafx.scene.control.TreeTableView;
13+
import javafx.scene.control.TreeView;
1214
import javafx.scene.input.KeyCode;
1315
import javafx.scene.input.KeyEvent;
1416

@@ -95,6 +97,14 @@ private void initialize() {
9597
preferencesContainer.setContent(preferencesTab.getBuilder());
9698
preferencesTab.prefWidthProperty().bind(preferencesContainer.widthProperty().subtract(10d));
9799
preferencesTab.getStyleClass().add("preferencesTab");
100+
this.getDialogPane().addEventFilter(KeyEvent.KEY_PRESSED, event -> {
101+
if (preferences.getKeyBindingRepository().checkKeyCombinationEquality(KeyBinding.CLOSE, event)) {
102+
if (event.getTarget() instanceof ListView || event.getTarget() instanceof TableView || event.getTarget() instanceof TreeView || event.getTarget() instanceof TreeTableView) {
103+
this.closeDialog();
104+
event.consume();
105+
}
106+
}
107+
});
98108
} else {
99109
preferencesContainer.setContent(null);
100110
}
@@ -117,58 +127,6 @@ private void initialize() {
117127
memoryStickMode.selectedProperty().bindBidirectional(viewModel.getMemoryStickProperty());
118128

119129
viewModel.setValues();
120-
// Delay execution until JavaFX has completed layout and the Scene object is attached to the DialogPane
121-
Platform.runLater(this::installGlobalCloseBehavior);
122-
}
123-
124-
private void installGlobalCloseBehavior() {
125-
var scene = getDialogPane().getScene();
126-
127-
// Capture events BEFORE child nodes
128-
scene.addEventFilter(KeyEvent.KEY_PRESSED, e -> {
129-
if (!preferences.getKeyBindingRepository().checkKeyCombinationEquality(KeyBinding.CLOSE, e)) {
130-
return;
131-
}
132-
133-
// If any cell-based control is editing (ListView/TableView/TreeView/TreeTableView),
134-
// record that the close input is for canceling edit; DO NOT consume, let the control cancel.
135-
if (isAnyCellControlEditing()) {
136-
return;
137-
}
138-
139-
// No editing in progress --> close dialog
140-
closeDialog();
141-
e.consume();
142-
});
143-
}
144-
145-
private boolean isAnyCellControlEditing() {
146-
var root = getDialogPane();
147-
148-
for (var n : root.lookupAll(".list-view")) {
149-
if (n instanceof javafx.scene.control.ListView<?> lv && lv.getEditingIndex() != -1) {
150-
return true;
151-
}
152-
}
153-
154-
for (var n : root.lookupAll(".table-view")) {
155-
if (n instanceof javafx.scene.control.TableView<?> tv && tv.getEditingCell() != null) {
156-
return true;
157-
}
158-
}
159-
160-
for (var n : root.lookupAll(".tree-view")) {
161-
if (n instanceof javafx.scene.control.TreeView<?> trv && trv.getEditingItem() != null) {
162-
return true;
163-
}
164-
}
165-
166-
for (var n : root.lookupAll(".tree-table-view")) {
167-
if (n instanceof javafx.scene.control.TreeTableView<?> ttv && ttv.getEditingCell() != null) {
168-
return true;
169-
}
170-
}
171-
return false;
172130
}
173131

174132
@FXML

jabgui/src/main/java/org/jabref/gui/util/BaseDialog.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// BaseDialog.java
2-
31
package org.jabref.gui.util;
42

53
import java.util.Optional;

0 commit comments

Comments
 (0)