Skip to content
Snippets Groups Projects
Commit d8754f4a authored by Kaj Koivunen's avatar Kaj Koivunen :coffee:
Browse files

tiedostojen lataus ja tallennus

parent a118bf87
No related branches found
No related tags found
No related merge requests found
...@@ -18,11 +18,9 @@ class MainView : View("Ronove") { ...@@ -18,11 +18,9 @@ class MainView : View("Ronove") {
top = menubar { top = menubar {
menu("File") { menu("File") {
item("New project...") { action { TODO() } } item("New project...") { action { TODO() } }
item("New empty project") { action { TODO() } } item("New empty project") { action { (app as Ronove).project.new() } }
separator() separator()
item("Open...").action { item("Open...") { action { (app as Ronove).project.open() }}
chooseDirectory("Choose folder")
}
menu("Open recent") { menu("Open recent") {
item("Recent 1") item("Recent 1")
item("Recent 2") item("Recent 2")
...@@ -31,15 +29,20 @@ class MainView : View("Ronove") { ...@@ -31,15 +29,20 @@ class MainView : View("Ronove") {
item("Recent 5") item("Recent 5")
} }
separator() separator()
item("Save") { action { TODO("Save") } } item("Save") {
item("Save as...") { action { TODO() } } action { (app as Ronove).project.save() }
enableWhen {(app as Ronove).project.projectFileSet}
}
item("Save as...") { action { (app as Ronove).project.saveAs() }}
item("Export...") { action { TODO() } } item("Export...") { action { TODO() } }
separator() separator()
item("Exit").action { item("Exit") {
action {
//TODO: Confirm unsaved changes //TODO: Confirm unsaved changes
exitProcess(0) exitProcess(0)
} }
} }
}
menu("Edit") { menu("Edit") {
item("Add page") { action { (app as Ronove).addPage() } } item("Add page") { action { (app as Ronove).addPage() } }
item("Remove page") { action { TODO() } } item("Remove page") { action { TODO() } }
...@@ -104,4 +107,3 @@ class MainView : View("Ronove") { ...@@ -104,4 +107,3 @@ class MainView : View("Ronove") {
modality = Modality.APPLICATION_MODAL, owner = primaryStage) modality = Modality.APPLICATION_MODAL, owner = primaryStage)
} }
} }
\ No newline at end of file
package guru.kake.ronove package guru.kake.ronove
import javafx.beans.property.SimpleBooleanProperty
import javafx.stage.FileChooser
import tornadofx.FileChooserMode
import tornadofx.chooseFile
import java.io.File
import java.io.PrintWriter
import kotlin.reflect.KProperty1 import kotlin.reflect.KProperty1
/** /**
* Class for holding the data of the entire translation project, which consists of pages consisting of lines. * Class for holding the data of the entire translation project, which consists of pages consisting of lines.
*/ */
class Project { class Project {
/** Last used file for saving, updated on Load/Save as */
private var projectFile: File? = null
/** Observable denoting if projectfile is set */
var projectFileSet = SimpleBooleanProperty(false)
/** Pages of the project */ /** Pages of the project */
var pages: MutableList<Page> = mutableListOf() var pages: MutableList<Page> = mutableListOf(Page())
/** Prompts user for project file to open and loads it */
fun open() {
val file = chooseFile("Open...",
arrayOf(
FileChooser.ExtensionFilter("Ronove project files", "*.rvp", "*.RVP"),
FileChooser.ExtensionFilter("All files", "*")
),
mode=FileChooserMode.Single
)
if (file.isNotEmpty()) loadFile(file[0])
projectFile = file[0]
projectFileSet.value = true
}
/** Prompts user for project file to open and saves to it */
fun saveAs() {
val file = chooseFile("Save as..",
arrayOf(
FileChooser.ExtensionFilter("Ronove project files", "*.rvp", "*.RVP"),
FileChooser.ExtensionFilter("All files", "*")
),
mode=FileChooserMode.Save
)
saveFile(file[0])
projectFile = file[0]
projectFileSet.value = true
}
fun save() = projectFile?.let { saveFile(it) }
fun new() {
pages = mutableListOf(Page())
projectFile = null
projectFileSet.value = false
}
private fun loadFile(file: File) {
if (!file.exists()) return
new()
file.bufferedReader().use { reader ->
var line: String?
while (reader.readLine().also { line = it } != null) {
println(line)
if (line!!.startsWith('#')) {
pages.add(Page())
} else {
pages.last().lines.add(Line(line!!))
}
}
}
}
private fun saveFile(file: File) {
file.printWriter().use { writer ->
var pageNumber = 1
for (page in pages) {
writer.println("#${pageNumber++}")
page.save(writer)
}
}
}
} }
/** /**
...@@ -44,6 +118,14 @@ class Page(lines: Collection<Line> = listOf()) { ...@@ -44,6 +118,14 @@ class Page(lines: Collection<Line> = listOf()) {
println("${line.original}: ${line.machineTranslation}") println("${line.original}: ${line.machineTranslation}")
} }
} }
fun save(writer: PrintWriter) {
for (line in lines) {
with(line) {
writer.println("$original|$machineTranslation|$finalTranslation|$notes")
}
}
}
} }
/** /**
...@@ -58,4 +140,12 @@ data class Line( ...@@ -58,4 +140,12 @@ data class Line(
var finalTranslation: String = "", var finalTranslation: String = "",
/** Translator notes for the line */ /** Translator notes for the line */
var notes: String = "" var notes: String = ""
) ) {
\ No newline at end of file constructor(s: String) : this() {
val args = s.split('|')
original = args.getOrElse(0) { "" }
machineTranslation = args.getOrElse(1) { "" }
finalTranslation = args.getOrElse(2) { "" }
notes = args.getOrElse(3) { "" }
}
}
\ No newline at end of file
package guru.kake.ronove package guru.kake.ronove
import javafx.stage.Modality
import javafx.stage.StageStyle
import tornadofx.* import tornadofx.*
import kotlin.system.exitProcess import kotlin.system.exitProcess
...@@ -71,14 +69,8 @@ class SplashScreen(project: Project) : View("Ronove") { ...@@ -71,14 +69,8 @@ class SplashScreen(project: Project) : View("Ronove") {
progressbar(0.9) progressbar(0.9)
} }
field { field {
button("New project") { button("New project") { action { project.new(); close() }}
action { button("Open...") { action { project.open(); close() }}
ProjectSettings().openModal(
stageStyle = StageStyle.UTILITY, block = true,
modality = Modality.APPLICATION_MODAL, owner = primaryStage)
}
}
button("Open...")
button("Exit") { action { exitProcess(0) }} button("Exit") { action { exitProcess(0) }}
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment