Added some to saving, add more to exceptions tomorrow
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
package app.controllers;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
@@ -16,6 +20,7 @@ import app.events.OpenLinkInBrowserEvent;
|
||||
import app.events.OpenProjectEvent;
|
||||
import app.events.PasteEvent;
|
||||
import app.events.RedoEvent;
|
||||
import app.events.SaveFile;
|
||||
import app.events.ThemeChangedEvent;
|
||||
import app.events.ToggleCommentEvent;
|
||||
import app.events.ToggleWrapTextEvent;
|
||||
@@ -57,7 +62,20 @@ public class MenubarController implements Initializable, Controller {
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* FILE */
|
||||
/* CREATE FILE/DIRECTORY */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
@FXML
|
||||
private void handleNewFile() {
|
||||
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void handleNewFolder() {
|
||||
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* OPEN FILE */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
/**
|
||||
@@ -93,6 +111,47 @@ public class MenubarController implements Initializable, Controller {
|
||||
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* SAVE FILE */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
/**
|
||||
* Handles whenever the Save button is pressed in the menubar
|
||||
*/
|
||||
@FXML
|
||||
private void handleSaveFile() {
|
||||
if (Model.getActiveFilePath() != null) {
|
||||
this.eventBus.post(new SaveFile(Model.getActiveFilePath().toString()));
|
||||
} else {
|
||||
handleSaveAsFile();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles whenever the Save as button is pressed in the menubar
|
||||
*/
|
||||
@FXML
|
||||
private void handleSaveAsFile() {
|
||||
FileChooser fc = new FileChooser();
|
||||
fc.setTitle("Save as");
|
||||
Stage stage = (Stage) menubar.getScene().getWindow();
|
||||
|
||||
FileChooser.ExtensionFilter extJava = new FileChooser.ExtensionFilter("Java", "*.java");
|
||||
FileChooser.ExtensionFilter extMd = new FileChooser.ExtensionFilter("Markdown", "*.md");
|
||||
|
||||
fc.getExtensionFilters().addAll(extJava, extMd);
|
||||
|
||||
File chosenLocation = fc.showSaveDialog(stage);
|
||||
|
||||
if (chosenLocation != null) {
|
||||
String chosenLocationToString = chosenLocation.toString();
|
||||
this.eventBus.post(new SaveFile(chosenLocationToString));
|
||||
this.eventBus.post(new FileSelectedEvent(chosenLocationToString));
|
||||
Path chosenLocationToPath = Paths.get(chosenLocationToString);
|
||||
Model.setActiveFilePath(chosenLocationToPath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles whenever the programming language is changed from the menubar.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user