Skip to content

Commit 49d07c0

Browse files
Maximilian StiedeleMaik
andauthored
Make chunk deletion confirmation dialog more intrusive (#1035)
* issue #1034 - add separators between different chunk operation groups, move "delete chunks" really far away from "clear selection" * issue #1034 - replace Alert confirmation dialog with special dialog which only enables the "OK" button after confirming a checkbox * add icons to chunk operations and fix naming of buttons * improve wording Co-authored-by: Maik Marschner <an@maik.tk>
1 parent a1d74b7 commit 49d07c0

3 files changed

Lines changed: 80 additions & 19 deletions

File tree

chunky/src/java/se/llbit/chunky/ui/ChunkyFxController.java

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import javafx.scene.control.Button;
4848
import javafx.scene.control.ButtonType;
4949
import javafx.scene.control.CheckBox;
50+
import javafx.scene.control.Dialog;
5051
import javafx.scene.control.Hyperlink;
5152
import javafx.scene.control.Label;
5253
import javafx.scene.control.MenuItem;
@@ -147,9 +148,9 @@ public class ChunkyFxController
147148
@FXML private Button creditsBtn;
148149
@FXML private DoubleTextField xPosition;
149150
@FXML private DoubleTextField zPosition;
150-
@FXML private Button deleteChunks;
151-
@FXML private Button exportZip;
152-
@FXML private Button renderPng;
151+
@FXML private Button deleteChunksBtn;
152+
@FXML private Button exportZipBtn;
153+
@FXML private Button renderPngBtn;
153154
@FXML private StackPane mapPane;
154155
@FXML private SplitPane splitPane;
155156
@FXML private TabPane mapTabs;
@@ -511,30 +512,36 @@ public synchronized void exportZip(File targetFile, ProgressTracker progress) {
511512
scale.set(newValue.scale);
512513
}));
513514

