Fix save on Exit Event

master
Oystein Kristoffer Tveit 2021-04-26 13:09:23 +02:00
parent 22406222f3
commit 0c16ae3f15
2 changed files with 12 additions and 10 deletions

View File

@ -13,7 +13,6 @@ import app.controllers.*;
import app.events.ExitApplicationEvent;
import app.events.LanguageChangedEvent;
import app.events.OpenLinkInBrowserEvent;
import app.events.SaveFileEvent;
import app.events.ThemeChangedEvent;
import app.model.Model;
import javafx.application.HostServices;
@ -138,13 +137,9 @@ public class MainController implements Initializable {
int g = JOptionPane.showConfirmDialog(null, "Your files are not saved.\nSave before exit?", "Exit",
JOptionPane.YES_NO_OPTION);
if (g == JOptionPane.YES_OPTION) {
this.eventBus.post(new SaveFileEvent());
Platform.exit();
}
} else {
Platform.exit();
if (g == JOptionPane.YES_OPTION)
this.editorController.saveCodeArea(Model.getActiveFilePath().isEmpty());
}
Platform.exit();
}
}

View File

@ -4,6 +4,7 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.nio.file.Path;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.Scanner;
@ -48,9 +49,15 @@ public class FileOperations {
}
public static boolean saveFileWithDialog(Stage stage, String content) {
File chosenLocation = DialogBoxes.showSaveFileWithDialog(stage);
if (chosenLocation == null)
File chosenLocation;
try {
chosenLocation = DialogBoxes.showSaveFileWithDialog(stage);
} catch (NoSuchElementException e) {
return false;
}
if (chosenLocation == null) return false;
if (saveFile(chosenLocation.toPath(), content)) {
Model.setActiveFilePath(Optional.of(chosenLocation.toPath()));