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 5bb871a3b..1d0c8c2d2 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 @@ -93,6 +93,10 @@ public void start(Stage primaryStage) throws IOException { primaryStage.setWidth(Screen.getPrimary().getVisualBounds().getWidth()); primaryStage.setHeight(Screen.getPrimary().getVisualBounds().getHeight()); primaryStage.setOnCloseRequest(closeEvent -> { + if (!AppPreferences.getInstance().isConfirmExit()) { + // Don't show the confirmation dialog, just exit + return; + } Alert alert = new Alert(Alert.AlertType.CONFIRMATION); alert.setTitle("Save layout"); alert.getDialogPane().getScene().getStylesheets().setAll(mainPane.getStylesheets()); diff --git a/app/src/main/java/edu/wpi/first/shuffleboard/app/prefs/AppPreferences.java b/app/src/main/java/edu/wpi/first/shuffleboard/app/prefs/AppPreferences.java index 5d3162289..e6df53304 100644 --- a/app/src/main/java/edu/wpi/first/shuffleboard/app/prefs/AppPreferences.java +++ b/app/src/main/java/edu/wpi/first/shuffleboard/app/prefs/AppPreferences.java @@ -18,8 +18,7 @@ import javafx.beans.property.SimpleObjectProperty; /** - * Contains the user preferences for the app. These preferences are user-specific and are saved - * to the users home directory and are not contained in save files. + * Contains the user preferences for the app. These preferences are user-specific and are not contained in save files. */ public final class AppPreferences { @@ -28,6 +27,7 @@ public final class AppPreferences { private final Property saveFile = new SimpleObjectProperty<>(this, "saveFile", null); private final BooleanProperty autoLoadLastSaveFile = new SimpleBooleanProperty(this, "automaticallyLoadLastSaveFile", true); + private final BooleanProperty confirmExit = new SimpleBooleanProperty(this, "showConfirmationDialogWhenExiting", true); @VisibleForTesting static AppPreferences instance = new AppPreferences(); @@ -41,11 +41,13 @@ public AppPreferences() { PreferencesUtils.read(defaultTileSize, preferences); PreferencesUtils.read(saveFile, preferences, File::new); PreferencesUtils.read(autoLoadLastSaveFile, preferences); + PreferencesUtils.read(confirmExit, preferences); theme.addListener(__ -> PreferencesUtils.save(theme, preferences, Theme::getName)); defaultTileSize.addListener(__ -> PreferencesUtils.save(defaultTileSize, preferences)); saveFile.addListener(__ -> PreferencesUtils.save(saveFile, preferences, File::getAbsolutePath)); autoLoadLastSaveFile.addListener(__ -> PreferencesUtils.save(autoLoadLastSaveFile, preferences)); + confirmExit.addListener(__ -> PreferencesUtils.save(confirmExit, preferences)); } public static AppPreferences getInstance() { @@ -59,7 +61,8 @@ public ImmutableList> getProperties() { return ImmutableList.of( theme, defaultTileSize, - autoLoadLastSaveFile + autoLoadLastSaveFile, + confirmExit ); } @@ -110,4 +113,16 @@ public BooleanProperty autoLoadLastSaveFileProperty() { public void setAutoLoadLastSaveFile(boolean autoLoadLastSaveFile) { this.autoLoadLastSaveFile.set(autoLoadLastSaveFile); } + + public boolean isConfirmExit() { + return confirmExit.get(); + } + + public BooleanProperty confirmExitProperty() { + return confirmExit; + } + + public void setConfirmExit(boolean confirmExit) { + this.confirmExit.set(confirmExit); + } }