Skip to content

Commit

Permalink
[FIX] Remove auto saving feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Baptiste123D committed Feb 29, 2024
1 parent d3e10cc commit 74f3f95
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 57 deletions.
30 changes: 0 additions & 30 deletions src/main/java/application/UPMTApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,13 @@ public class UPMTApp {
private String currentProjectPath;
private UUID lastSavedCommandId;

private long autoSaveIntervalMillis;


public UPMTApp(Stage primaryStage) throws IOException {


this.primaryStage = primaryStage;
this.appCommandFactory = new ApplicationCommandFactory(this);
this.rootLayoutController = new RootLayoutController(appCommandFactory);
this.autoSaveIntervalMillis = 10000;


Configuration.loadAppConfiguration();
Expand All @@ -59,8 +56,6 @@ public UPMTApp(Stage primaryStage) throws IOException {
appCommandFactory.openProjectManagerCommand().execute();
}

startAutoSave();

FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/views/MainView/MainView.fxml"));
loader.setResources(Configuration.langBundle);
Expand Down Expand Up @@ -95,29 +90,4 @@ public void restartApp() {
setCurrentProject(getCurrentProject(), currentProjectPath);
}

public void startAutoSave() {
if (currentProject != null) {
// Créez et démarrez un nouveau thread pour la sauvegarde automatique
Thread autoSaveThread = new Thread(() -> {
while (true) {
try {
// Effectuez la sauvegarde automatique
//currentProject.saveAs("auto_save", getCurrentProjectPath());

// Utilisez Platform.runLater() pour exécuter l'opération sur le thread de l'interface utilisateur
Platform.runLater(() -> appCommandFactory.saveProject().execute());

// Pause pour l'intervalle spécifié
Thread.sleep(autoSaveIntervalMillis);
} catch (InterruptedException e) {
e.printStackTrace();
// Gérer les exceptions si nécessaire
}
}
});
autoSaveThread.setDaemon(true); // Le thread s'exécutera en arrière-plan et se terminera lorsque le programme principal se termine
autoSaveThread.start();
}
}

}
50 changes: 23 additions & 27 deletions src/main/java/application/appCommands/CloseApplicationCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,40 +54,36 @@ public Void execute() {
}
}

if (upmtApp.getCurrentProjectPath() == null) {
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setHeaderText("");
alert.setTitle(Configuration.langBundle.getString("alert_unsaved_project_title"));
alert.setContentText(Configuration.langBundle.getString("alert_unsaved_project"));
alert.getDialogPane().getStylesheets().add(getClass().getResource("/css/application.css").toExternalForm());
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setHeaderText("");
alert.setTitle(Configuration.langBundle.getString("alert_unsaved_project_title"));
alert.setContentText(Configuration.langBundle.getString("alert_unsaved_project"));
alert.getDialogPane().getStylesheets().add(getClass().getResource("/css/application.css").toExternalForm());

ButtonType buttonTypeOne = new ButtonType(Configuration.langBundle.getString("alert_unsaved_project_buttonTypeOne"));
ButtonType buttonTypeTwo = new ButtonType(Configuration.langBundle.getString("alert_unsaved_project_buttonTypeTwo"));
ButtonType buttonTypeCancel = new ButtonType("Cancel", ButtonData.CANCEL_CLOSE);
ButtonType buttonTypeOne = new ButtonType(Configuration.langBundle.getString("alert_unsaved_project_buttonTypeOne"));
ButtonType buttonTypeTwo = new ButtonType(Configuration.langBundle.getString("alert_unsaved_project_buttonTypeTwo"));
ButtonType buttonTypeCancel = new ButtonType("Cancel", ButtonData.CANCEL_CLOSE);

alert.getButtonTypes().setAll(buttonTypeOne, buttonTypeTwo, buttonTypeCancel);
alert.getButtonTypes().setAll(buttonTypeOne, buttonTypeTwo, buttonTypeCancel);

Optional<ButtonType> result = alert.showAndWait();
Optional<ButtonType> result = alert.showAndWait();

if (result.get() == buttonTypeOne){
// ... user chose "Save And Quit"
appCommandFactory.saveProject().execute();
System.exit(0);
} else if (result.get() == buttonTypeTwo) {
// ... user chose "Quit without saving"
System.exit(0);
} else if (result.get() == buttonTypeCancel) {
// ... user chose "Cancel"
if (event != null) {
event.consume();
}
return null;
}
} else {
System.exit(0);
if (result.get() == buttonTypeOne){
// ... user chose "Save And Quit"
appCommandFactory.saveProject().execute();
System.exit(0);
} else if (result.get() == buttonTypeTwo) {
// ... user chose "Quit without saving"
System.exit(0);
} else if (result.get() == buttonTypeCancel) {
// ... user chose "Cancel"
if (event != null) {
event.consume();
}
return null;
}


return null;
}
}

0 comments on commit 74f3f95

Please sign in to comment.