Added some to saving, add more to exceptions tomorrow

This commit is contained in:
Oystein
2021-04-06 20:45:15 +02:00
parent 3f8482bb78
commit df41e3df58
5 changed files with 113 additions and 7 deletions

View File

@@ -2,6 +2,7 @@ package app.controllers;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.net.URL;
import java.util.Collection;
import java.util.ResourceBundle;
@@ -22,6 +23,7 @@ import app.events.EditorChangedEvent;
import app.events.LanguageChangedEvent;
import app.events.PasteEvent;
import app.events.RedoEvent;
import app.events.SaveFile;
import app.events.ToggleCommentEvent;
import app.events.ToggleWrapTextEvent;
import app.events.UndoEvent;
@@ -76,11 +78,12 @@ public class EditorController implements Initializable, Controller {
}
/**
* Uses the {@link app.model.ProgrammingLanguage ProgrammingLanguage} in
* Uses the {@link app.model.ProgrammingLanguage ProgrammingLanguage} in
* {@link app.model.Model Model} to determine whether the current line/selection
* is commented or not, and toggles the comment.
*
* @see app.model.ProgrammingLanguage#commentLine(String) ProgrammingLanguage.commentLine(line)
* @see app.model.ProgrammingLanguage#commentLine(String)
* ProgrammingLanguage.commentLine(line)
*/
private void toggleComment() {
if (editor.getSelectedText().equals("")) {
@@ -109,6 +112,7 @@ public class EditorController implements Initializable, Controller {
/**
* Updates the wraptext setting of the code area
*
* @param isWrapText The new value for the setting
*/
private void setWrapText(boolean isWrapText) {
@@ -131,6 +135,7 @@ public class EditorController implements Initializable, Controller {
/**
* Updates the content of the editor to a specific filepath
*
* @param filePath The path of the file
* @throws FileNotFoundException
*/
@@ -147,11 +152,24 @@ public class EditorController implements Initializable, Controller {
}
}
private void saveCodeArea(String filePath) {
try (PrintWriter writer = new PrintWriter(new File(filePath))) {
writer.println(editor.getText());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
@Subscribe
private void handle(FileSelectedEvent event) {
this.setEditorContent(event.getPath());
}
@Subscribe
private void handle(SaveFile event) {
this.saveCodeArea(event.getPath());
}
@Subscribe
private void handle(LanguageChangedEvent event) {
this.refreshHighlighting();