close message sign dialog on platform button and escape key

This commit is contained in:
Craig Raw 2021-06-28 13:32:24 +02:00
parent 324540009a
commit ea2f858dc9

View file

@ -51,6 +51,7 @@ public class MessageSignDialog extends Dialog<ButtonBar.ButtonData> {
private final Wallet wallet; private final Wallet wallet;
private WalletNode walletNode; private WalletNode walletNode;
private boolean electrumSignatureFormat; private boolean electrumSignatureFormat;
private boolean closed;
/** /**
* Verification only constructor * Verification only constructor
@ -177,7 +178,7 @@ public class MessageSignDialog extends Dialog<ButtonBar.ButtonData> {
ButtonType signButtonType = new javafx.scene.control.ButtonType("Sign", ButtonBar.ButtonData.BACK_PREVIOUS); ButtonType signButtonType = new javafx.scene.control.ButtonType("Sign", ButtonBar.ButtonData.BACK_PREVIOUS);
ButtonType verifyButtonType = new javafx.scene.control.ButtonType("Verify", ButtonBar.ButtonData.NEXT_FORWARD); ButtonType verifyButtonType = new javafx.scene.control.ButtonType("Verify", ButtonBar.ButtonData.NEXT_FORWARD);
ButtonType doneButtonType = new javafx.scene.control.ButtonType("Done", ButtonBar.ButtonData.OK_DONE); ButtonType doneButtonType = new javafx.scene.control.ButtonType("Done", ButtonBar.ButtonData.CANCEL_CLOSE);
if(buttons.length > 0) { if(buttons.length > 0) {
dialogPane.getButtonTypes().addAll(buttons); dialogPane.getButtonTypes().addAll(buttons);
@ -189,7 +190,7 @@ public class MessageSignDialog extends Dialog<ButtonBar.ButtonData> {
customSignButton.setOnAction(event -> { customSignButton.setOnAction(event -> {
customSignButton.setDisable(true); customSignButton.setDisable(true);
signMessage(); signMessage();
setResult(ButtonBar.ButtonData.OK_DONE); setResult(ButtonBar.ButtonData.CANCEL_CLOSE);
}); });
} }
} else { } else {
@ -240,9 +241,13 @@ public class MessageSignDialog extends Dialog<ButtonBar.ButtonData> {
return; return;
} }
if(!closed) {
EventManager.get().unregister(this); EventManager.get().unregister(this);
closed = true;
}
}); });
AppServices.onEscapePressed(dialogPane.getScene(), () -> setResult(ButtonBar.ButtonData.CANCEL_CLOSE));
AppServices.moveToActiveWindowScreen(this); AppServices.moveToActiveWindowScreen(this);
setResultConverter(dialogButton -> dialogButton == signButtonType || dialogButton == verifyButtonType ? ButtonBar.ButtonData.APPLY : dialogButton.getButtonData()); setResultConverter(dialogButton -> dialogButton == signButtonType || dialogButton == verifyButtonType ? ButtonBar.ButtonData.APPLY : dialogButton.getButtonData());