默认粒子应用程序的消息在哪里?
Where is the message for the defaut ParticleApplication?
我正在创建一个 Gluon ParticleApplication,我需要更改退出消息 and/or 退出程序,它在哪里或者我应该覆盖什么?
谢谢你的回答。
当前的实现使用 Alert
对话框在存在退出事件(来自工具栏或菜单操作)或来自关闭请求事件时显示消息。
虽然此对话框不可自定义,但有一个 showCloseConfirmation
属性 允许您取消该对话框,因此您可以静默退出应用程序或提供您自己的对话框。
例如,基于使用Gluon Plugin创建的默认单桌面项目,我们可以修改MenuActions
下的exit
动作:
@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();
}
}
此外,您还需要处理关闭请求事件,主要 class,使用这些事件并调用您的 exit
操作:
@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);
}
});
}
我正在创建一个 Gluon ParticleApplication,我需要更改退出消息 and/or 退出程序,它在哪里或者我应该覆盖什么? 谢谢你的回答。
当前的实现使用 Alert
对话框在存在退出事件(来自工具栏或菜单操作)或来自关闭请求事件时显示消息。
虽然此对话框不可自定义,但有一个 showCloseConfirmation
属性 允许您取消该对话框,因此您可以静默退出应用程序或提供您自己的对话框。
例如,基于使用Gluon Plugin创建的默认单桌面项目,我们可以修改MenuActions
下的exit
动作:
@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();
}
}
此外,您还需要处理关闭请求事件,主要 class,使用这些事件并调用您的 exit
操作:
@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);
}
});
}