From c096327be4b5f5cc485af80c08a946408fff24f1 Mon Sep 17 00:00:00 2001 From: Haakon Nilsen Date: Tue, 25 May 2021 22:13:51 +0200 Subject: [PATCH] Close "About" and "Introduction" when Escape key is pressed --- .../java/com/sparrowwallet/sparrow/AppController.java | 6 ++++-- src/main/java/com/sparrowwallet/sparrow/AppServices.java | 9 +++++++++ .../java/com/sparrowwallet/sparrow/WelcomeDialog.java | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/AppController.java b/src/main/java/com/sparrowwallet/sparrow/AppController.java index 98d93fa0..677e3972 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppController.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppController.java @@ -351,7 +351,9 @@ public class AppController implements Initializable { stage.setTitle("About " + MainApp.APP_NAME); stage.initStyle(org.controlsfx.tools.Platform.getCurrent() == org.controlsfx.tools.Platform.OSX ? StageStyle.UNDECORATED : StageStyle.DECORATED); stage.setResizable(false); - stage.setScene(new Scene(root)); + Scene scene = new Scene(root); + AppServices.onEscapePressed(scene, stage::close); + stage.setScene(scene); controller.setStage(stage); controller.initializeView(); setStageIcon(stage); @@ -1884,4 +1886,4 @@ public class AppController implements Initializable { public void recieveAction(ReceiveActionEvent event) { selectTab(event.getWallet()); } -} \ No newline at end of file +} diff --git a/src/main/java/com/sparrowwallet/sparrow/AppServices.java b/src/main/java/com/sparrowwallet/sparrow/AppServices.java index 2472c569..300ab29c 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppServices.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppServices.java @@ -31,6 +31,7 @@ import javafx.scene.control.Dialog; import javafx.scene.control.Label; import javafx.scene.image.Image; import javafx.scene.image.ImageView; +import javafx.scene.input.KeyCode; import javafx.scene.text.Font; import javafx.stage.Screen; import javafx.stage.Stage; @@ -449,6 +450,14 @@ public class AppServices { stage.hide(); } + public static void onEscapePressed(Scene scene, Runnable runnable) { + scene.setOnKeyPressed(event -> { + if(event.getCode() == KeyCode.ESCAPE) { + runnable.run(); + } + }); + } + public Map getOpenWallets() { Map openWallets = new LinkedHashMap<>(); for(List walletTabDataList : walletWindows.values()) { diff --git a/src/main/java/com/sparrowwallet/sparrow/WelcomeDialog.java b/src/main/java/com/sparrowwallet/sparrow/WelcomeDialog.java index c0282f25..843e9ddd 100644 --- a/src/main/java/com/sparrowwallet/sparrow/WelcomeDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/WelcomeDialog.java @@ -12,6 +12,7 @@ public class WelcomeDialog extends Dialog { public WelcomeDialog() { final DialogPane dialogPane = getDialogPane(); AppServices.setStageIcon(dialogPane.getScene().getWindow()); + AppServices.onEscapePressed(dialogPane.getScene(), this::close); try { FXMLLoader welcomeLoader = new FXMLLoader(AppServices.class.getResource("welcome.fxml"));