open, save files
This commit is contained in:
@@ -4,6 +4,7 @@ import befide.befunge.core.Interpreter
|
||||
import javafx.animation.Animation
|
||||
import javafx.animation.Timeline
|
||||
import javafx.beans.property.SimpleBooleanProperty
|
||||
import javafx.beans.property.SimpleObjectProperty
|
||||
import javafx.stage.FileChooser
|
||||
import javafx.util.Duration
|
||||
import tornadofx.*
|
||||
@@ -30,6 +31,9 @@ class ActionView(val interp: Interpreter, val codeView: CodeView, val ioView: IO
|
||||
val canResetProperty = SimpleBooleanProperty(false)
|
||||
var canReset by canResetProperty
|
||||
|
||||
val saveFileProperty = SimpleObjectProperty<File>()
|
||||
var saveFile by saveFileProperty
|
||||
|
||||
fun start(rate: Double) {
|
||||
stop()
|
||||
|
||||
@@ -68,13 +72,46 @@ class ActionView(val interp: Interpreter, val codeView: CodeView, val ioView: IO
|
||||
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 {
|
||||
button("step") {
|
||||
setOnAction { step() }
|
||||
disableWhen(isRunningProperty)
|
||||
}
|
||||
|
||||
separator { }
|
||||
separator {}
|
||||
|
||||
button("run") {
|
||||
setOnAction { start(10000.0) }
|
||||
@@ -95,29 +132,35 @@ class ActionView(val interp: Interpreter, val codeView: CodeView, val ioView: IO
|
||||
enableWhen(isRunningProperty)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
spacer {}
|
||||
|
||||
button("reset") {
|
||||
setOnAction { reset() }
|
||||
enableWhen(canResetProperty.and(isRunningProperty.not()))
|
||||
}
|
||||
|
||||
button("clear") {
|
||||
setOnAction { clearCode() }
|
||||
separator {}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user