Issue #12: Added option to create empty applesoft program and added warning before trying to load program from memory.

This commit is contained in:
Brendan Robert 2016-02-12 23:53:03 -06:00
parent 58199776a5
commit 921ce3a0b0
3 changed files with 26 additions and 12 deletions

View File

@ -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<ButtonType> 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<Tab, Program> openDocuments = new HashMap<>();
Map<Option, Object> 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);
}
}

View File

@ -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");

View File

@ -26,7 +26,8 @@
</accelerator>
<items>
<MenuItem mnemonicParsing="false" onAction="#newAssemblyListingClicked" text="Assembly Listing" />
<MenuItem mnemonicParsing="false" onAction="#newApplesoftBasicClicked" text="Applesoft Basic Listing" />
<MenuItem mnemonicParsing="false" onAction="#newApplesoftBasicClicked" text="Applesoft Basic Listing (blank)" />
<MenuItem mnemonicParsing="false" onAction="#newApplesoftBasicFromMemoryClicked" text="Applesoft Basic Listing (from memory)" />
<MenuItem mnemonicParsing="false" onAction="#newPlainTextClicked" text="Plain Text" />
<MenuItem mnemonicParsing="false" onAction="#newHexdataClicked" text="Data (Hex)" />
</items>