Rework choice pane handling for #125

This commit is contained in:
crschnick 2023-12-24 13:22:53 +00:00
parent ea882bcc43
commit 8c8dd99ad2
2 changed files with 15 additions and 3 deletions

View file

@ -1,6 +1,7 @@
package io.xpipe.app.comp.base; package io.xpipe.app.comp.base;
import atlantafx.base.controls.Spacer; import atlantafx.base.controls.Spacer;
import atlantafx.base.theme.Styles;
import com.jfoenix.controls.JFXTabPane; import com.jfoenix.controls.JFXTabPane;
import io.xpipe.app.core.AppI18n; import io.xpipe.app.core.AppI18n;
import io.xpipe.app.fxcomps.Comp; import io.xpipe.app.fxcomps.Comp;
@ -200,7 +201,7 @@ public abstract class MultiStepComp extends Comp<CompStructure<VBox>> {
var nextText = Bindings.createStringBinding( var nextText = Bindings.createStringBinding(
() -> isLastPage() ? AppI18n.get("finishStep") : AppI18n.get("nextStep"), currentStep); () -> isLastPage() ? AppI18n.get("finishStep") : AppI18n.get("nextStep"), currentStep);
var nextButton = new ButtonComp(nextText, null, comp::next) var nextButton = new ButtonComp(nextText, null, comp::next)
.apply(struc -> struc.get().setDefaultButton(true)) .styleClass(Styles.ACCENT)
.styleClass("next"); .styleClass("next");
var previousButton = new ButtonComp(AppI18n.observable("previousStep"), null, comp::previous) var previousButton = new ButtonComp(AppI18n.observable("previousStep"), null, comp::previous)

View file

@ -9,6 +9,7 @@ import javafx.beans.property.Property;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.scene.control.ComboBox; import javafx.scene.control.ComboBox;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.Region; import javafx.scene.layout.Region;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.util.StringConverter; import javafx.util.StringConverter;
@ -31,6 +32,12 @@ public class ChoicePaneComp extends Comp<CompStructure<VBox>> {
public CompStructure<VBox> createBase() { public CompStructure<VBox> createBase() {
var list = FXCollections.observableArrayList(entries); var list = FXCollections.observableArrayList(entries);
var cb = new ComboBox<>(list); var cb = new ComboBox<>(list);
cb.setOnKeyPressed(event -> {
if (!cb.isShowing() && event.getCode().equals(KeyCode.ENTER)) {
cb.show();
event.consume();
}
});
cb.getSelectionModel().select(selected.getValue()); cb.getSelectionModel().select(selected.getValue());
cb.setConverter(new StringConverter<>() { cb.setConverter(new StringConverter<>() {
@Override @Override
@ -63,8 +70,12 @@ public class ChoicePaneComp extends Comp<CompStructure<VBox>> {
} else { } else {
vbox.getChildren().set(1, region); vbox.getChildren().set(1, region);
} }
}
});
region.requestFocus(); cb.showingProperty().addListener((observable, oldValue, newValue) -> {
if (!newValue && vbox.getChildren().size() > 1) {
vbox.getChildren().get(1).requestFocus();
} }
}); });