From db3f3efc5289ca20d752c9e6035b70b3d6f519ba Mon Sep 17 00:00:00 2001 From: Sam Carlberg Date: Tue, 21 Nov 2017 17:57:53 -0500 Subject: [PATCH] Ask to save the current layout when closing shuffleboard Fixes #173 --- .../edu/wpi/first/shuffleboard/api/base.css | 8 +++++++ .../first/shuffleboard/app/Shuffleboard.java | 21 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/api/src/main/resources/edu/wpi/first/shuffleboard/api/base.css b/api/src/main/resources/edu/wpi/first/shuffleboard/api/base.css index 01f9de10f..49e62febe 100644 --- a/api/src/main/resources/edu/wpi/first/shuffleboard/api/base.css +++ b/api/src/main/resources/edu/wpi/first/shuffleboard/api/base.css @@ -235,3 +235,11 @@ /* Bring the content to all edges */ -fx-padding: 0; /* 10 0 0 10 */ } + +.dialog-pane .header-panel { + -fx-background-color: -swatch-500; +} + +.dialog-pane .header-panel .label { + -fx-text-fill: white; +} diff --git a/app/src/main/java/edu/wpi/first/shuffleboard/app/Shuffleboard.java b/app/src/main/java/edu/wpi/first/shuffleboard/app/Shuffleboard.java index 769ce47e5..d1a477617 100644 --- a/app/src/main/java/edu/wpi/first/shuffleboard/app/Shuffleboard.java +++ b/app/src/main/java/edu/wpi/first/shuffleboard/app/Shuffleboard.java @@ -28,6 +28,8 @@ import javafx.application.Platform; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; +import javafx.scene.control.Alert; +import javafx.scene.control.ButtonType; import javafx.scene.layout.Pane; import javafx.stage.Screen; import javafx.stage.Stage; @@ -90,6 +92,25 @@ public void start(Stage primaryStage) throws IOException { primaryStage.setMinHeight(480); primaryStage.setWidth(Screen.getPrimary().getVisualBounds().getWidth()); primaryStage.setHeight(Screen.getPrimary().getVisualBounds().getHeight()); + primaryStage.setOnCloseRequest(closeEvent -> { + Alert alert = new Alert(Alert.AlertType.CONFIRMATION); + alert.getDialogPane().getScene().getStylesheets().setAll(mainPane.getStylesheets()); + alert.getButtonTypes().setAll(ButtonType.YES, ButtonType.NO, ButtonType.CANCEL); + alert.getDialogPane().setHeaderText("Save the current layout?"); + alert.showAndWait().ifPresent(bt -> { + if (bt == ButtonType.YES) { + try { + mainWindowController.save(); + } catch (IOException ex) { + logger.log(Level.WARNING, "Could not save the layout", ex); + } + } else if (bt == ButtonType.CANCEL) { + // cancel the close request by consuming the event + closeEvent.consume(); + } + // Don't need to check for NO because it just lets the window close normally + }); + }); primaryStage.show(); Time.setStartTime(Time.now()); }