1
0
mirror of https://github.com/aNNiMON/HotaruFX.git synced 2024-09-19 14:14:21 +03:00

Ability to create new document, fix opening files

This commit is contained in:
Victor 2017-09-06 11:30:21 +03:00
parent 00df10350a
commit 141dae5379
2 changed files with 29 additions and 3 deletions

View File

@ -44,10 +44,16 @@ public class EditorController implements Initializable, DocumentListener {
private SyntaxHighlighter syntaxHighlighter;
private DocumentManager documentManager;
@FXML
private void handleMenuNew(ActionEvent event) {
documentManager.newDocument();
openSample();
updateTitle();
}
@FXML
private void handleMenuOpen(ActionEvent event) {
val isOpened = documentManager.open(primaryStage,
s -> editor.replaceText(0, 0, s));
val isOpened = documentManager.open(primaryStage, editor::replaceText);
if (isOpened) {
updateTitle();
}
@ -72,6 +78,7 @@ public class EditorController implements Initializable, DocumentListener {
private void handleMenuPlay(ActionEvent event) {
log.setText("");
val input = editor.getText();
logError(input);
val context = new Context();
BundleLoader.load(context, Arrays.asList(
@ -101,7 +108,7 @@ public class EditorController implements Initializable, DocumentListener {
syntaxHighlighter = new SyntaxHighlighter(editor, Executors.newSingleThreadExecutor());
syntaxHighlighter.init();
documentManager = new FileManager();
editor.replaceText(0, 0, readProgram("/main.hfx"));
openSample();
}
public void setPrimaryStage(Stage primaryStage) {
@ -117,6 +124,24 @@ public class EditorController implements Initializable, DocumentListener {
log.insertText(0, message + System.lineSeparator());
}
private void openSample() {
editor.replaceText(
"composition(1280, 720, 30)\n" +
"\n" +
"A = circle({\n" +
" cx: 0,\n" +
" cy: 0,\n" +
" radius: 100,\n" +
" fill: '#9bc747'\n" +
"})\n" +
"\n" +
"A@radius\n" +
" .add(300 ms, 200)\n" +
" .add(1 sec, 50)\n" +
"\n" +
"render(A)");
}
private String readProgram(String path) {
val fallbackProgram = "composition(640, 480, 25)";
try (InputStream is = Main.class.getResourceAsStream(path)) {

View File

@ -21,6 +21,7 @@
<VBox BorderPane.alignment="CENTER">
<MenuBar>
<Menu mnemonicParsing="false" text="File">
<MenuItem onAction="#handleMenuNew" text="New"/>
<MenuItem onAction="#handleMenuOpen" text="Open"/>
<MenuItem onAction="#handleMenuExit" text="Exit"/>
</Menu>