Fix connection choice filter focus

This commit is contained in:
crschnick 2024-01-09 04:20:13 +00:00
parent 44945546f7
commit e4d3eb2a3d

View file

@ -13,7 +13,6 @@ import io.xpipe.app.storage.DataStoreEntryRef;
import io.xpipe.app.util.DataStoreCategoryChoiceComp;
import io.xpipe.core.store.DataStore;
import io.xpipe.core.store.ShellStore;
import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.beans.property.Property;
import javafx.beans.property.SimpleBooleanProperty;
@ -106,18 +105,7 @@ public class DataStoreChoiceComp<T extends DataStore> extends SimpleComp {
selectedCategory).styleClass(Styles.LEFT_PILL);
var filter = new FilterComp(filterText)
.styleClass(Styles.CENTER_PILL)
.hgrow()
.apply(struc -> {
popover.setOnShowing(event -> {
Platform.runLater(() -> {
Platform.runLater(() -> {
Platform.runLater(() -> {
struc.getText().requestFocus();
});
});
});
});
});
.hgrow();
var addButton = Comp.of(() -> {
MenuButton m = new MenuButton(null, new FontIcon("mdi2p-plus-box-outline"));
@ -132,6 +120,15 @@ public class DataStoreChoiceComp<T extends DataStore> extends SimpleComp {
var top = new HorizontalComp(List.of(category, filter.hgrow(), addButton))
.styleClass("top")
.apply(struc -> struc.get().setFillHeight(true))
.apply(struc -> {
// Ugly solution to focus the text field
// Somehow this does not work through the normal on shown listeners
struc.get().getChildren().get(0).focusedProperty().addListener((observable, oldValue, newValue) -> {
if (newValue) {
((StackPane) struc.get().getChildren().get(1)).getChildren().get(1).requestFocus();
}
});
})
.createStructure().get();
var r = section.vgrow().createRegion();
var content = new VBox(top, r);
@ -146,12 +143,6 @@ public class DataStoreChoiceComp<T extends DataStore> extends SimpleComp {
popover.setHeaderAlwaysVisible(true);
popover.setDetachable(true);
popover.setTitle(AppI18n.get("selectConnection"));
popover.setOnShowing(event -> {
Platform.runLater(() -> {
((StackPane) top.getChildren().get(1)).getChildren().get(1).requestFocus();
});
event.consume();
});
AppFont.small(popover.getContentNode());
}