From 921ce3a0b036e2736853a3f4762329e399fdc4b0 Mon Sep 17 00:00:00 2001 From: Brendan Robert Date: Fri, 12 Feb 2016 23:53:03 -0600 Subject: [PATCH] Issue #12: Added option to create empty applesoft program and added warning before trying to load program from memory. --- src/main/java/jace/ide/IdeController.java | 27 +++++++++++++++++------ src/main/java/jace/ide/Program.java | 8 +++---- src/main/resources/fxml/editor.fxml | 3 ++- 3 files changed, 26 insertions(+), 12 deletions(-) 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 @@ - + +