514-
deleteChunks.setTooltip(new Tooltip("Delete selected chunks."));
515-
deleteChunks.setOnAction(e -> {
516-
Alert alert = Dialogs.createAlert(Alert.AlertType.CONFIRMATION);
517-
alert.setTitle("Delete Selected Chunks");
518-
alert.setContentText(
519-
"Do you really want to delete the selected chunks? This can not be undone.");
520-
if (alert.showAndWait().orElse(ButtonType.CANCEL) == ButtonType.OK) {
515+
deleteChunksBtn.setTooltip(new Tooltip("Delete selected chunks."));
516+
deleteChunksBtn.setGraphic(new ImageView(Icon.clear.fxImage()));
517+
deleteChunksBtn.setOnAction(e -> {
518+
Dialog<ButtonType> confirmationDialog = Dialogs.createSpecialApprovalConfirmation(
519+
"Delete selected chunks",
520+
"Confirm deleting the selected chunks",
521+
"Do you really want to delete the selected chunks from the world?\nThis will remove the selected chunks from your disk and cannot be undone. Be sure to have a backup!",
522+
"I do want to permanently delete the selected chunks"
523+
);
524+
if (confirmationDialog.showAndWait().orElse(ButtonType.CANCEL) == ButtonType.OK) {
521525
deleteSelectedChunks(ProgressTracker.NONE);
522526
}
523527
});
524528

525-
exportZip.setTooltip(new Tooltip("Export selected chunks to Zip archive."));
526-
exportZip.setOnAction(e -> {
529+
exportZipBtn.setTooltip(new Tooltip("Export selected chunks to Zip archive."));
530+
exportZipBtn.setGraphic(new ImageView(Icon.save.fxImage()));
531+
exportZipBtn.setOnAction(e -> {
527532
FileChooser fileChooser = new FileChooser();
528533
fileChooser.setTitle("Export Chunks to Zip");
529534
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Zip files", "*.zip"));
530535
mapLoader.withWorld(world -> fileChooser.setInitialFileName(world.levelName() + ".zip"));
531-
File target = fileChooser.showSaveDialog(exportZip.getScene().getWindow());
536+
File target = fileChooser.showSaveDialog(exportZipBtn.getScene().getWindow());
532537
if (target != null) {
533538
exportZip(target, ProgressTracker.NONE);
534539
}
535540
});
536541

537-
renderPng.setOnAction(e -> {
542+
exportZipBtn.setTooltip(new Tooltip("Exports the current map view (not the selected chunks) as a PNG file."));
543+
renderPngBtn.setGraphic(new ImageView(Icon.save.fxImage()));
544+
renderPngBtn.setOnAction(e -> {
538545
FileChooser fileChooser = new FileChooser();
539546
fileChooser.setTitle("Export PNG");
540547
fileChooser
@@ -543,7 +550,7 @@ public synchronized void exportZip(File targetFile, ProgressTracker progress) {
543550
if (prevPngDir != null) {
544551
fileChooser.setInitialDirectory(prevPngDir.toFile());
545552
}
546-
File target = fileChooser.showSaveDialog(exportZip.getScene().getWindow());
553+
File target = fileChooser.showSaveDialog(exportZipBtn.getScene().getWindow());
547554
if (target != null) {
548555
Path path = target.toPath();
549556
if (!target.getName().endsWith(".png")) {
@@ -653,6 +660,7 @@ public synchronized void exportZip(File targetFile, ProgressTracker progress) {
653660

654661
menuExit.setAccelerator(new KeyCodeCombination(KeyCode.Q, KeyCombination.CONTROL_DOWN));
655662
clearSelectionBtn.setOnAction(event -> chunkSelection.clearSelection());
663+
clearSelectionBtn.setGraphic(new ImageView(Icon.clear.fxImage()));
656664

657665
mapView.setMapSize((int) mapCanvas.getWidth(), (int) mapCanvas.getHeight());
658666
mapOverlay.setOnScroll(map::onScroll);

chunky/src/java/se/llbit/fxutil/Dialogs.java

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22

33
import javafx.scene.control.Alert;
44
import javafx.scene.control.Alert.AlertType;
5+
import javafx.scene.control.ButtonType;
6+
import javafx.scene.control.CheckBox;
7+
import javafx.scene.control.Dialog;
8+
import javafx.scene.control.DialogPane;
59
import javafx.scene.control.Label;
610
import javafx.scene.layout.Region;
11+
import javafx.scene.layout.VBox;
12+
import javafx.scene.text.Text;
713

814
public class Dialogs {
915

@@ -16,7 +22,50 @@ public static Alert createAlert(AlertType type) {
1622
// We have to do some adjustments to make the alert dialog resize to
1723
// the text content on Linux. Source: http://stackoverflow.com/a/33905734
1824
alert.getDialogPane().getChildren().stream().filter(node -> node instanceof Label)
19-
.forEach(node -> ((Label) node).setMinHeight(Region.USE_PREF_SIZE));
25+
.forEach(node -> ((Label) node).setMinHeight(Region.USE_PREF_SIZE));
2026
return alert;
2127
}
28+
29+
public static Dialog<ButtonType> createSpecialApprovalConfirmation(
30+
String title,
31+
String header,
32+
String content,
33+
String confirmLabel
34+
) {
35+
return new SpecialApprovalConfirmationDialog(
36+
title,
37+
header,
38+
content,
39+
confirmLabel
40+
);
41+
}
42+
43+
/**
44+
* makes extra sure that user wants to confirm things
45+
*/
46+
static class SpecialApprovalConfirmationDialog extends Dialog<ButtonType> {
47+
final CheckBox checkBox;
48+
49+
SpecialApprovalConfirmationDialog(
50+
String title,
51+
String header,
52+
String content,
53+
String checkBoxLabel
54+
) {
55+
setResultConverter(param -> param);
56+
checkBox = new CheckBox(checkBoxLabel);
57+
58+
final DialogPane dialogPane = getDialogPane();
59+
dialogPane.getStyleClass().add("alert");
60+
dialogPane.getStyleClass().add("warning");
61+
62+
setTitle(title);
63+
dialogPane.setHeaderText(header);
64+
dialogPane.setContent(new VBox(16, new Text(content), checkBox));
65+
dialogPane.getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
66+
67+
dialogPane.lookupButton(ButtonType.OK)
68+
.disableProperty().bind(checkBox.selectedProperty().not());
69+
}
70+
}
2271
}

chunky/src/res/se/llbit/chunky/ui/Chunky.fxml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,13 @@
149149
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/>
150150
</padding>
151151
<Button fx:id="clearSelectionBtn" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Clear selection"/>
152-
<Button fx:id="deleteChunks" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Delete selected chunks"/>
153-
<Button fx:id="exportZip" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Export chunks to ZIP"/>
154-
<Button fx:id="renderPng" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Export view to PNG"/>
152+
<Separator/>
153+
<Label text="Exports"/>
154+
<Button fx:id="exportZipBtn" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Export chunks to ZIP"/>
155+
<Button fx:id="renderPngBtn" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Export view to PNG"/>
156+
<Separator/>
157+
<Label text="World modification - Use with caution!"/>
158+
<Button fx:id="deleteChunksBtn" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Delete selected chunks"/>
155159
</VBox>
156160
</Tab>
157161
<Tab fx:id="optionsTab" text="Options">

0 commit comments

Comments
 (0)