When a new file is opened check first if there are unsafed changes and show a warning dialog.

This commit is contained in:
2022-10-19 13:48:09 +02:00
parent 7dac3ce011
commit bec55b6119
6 changed files with 28 additions and 4 deletions

View File

@@ -276,7 +276,7 @@ public class SmartCSVController extends FXMLController {
tableWrapper.setOnDragDropped(event -> {
Dragboard db = event.getDragboard();
boolean success = false;
if (db.hasFiles() && db.getFiles().size() == 1) {
if (db.hasFiles() && db.getFiles().size() == 1 && canOpen()) {
File file = db.getFiles().get(0);
openFile(currentCsvFile, file);
success = true;
@@ -503,6 +503,22 @@ public class SmartCSVController extends FXMLController {
return canExit;
}
private boolean canOpen() {
boolean canOpen = true;
if (currentCsvFile.getContent() != null && currentCsvFile.isFileChanged()) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle(resourceBundle.getString("dialog.changes.title"));
alert.setHeaderText(resourceBundle.getString("dialog.changes.header.text"));
alert.setContentText(resourceBundle.getString("dialog.changes.text"));
Optional<ButtonType> result = alert.showAndWait();
if (result.get() != ButtonType.OK){
canOpen = false;
}
}
return canOpen;
}
public void showValidationEditor(String column) {
validationEditorController.setSelectedColumn(column);
validationEditorController.updateForm();