2424import org .slf4j .Logger ;
2525import org .slf4j .LoggerFactory ;
2626
27+ import com .sun .javafx .scene .control .skin .ComboBoxListViewSkin ;
28+
2729import de .doubleslash .keeptime .common .ColorHelper ;
2830import de .doubleslash .keeptime .common .StyleUtils ;
2931import de .doubleslash .keeptime .model .Model ;
3941import javafx .scene .control .ComboBox ;
4042import javafx .scene .control .DatePicker ;
4143import javafx .scene .control .ListCell ;
44+ import javafx .scene .control .ListView ;
4245import javafx .scene .control .Spinner ;
4346import javafx .scene .control .SpinnerValueFactory ;
4447import javafx .scene .control .TextArea ;
4548import javafx .scene .input .KeyCode ;
49+ import javafx .scene .input .KeyCodeCombination ;
50+ import javafx .scene .input .KeyEvent ;
4651import javafx .scene .layout .GridPane ;
4752import javafx .scene .paint .Color ;
4853import javafx .util .StringConverter ;
@@ -198,6 +203,8 @@ public Project fromString(final String string) {
198203
199204 );
200205
206+ enableStrgA_combo ();
207+
201208 projectComboBox .getEditor ().textProperty ().addListener (new ChangeListener <String >() {
202209
203210 boolean isValidProject = true ;
@@ -283,7 +290,29 @@ public void initializeWith(final Work work) {
283290 setColor (projectComboBox .getEditor (), model .hoverBackgroundColor .get ());
284291
285292 setTextColor (projectComboBox .getEditor (), model .hoverFontColor .get ());
293+ }
294+
295+ public Work getWorkFromUserInput () {
296+ return new Work (startDatePicker .getValue (),
297+ LocalDateTime .of (startDatePicker .getValue (), startTimeSpinner .getValue ()),
298+ LocalDateTime .of (endDatePicker .getValue (), endTimeSpinner .getValue ()), selectedProject ,
299+ noteTextArea .getText ());
300+ }
286301
302+ private void enableStrgA_combo () {
303+ // strg+a Behaviour bug hack
304+ // https://stackoverflow.com/questions/51943654/javafx-combobox-make-control-a-select-all-in-text-box-while-dropdown-is-visi
305+ projectComboBox .setOnShown (e -> {
306+ final ComboBoxListViewSkin <?> skin = (ComboBoxListViewSkin <?>) projectComboBox .getSkin ();
307+ final ListView <?> list = (ListView <?>) skin .getPopupContent ();
308+ final KeyCodeCombination ctrlA = new KeyCodeCombination (KeyCode .A , KeyCodeCombination .CONTROL_DOWN );
309+ list .addEventFilter (KeyEvent .KEY_PRESSED , keyEvent -> {
310+ if (ctrlA .match (keyEvent )) {
311+ projectComboBox .getEditor ().selectAll ();
312+ }
313+ });
314+ projectComboBox .setOnShown (null );
315+ });
287316 }
288317
289318 private void setColor (final Node object , final Color color ) {
@@ -298,12 +327,4 @@ private void setTextColor(final Node object, final Color color) {
298327 object .setStyle (style );
299328 }
300329
301- public Work getWorkFromUserInput () {
302-
303- return new Work (startDatePicker .getValue (),
304- LocalDateTime .of (startDatePicker .getValue (), startTimeSpinner .getValue ()),
305- LocalDateTime .of (endDatePicker .getValue (), endTimeSpinner .getValue ()), selectedProject ,
306- noteTextArea .getText ());
307- }
308-
309330}
0 commit comments