Ask on close

main
Thomas Battermann 10 years ago committed by Thomas Ba
parent a3077208e5
commit f984bf7b34

@ -287,11 +287,11 @@ public class Controller {
}
n = primaryStage.getScene().lookup("#menuClose");
if ( n != null && n instanceof Button ) {
((Button) n).setOnAction(event -> Platform.exit());
((Button) n).setOnAction(event -> showCloseDialog());
}else{
ErrorPrinter.printWarning("showMainWindow > Couldnt find element '#menuClose'");
}
this.primaryStage.setOnCloseRequest(event -> Platform.exit());
this.primaryStage.setOnCloseRequest(event -> showCloseDialog());
n = primaryStage.getScene().lookup("#todoDetailSave");
if ( n != null && n instanceof Button) {
((Button) n).setOnAction(event -> this.saveTodoEntry());
@ -497,6 +497,10 @@ public class Controller {
}
private void showSaveAs() {
showSaveAs(false);
}
private void showSaveAs(boolean exitAfterSave) {
Stage save = new Stage();
try {
save.setScene(new Scene(FXMLLoader.load(getClass().getResource("saveAs.fxml")),500,150));
@ -521,8 +525,13 @@ public class Controller {
if (!file.isDirectory()) {
if (this.filename == null)
this.filename = f.getText();
if (this.export(f.getText()))
save.close();
if (this.export(f.getText())) {
if (exitAfterSave) {
Platform.exit();
} else {
save.close();
}
}
} else {
this.updateStatusLine("Cant write to file!");
}
@ -928,6 +937,44 @@ public class Controller {
});
}
private void showCloseDialog() {
Stage close = new Stage();
try {
close.setScene(new Scene(FXMLLoader.load(getClass().getResource("close.fxml"))));
} catch (IOException e) {
ErrorPrinter.printError("showCloseDialog > Failed to open window 'close'! Goodbye!");
e.printStackTrace();
Platform.exit();
}
close.setTitle("Close program?");
close.show();
Node n = close.getScene().lookup("#abort");
if ( n == null || !(n instanceof Button)) {
ErrorPrinter.printWarning("showCloseDialog > Didnt find element #abort");
return;
}
((Button) n).setOnAction(event -> close.close());
n = close.getScene().lookup("#save");
if ( n == null || !(n instanceof Button)) {
ErrorPrinter.printWarning("showCloseDialog > Didnt find element #save");
return;
}
((Button) n).setOnAction(event -> {
if (this.filename != null) {
this.export(this.filename);
Platform.exit();
} else {
this.showSaveAs(true);
}
});
n = close.getScene().lookup("#close");
if ( n == null || !(n instanceof Button)) {
ErrorPrinter.printWarning("showCloseDialog > Didnt find element #close");
return;
}
((Button) n).setOnAction(event -> Platform.exit());
}
/**
* Notify a list about a changed item
* Taken from: http://stackoverflow.com/a/21435063

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<TitledPane animated="false" collapsible="false" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" text="Close the program?" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.45">
<font>
<Font name="System Bold" size="13.0" />
</font>
<content>
<VBox>
<children>
<Button id="abort" cancelButton="true" defaultButton="true" minWidth="250.0" mnemonicParsing="false" text="No, dont close" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets bottom="10.0" />
</VBox.margin>
</Button>
<Button id="save" minWidth="250.0" mnemonicParsing="false" text="Yes, but save the changes" textFill="#0cb228">
<VBox.margin>
<Insets bottom="10.0" />
</VBox.margin>
</Button>
<Button id="close" minWidth="250.0" mnemonicParsing="false" text="Yes and discard the changes" textFill="#b20000" />
</children>
</VBox>
</content>
</TitledPane>
Loading…
Cancel
Save