33import java .util .Locale ;
44import java .util .Optional ;
55
6- import javafx .application .Platform ;
76import javafx .fxml .FXML ;
87import javafx .scene .control .ButtonType ;
98import javafx .scene .control .ListView ;
109import javafx .scene .control .ScrollPane ;
10+ import javafx .scene .control .TableView ;
1111import javafx .scene .control .ToggleButton ;
12+ import javafx .scene .control .TreeTableView ;
13+ import javafx .scene .control .TreeView ;
1214import javafx .scene .input .KeyCode ;
1315import 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
0 commit comments