From 9bf53ab0cd4ea406ca0a1af4f92d5db2534c7f70 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Wed, 2 Feb 2022 08:58:39 +0200 Subject: [PATCH] request focus on password field for encrypted locked wallets when wallet window becomes active --- .../sparrow/wallet/WalletController.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/WalletController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/WalletController.java index 933c1250..ad9efe16 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/WalletController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/WalletController.java @@ -12,6 +12,9 @@ import com.sparrowwallet.sparrow.io.Storage; import javafx.application.Platform; import javafx.beans.property.BooleanProperty; import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.beans.value.WeakChangeListener; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.fxml.Initializable; @@ -48,8 +51,19 @@ public class WalletController extends WalletFormController implements Initializa private BorderPane lockPane; + private CustomPasswordField passwordField; + private final BooleanProperty walletEncryptedProperty = new SimpleBooleanProperty(false); + private final ChangeListener lockFocusListener = new ChangeListener<>() { + @Override + public void changed(ObservableValue observable, Boolean oldValue, Boolean newValue) { + if(newValue && getWalletForm().isLocked() && passwordField != null && passwordField.isVisible()) { + passwordField.requestFocus(); + } + } + }; + @Override public void initialize(URL location, ResourceBundle resources) { EventManager.get().register(this); @@ -148,7 +162,7 @@ public class WalletController extends WalletFormController implements Initializa Label label = new Label("Enter password to unlock:"); label.managedProperty().bind(label.visibleProperty()); label.visibleProperty().bind(walletEncryptedProperty); - CustomPasswordField passwordField = new ViewPasswordField(); + passwordField = new ViewPasswordField(); passwordField.setMaxWidth(300); passwordField.managedProperty().bind(passwordField.visibleProperty()); passwordField.visibleProperty().bind(walletEncryptedProperty); @@ -165,6 +179,8 @@ public class WalletController extends WalletFormController implements Initializa stackPane.getChildren().add(vBox); lockPane.setCenter(stackPane); walletPane.getChildren().add(lockPane); + + walletPane.getScene().getWindow().focusedProperty().addListener(new WeakChangeListener<>(lockFocusListener)); } private void unlockWallet(CustomPasswordField passwordField) {