Where is the message for the defaut ParticleApplication?

87 Views Asked by At

I am creating a Gluon ParticleApplication and i need to change the exit message and/or exit procedure, where is it or what should i override? Thanks for the answer.

1

There are 1 best solutions below

0
On BEST ANSWER

The current implementation uses an Alert dialog to display a message whenever there's an exit event (from toolbar or menu actions) or from a close request event.

While this dialog is not customizable, there is a showCloseConfirmation property that allows you cancelling that dialog, so you can silently quit the application or you can provide your own dialog.

For instance, based on the default single desktop project created with the Gluon Plugin, we could modify the exit action under MenuActions:

@Inject
ParticleApplication app;

@ActionProxy(text="Exit", accelerator="alt+F4")
private void exit() {
    // disable built-in dialog
    app.setShowCloseConfirmation(false);
    // create a custom dialog
    Alert dialog = new Alert(Alert.AlertType.CONFIRMATION, "Custom exit Message");
    Optional<ButtonType> result = dialog.showAndWait();
    if(result.isPresent() && result.get().equals(ButtonType.OK)) {
        app.exit();
    }
}

Also, you will need to process close request events, in the main class, consuming those events and calling your exit action:

@Override
public void postInit(Scene scene) {
    ...
    scene.windowProperty().addListener(new InvalidationListener() {
        @Override
        public void invalidated(Observable observable) {
            scene.getWindow().setOnCloseRequest(e -> {
                e.consume();
                action("exit").handle(new ActionEvent());
            });

            scene.windowProperty().removeListener(this);
        }
    });
}