added some more with writing and reading to file
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
package app.controllers;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
|
||||
@@ -19,7 +23,7 @@ import app.events.OpenLinkInBrowserEvent;
|
||||
import app.events.OpenProjectEvent;
|
||||
import app.events.PasteEvent;
|
||||
import app.events.RedoEvent;
|
||||
import app.events.SaveFile;
|
||||
import app.events.SaveFileEvent;
|
||||
import app.events.ThemeChangedEvent;
|
||||
import app.events.ToggleCommentEvent;
|
||||
import app.events.ToggleWrapTextEvent;
|
||||
@@ -28,10 +32,12 @@ import app.model.Model;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.CheckMenuItem;
|
||||
import javafx.scene.control.MenuBar;
|
||||
import javafx.scene.control.RadioMenuItem;
|
||||
import javafx.scene.control.ToggleGroup;
|
||||
import javafx.scene.control.Alert.AlertType;
|
||||
import javafx.stage.DirectoryChooser;
|
||||
import javafx.stage.FileChooser;
|
||||
import javafx.stage.Stage;
|
||||
@@ -69,16 +75,33 @@ public class MenubarController implements Initializable, Controller {
|
||||
this.eventBus.post(new FileSelectedEvent(null));
|
||||
}
|
||||
|
||||
@FXML // temp solution
|
||||
@FXML // temp solution, dette dreper pcen min, kan ikke brukes og logikken er heller
|
||||
// ikke helt riktig
|
||||
private void handleNewFolder() {
|
||||
|
||||
// File chosenLocation = fc.showDialog(stage);
|
||||
// if (Model.getProjectPath() == null) {
|
||||
// Alert warning = new Alert(AlertType.WARNING);
|
||||
// warning.setContentText("You must select a root before creating a
|
||||
// directory!");
|
||||
|
||||
// warning.showAndWait();
|
||||
// } else {
|
||||
// String createDirectory = JOptionPane.showInputDialog("Enter name of folder:
|
||||
// ");
|
||||
// try {
|
||||
// if (createDirectory.matches("[a-zA-Z]+")) {
|
||||
// Path path = Paths.get(Model.getProjectPath().toString() + "\\" +
|
||||
// createDirectory);
|
||||
// Files.createDirectory(path);
|
||||
// this.eventBus.post(new OpenProjectEvent(Model.getProjectPath().toString()));
|
||||
// } else {
|
||||
// throw new IOException();
|
||||
// }
|
||||
// } catch (IOException ex) {
|
||||
// JOptionPane.showMessageDialog(null, "Could not create folder. Try again!");
|
||||
// System.out.println(ex);
|
||||
// }
|
||||
|
||||
// if (chosenLocation != null) {
|
||||
// chosenLocation.mkdir();
|
||||
// Model.setActiveFilePath(null);
|
||||
// this.eventBus.post(new FileSelectedEvent(null));
|
||||
// this.eventBus.post(new OpenProjectEvent(chosenLocation.toString()));
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -136,7 +159,7 @@ public class MenubarController implements Initializable, Controller {
|
||||
@FXML
|
||||
private void handleSaveFile() {
|
||||
if (Model.getActiveFilePath() != null) {
|
||||
this.eventBus.post(new SaveFile(Model.getActiveFilePath().toString()));
|
||||
this.eventBus.post(new SaveFileEvent(Model.getActiveFilePath().toString()));
|
||||
this.eventBus.post(new FileSaveStateChangedEvent(true));
|
||||
} else {
|
||||
handleSaveAsFile();
|
||||
@@ -164,8 +187,9 @@ public class MenubarController implements Initializable, Controller {
|
||||
|
||||
if (chosenLocation != null) {
|
||||
String chosenLocationToString = chosenLocation.toString();
|
||||
this.eventBus.post(new SaveFile(chosenLocationToString));
|
||||
this.eventBus.post(new SaveFileEvent(chosenLocationToString));
|
||||
this.eventBus.post(new FileSelectedEvent(chosenLocationToString));
|
||||
|
||||
Path chosenLocationToPath = Paths.get(chosenLocationToString);
|
||||
Model.setActiveFilePath(chosenLocationToPath);
|
||||
this.eventBus.post(new FileSaveStateChangedEvent(true));
|
||||
|
||||
Reference in New Issue
Block a user