-
-
Notifications
You must be signed in to change notification settings - Fork 3k
ESC closes the preferences dialog when editing table. #14106
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
Changes from 3 commits
ae51634
2a244a3
53bdb65
026b018
287680d
ff149a1
c36c778
5b3eb1f
f3b56cb
6fc48b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,12 +3,14 @@ | |
| import java.util.Locale; | ||
| import java.util.Optional; | ||
|
|
||
| import javafx.application.Platform; | ||
| import javafx.fxml.FXML; | ||
| import javafx.scene.control.ButtonType; | ||
| import javafx.scene.control.ListView; | ||
| import javafx.scene.control.ScrollPane; | ||
| import javafx.scene.control.ToggleButton; | ||
| import javafx.scene.input.KeyCode; | ||
| import javafx.scene.input.KeyEvent; | ||
|
|
||
| import org.jabref.gui.DialogService; | ||
| import org.jabref.gui.icon.IconTheme; | ||
|
|
@@ -115,6 +117,58 @@ private void initialize() { | |
| memoryStickMode.selectedProperty().bindBidirectional(viewModel.getMemoryStickProperty()); | ||
|
|
||
| viewModel.setValues(); | ||
| // Delay execution until JavaFX has completed layout and the Scene object is attached to the DialogPane | ||
| Platform.runLater(this::installGlobalCloseBehavior); | ||
| } | ||
|
|
||
| private void installGlobalCloseBehavior() { | ||
| var scene = getDialogPane().getScene(); | ||
|
|
||
| // Capture events BEFORE child nodes | ||
| scene.addEventFilter(KeyEvent.KEY_PRESSED, e -> { | ||
| if (!preferences.getKeyBindingRepository().checkKeyCombinationEquality(KeyBinding.CLOSE, e)) { | ||
| return; | ||
| } | ||
|
|
||
| // If any cell-based control is editing (ListView/TableView/TreeView/TreeTableView), | ||
| // record that the close input is for canceling edit; DO NOT consume, let the control cancel. | ||
| if (isAnyCellControlEditing()) { | ||
| return; | ||
| } | ||
|
|
||
| // No editing in progress --> close dialog | ||
| closeDialog(); | ||
| e.consume(); | ||
| }); | ||
| } | ||
|
|
||
| private boolean isAnyCellControlEditing() { | ||
| var root = getDialogPane(); | ||
|
|
||
| for (var n : root.lookupAll(".list-view")) { | ||
| if (n instanceof javafx.scene.control.ListView<?> lv && lv.getEditingIndex() != -1) { | ||
|
||
| return true; | ||
| } | ||
| } | ||
|
|
||
| for (var n : root.lookupAll(".table-view")) { | ||
| if (n instanceof javafx.scene.control.TableView<?> tv && tv.getEditingCell() != null) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| for (var n : root.lookupAll(".tree-view")) { | ||
| if (n instanceof javafx.scene.control.TreeView<?> trv && trv.getEditingItem() != null) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| for (var n : root.lookupAll(".tree-table-view")) { | ||
| if (n instanceof javafx.scene.control.TreeTableView<?> ttv && ttv.getEditingCell() != null) { | ||
| return true; | ||
|
||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| @FXML | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| // BaseDialog.java | ||
|
|
||
|
||
| package org.jabref.gui.util; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We avoid var and use explicit types