Merge pull request #132 from haakonn/close-on-escape

Close "About" and "Introduction" when Escape key is pressed
This commit is contained in:
craigraw 2021-05-26 08:39:16 +02:00 committed by GitHub
commit 8a77f22158
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 2 deletions

View file

@ -351,7 +351,9 @@ public class AppController implements Initializable {
stage.setTitle("About " + MainApp.APP_NAME); stage.setTitle("About " + MainApp.APP_NAME);
stage.initStyle(org.controlsfx.tools.Platform.getCurrent() == org.controlsfx.tools.Platform.OSX ? StageStyle.UNDECORATED : StageStyle.DECORATED); stage.initStyle(org.controlsfx.tools.Platform.getCurrent() == org.controlsfx.tools.Platform.OSX ? StageStyle.UNDECORATED : StageStyle.DECORATED);
stage.setResizable(false); 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.setStage(stage);
controller.initializeView(); controller.initializeView();
setStageIcon(stage); setStageIcon(stage);
@ -1884,4 +1886,4 @@ public class AppController implements Initializable {
public void recieveAction(ReceiveActionEvent event) { public void recieveAction(ReceiveActionEvent event) {
selectTab(event.getWallet()); selectTab(event.getWallet());
} }
} }

View file

@ -31,6 +31,7 @@ import javafx.scene.control.Dialog;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.text.Font; import javafx.scene.text.Font;
import javafx.stage.Screen; import javafx.stage.Screen;
import javafx.stage.Stage; import javafx.stage.Stage;
@ -449,6 +450,14 @@ public class AppServices {
stage.hide(); stage.hide();
} }
public static void onEscapePressed(Scene scene, Runnable runnable) {
scene.setOnKeyPressed(event -> {
if(event.getCode() == KeyCode.ESCAPE) {
runnable.run();
}
});
}
public Map<Wallet, Storage> getOpenWallets() { public Map<Wallet, Storage> getOpenWallets() {
Map<Wallet, Storage> openWallets = new LinkedHashMap<>(); Map<Wallet, Storage> openWallets = new LinkedHashMap<>();
for(List<WalletTabData> walletTabDataList : walletWindows.values()) { for(List<WalletTabData> walletTabDataList : walletWindows.values()) {

View file

@ -12,6 +12,7 @@ public class WelcomeDialog extends Dialog<Mode> {
public WelcomeDialog() { public WelcomeDialog() {
final DialogPane dialogPane = getDialogPane(); final DialogPane dialogPane = getDialogPane();
AppServices.setStageIcon(dialogPane.getScene().getWindow()); AppServices.setStageIcon(dialogPane.getScene().getWindow());
AppServices.onEscapePressed(dialogPane.getScene(), this::close);
try { try {
FXMLLoader welcomeLoader = new FXMLLoader(AppServices.class.getResource("welcome.fxml")); FXMLLoader welcomeLoader = new FXMLLoader(AppServices.class.getResource("welcome.fxml"));