Skip to content

Commit

Permalink
Add option to not show exit confirmation dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
SamCarlberg committed Nov 22, 2017
1 parent 93a559f commit 72e490d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -28,6 +27,8 @@ public final class AppPreferences {
private final Property<File> 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();
Expand All @@ -41,11 +42,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() {
Expand All @@ -59,7 +62,8 @@ public ImmutableList<Property<?>> getProperties() {
return ImmutableList.of(
theme,
defaultTileSize,
autoLoadLastSaveFile
autoLoadLastSaveFile,
confirmExit
);
}

Expand Down Expand Up @@ -110,4 +114,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);
}
}

0 comments on commit 72e490d

Please sign in to comment.