diff --git a/src/main/java/jace/ide/IdeController.java b/src/main/java/jace/ide/IdeController.java index f7e5131..189bd2a 100644 --- a/src/main/java/jace/ide/IdeController.java +++ b/src/main/java/jace/ide/IdeController.java @@ -19,6 +19,8 @@ import javafx.collections.ListChangeListener; import javafx.event.ActionEvent; import javafx.event.Event; import javafx.fxml.FXML; +import javafx.scene.control.Alert; +import javafx.scene.control.ButtonType; import javafx.scene.control.Label; import javafx.scene.control.Menu; import javafx.scene.control.MenuItem; @@ -96,31 +98,42 @@ public class IdeController { @FXML void newApplesoftBasicClicked(ActionEvent event) { - Program tab = createTab(DocumentType.applesoft, null); + Program tab = createTab(DocumentType.applesoft, null, true); + } + + @FXML + void newApplesoftBasicFromMemoryClicked(ActionEvent event) { + Alert warningAlert = new Alert(Alert.AlertType.CONFIRMATION); + warningAlert.setTitle("Is Applesoft running?"); + warningAlert.setContentText("If you proceed and applesoft is not running or there is no active program then the emulator might freeze. Press Cancel if you are unsure."); + Optional result = warningAlert.showAndWait(); + if (result.get() == ButtonType.OK) { + Program tab = createTab(DocumentType.applesoft, null, false); + } } @FXML void newAssemblyListingClicked(ActionEvent event) { - createTab(DocumentType.assembly, null); + createTab(DocumentType.assembly, null, false); } @FXML void newHexdataClicked(ActionEvent event) { - createTab(DocumentType.hex, null); + createTab(DocumentType.hex, null, false); } @FXML void newPlainTextClicked(ActionEvent event) { - createTab(DocumentType.plain, null); + createTab(DocumentType.plain, null, false); } Map openDocuments = new HashMap<>(); Map globalOptions = new EnumMap<>(Option.class); - private Program createTab(DocumentType type, File document) { + private Program createTab(DocumentType type, File document, boolean isBlank) { WebView editor = new WebView(); Program proxy = new Program(type, globalOptions); - proxy.initEditor(editor, document); + proxy.initEditor(editor, document, isBlank); Tab t = new Tab(proxy.getName(), editor); tabPane.getTabs().add(t); openDocuments.put(t, proxy); @@ -153,7 +166,7 @@ public class IdeController { File file = chooser.showOpenDialog(JaceApplication.getApplication().primaryStage); if (file != null && file.isFile() && file.exists()) { DocumentType type = DocumentType.fromFile(file); - createTab(type, file); + createTab(type, file, true); } } diff --git a/src/main/java/jace/ide/Program.java b/src/main/java/jace/ide/Program.java index 0b1e6af..6695929 100644 --- a/src/main/java/jace/ide/Program.java +++ b/src/main/java/jace/ide/Program.java @@ -105,7 +105,7 @@ public class Program { return Optional.ofNullable(targetFile); } - public void initEditor(WebView editor, File sourceFile) { + public void initEditor(WebView editor, File sourceFile, boolean isBlank) { this.editor = editor; targetFile = sourceFile; if (targetFile != null) { @@ -117,7 +117,7 @@ public class Program { if (newState == Worker.State.SUCCEEDED) { JSObject document = (JSObject) editor.getEngine().executeScript("window"); document.setMember("java", this); - Platform.runLater(this::createEditor); + Platform.runLater(()->createEditor(isBlank)); } }); @@ -132,8 +132,8 @@ public class Program { editor.getEngine().load(getClass().getResource(CODEMIRROR_EDITOR).toExternalForm()); } - public void createEditor() { - String document = targetFile == null ? getHandler().getNewDocumentContent() : getFileContents(targetFile); + public void createEditor(boolean isBlank) { + String document = targetFile == null ? isBlank ? "" : getHandler().getNewDocumentContent() : getFileContents(targetFile); String optionString = buildOptions(); editor.getEngine().executeScript("var codeMirror = CodeMirror(document.body, " + optionString + ");"); codeMirror = (JSObject) editor.getEngine().executeScript("codeMirror"); diff --git a/src/main/resources/fxml/editor.fxml b/src/main/resources/fxml/editor.fxml index c24b62b..5712a44 100644 --- a/src/main/resources/fxml/editor.fxml +++ b/src/main/resources/fxml/editor.fxml @@ -26,7 +26,8 @@ - + +