open, save files
This commit is contained in:
@@ -4,6 +4,7 @@ import befide.befunge.core.Interpreter
|
|||||||
import javafx.animation.Animation
|
import javafx.animation.Animation
|
||||||
import javafx.animation.Timeline
|
import javafx.animation.Timeline
|
||||||
import javafx.beans.property.SimpleBooleanProperty
|
import javafx.beans.property.SimpleBooleanProperty
|
||||||
|
import javafx.beans.property.SimpleObjectProperty
|
||||||
import javafx.stage.FileChooser
|
import javafx.stage.FileChooser
|
||||||
import javafx.util.Duration
|
import javafx.util.Duration
|
||||||
import tornadofx.*
|
import tornadofx.*
|
||||||
@@ -30,6 +31,9 @@ class ActionView(val interp: Interpreter, val codeView: CodeView, val ioView: IO
|
|||||||
val canResetProperty = SimpleBooleanProperty(false)
|
val canResetProperty = SimpleBooleanProperty(false)
|
||||||
var canReset by canResetProperty
|
var canReset by canResetProperty
|
||||||
|
|
||||||
|
val saveFileProperty = SimpleObjectProperty<File>()
|
||||||
|
var saveFile by saveFileProperty
|
||||||
|
|
||||||
fun start(rate: Double) {
|
fun start(rate: Double) {
|
||||||
stop()
|
stop()
|
||||||
|
|
||||||
@@ -68,13 +72,46 @@ class ActionView(val interp: Interpreter, val codeView: CodeView, val ioView: IO
|
|||||||
codeView.clear()
|
codeView.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun save() {
|
||||||
|
if (saveFile == null) {
|
||||||
|
saveAs()
|
||||||
|
} else {
|
||||||
|
saveFile.writeText(codeView.src)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun saveAs() {
|
||||||
|
val fc = FileChooser()
|
||||||
|
fc.title = "Save Befunge File"
|
||||||
|
|
||||||
|
val file: File? = fc.showSaveDialog(primaryStage)
|
||||||
|
if (file != null) {
|
||||||
|
saveFile = file
|
||||||
|
|
||||||
|
save()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun open() {
|
||||||
|
val fc = FileChooser()
|
||||||
|
fc.title = "Open Befunge File"
|
||||||
|
|
||||||
|
val file: File? = fc.showOpenDialog(primaryStage)
|
||||||
|
if (file != null) {
|
||||||
|
saveFile = file
|
||||||
|
|
||||||
|
reset()
|
||||||
|
codeView.src = saveFile.readText()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override val root = hbox {
|
override val root = hbox {
|
||||||
button("step") {
|
button("step") {
|
||||||
setOnAction { step() }
|
setOnAction { step() }
|
||||||
disableWhen(isRunningProperty)
|
disableWhen(isRunningProperty)
|
||||||
}
|
}
|
||||||
|
|
||||||
separator { }
|
separator {}
|
||||||
|
|
||||||
button("run") {
|
button("run") {
|
||||||
setOnAction { start(10000.0) }
|
setOnAction { start(10000.0) }
|
||||||
@@ -95,29 +132,35 @@ class ActionView(val interp: Interpreter, val codeView: CodeView, val ioView: IO
|
|||||||
enableWhen(isRunningProperty)
|
enableWhen(isRunningProperty)
|
||||||
}
|
}
|
||||||
|
|
||||||
spacer()
|
spacer {}
|
||||||
|
|
||||||
button("open") {
|
|
||||||
setOnAction {
|
|
||||||
val fc = FileChooser()
|
|
||||||
fc.title = "Open Befunge File"
|
|
||||||
|
|
||||||
val file: File? = fc.showOpenDialog(primaryStage)
|
|
||||||
if (file != null){
|
|
||||||
reset()
|
|
||||||
codeView.src = file.readText()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
disableWhen(isRunningProperty)
|
|
||||||
}
|
|
||||||
|
|
||||||
button("reset") {
|
button("reset") {
|
||||||
setOnAction { reset() }
|
setOnAction { reset() }
|
||||||
enableWhen(canResetProperty.and(isRunningProperty.not()))
|
enableWhen(canResetProperty.and(isRunningProperty.not()))
|
||||||
}
|
}
|
||||||
|
|
||||||
button("clear") {
|
separator {}
|
||||||
setOnAction { clearCode() }
|
|
||||||
|
button("open") {
|
||||||
|
setOnAction { open() }
|
||||||
|
disableWhen(isRunningProperty)
|
||||||
|
}
|
||||||
|
|
||||||
|
button("save as") {
|
||||||
|
setOnAction { saveAs() }
|
||||||
|
}
|
||||||
|
|
||||||
|
button("save") {
|
||||||
|
setOnAction { save() }
|
||||||
|
|
||||||
|
enableWhen(saveFileProperty.isNotNull.and(isRunningProperty.not()))
|
||||||
|
}
|
||||||
|
|
||||||
|
button("new") {
|
||||||
|
setOnAction {
|
||||||
|
clearCode()
|
||||||
|
saveFile = null
|
||||||
|
}
|
||||||
disableWhen(isRunningProperty)
|
disableWhen(isRunningProperty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user