diff --git a/src/main/java/app/MainController.java b/src/main/java/app/MainController.java index d61b1ab..428f83e 100644 --- a/src/main/java/app/MainController.java +++ b/src/main/java/app/MainController.java @@ -120,7 +120,7 @@ public class MainController implements Initializable { } /** - * Handle an exit request for the whole program Checking if all is saved before + * Handle an exit request for the whole program. Checking if all is saved before * closing the app. The user can either choose to exit or go back to the * application and save. * @@ -129,7 +129,7 @@ public class MainController implements Initializable { @Subscribe private void handle(ExitApplicationEvent event) { if (!Model.getFileIsSaved()) { - int g = JOptionPane.showConfirmDialog(null, "Your files are not saved.\nSave before you exit?", "Exit", + int g = JOptionPane.showConfirmDialog(null, "Your files are not saved.\nGo back to save?", "Exit", JOptionPane.YES_NO_OPTION); if (!(g == JOptionPane.YES_OPTION)) { diff --git a/src/main/java/app/controllers/EditorController.java b/src/main/java/app/controllers/EditorController.java index 4962bba..61981b4 100644 --- a/src/main/java/app/controllers/EditorController.java +++ b/src/main/java/app/controllers/EditorController.java @@ -29,6 +29,7 @@ import app.events.SaveFileEvent; import app.events.ToggleCommentEvent; import app.events.ToggleWrapTextEvent; import app.events.UndoEvent; +import app.interfaces.FileManagement; import app.events.FileSaveStateChangedEvent; import app.events.FileSelectedEvent; import app.model.Model; @@ -41,7 +42,7 @@ import javafx.scene.control.Alert.AlertType; /** * A FXML controller that controls the editor component of the UI */ -public class EditorController implements Initializable, Controller { +public class EditorController implements Initializable, Controller, FileManagement { @FXML private CodeArea editor; @@ -144,7 +145,7 @@ public class EditorController implements Initializable, Controller { * @param filePath The path of the file * @throws FileNotFoundException */ - private void setEditorContent(String filePath) { + public void setEditorContent(String filePath) { if (filePath == null) { editor.clear(); editor.appendText("// New File"); @@ -173,8 +174,11 @@ public class EditorController implements Initializable, Controller { /** * Saving/Writing to the file based on the spesific filepath. Otherwise it will * open an error dialog to give the user feedback about what has happened. + * + * @param filePath The path of the file + * @throws FileNotFoundException */ - private void saveCodeArea(String filePath) { + public void saveCodeArea(String filePath) { try (PrintWriter writer = new PrintWriter(new File(filePath))) { if (filePath.endsWith(".java") || filePath.endsWith(".md")) { writer.println(editor.getText()); diff --git a/src/main/java/app/interfaces/FileManagement.java b/src/main/java/app/interfaces/FileManagement.java new file mode 100644 index 0000000..2b4ec9d --- /dev/null +++ b/src/main/java/app/interfaces/FileManagement.java @@ -0,0 +1,13 @@ +package app.interfaces; + +/* +* An interface that contains two methods for reading and writing to files. +*/ + +public interface FileManagement { + + void setEditorContent(String filePath); + + void saveCodeArea(String filePath); + +}