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

recent projektit

parent c6847bad
No related branches found
No related tags found
No related merge requests found
......@@ -65,7 +65,7 @@ class Project {
* Loads project from specified file
* @param file file to load
*/
private fun loadFile(file: File) {
fun loadFile(file: File) {
if (!file.exists()) return
new()
file.bufferedReader().use { reader ->
......@@ -84,7 +84,7 @@ class Project {
* Saves project to a specified file
* @param file file to save to
*/
private fun saveFile(file: File) {
fun saveFile(file: File) {
file.printWriter().use { writer ->
var pageNumber = 1
for (page in pages) {
......@@ -92,6 +92,7 @@ class Project {
page.save(writer)
}
}
addRecent("name", file)
}
/**
......@@ -107,6 +108,47 @@ class Project {
for (page in pages) page.translatePage()
}
companion object {
/** List of recently opened projects */
val recent : MutableList<Pair<String, File>> = mutableListOf()
/** File to store recent projects in */
private val recentFile = File("recent.rvs")
init {
if (recentFile.exists()) {
recentFile.bufferedReader().use { reader ->
var line: String?
while (reader.readLine().also { line = it } != null) {
val s = line!!.split(2.toChar())
recent.add(s.getOrElse(0) { "" } to File(s.getOrElse(1) { "" }))
}
}
} else {
print("Creating recent file: $recentFile")
recentFile.printWriter().use { writer ->
writer.println()
}
}
}
/**
* Adds a file to recent list, if it isn't there yet
* @param name Name of display to user
* @param file Path to file
*/
fun addRecent(name: String, file: File) {
for (recent in recent) {
if (recent.second == file) return
}
recent.add(name to file)
recentFile.printWriter().use { writer ->
for (recent in recent) {
writer.println("${recent.first}${2.toChar()}${recent.second}")
}
}
}
}
}
/**
......
......@@ -14,61 +14,17 @@ class SplashScreen(project: Project) : View("Ronove") {
override val root = borderpane {
center = form {
fieldset {
field {
hyperlink("Dummy 1") {
action {
project.pages = mutableListOf(
Page(listOf(
Line("なんでタバコすってんだ?","Why are you smoking?","Why do you smoke?"),
Line("んー","Hmm.","Hmm..."),
Line("フー","whoosh","Haa...", "SFX: Exhaling"),
Line("カツコつけてんの","I'm trying to be cool.",
"I'm just trying to look cool"),
Line("かっこいー","That's so cool.", "Coooool!")
)),
Page(listOf(
Line("Sivu 2","Page 2","Page 2"),
Line("a","b","c"),Line("a","b","c"),
Line("a","b","c")
)),
Page(listOf(
Line("Sivu 3","Page 3","Page 3"),
Line("a","b","c"),Line("a","b","c"),Line("a","b","c"),Line("a","b","c"),
Line("a","b","c")
)),
Page(listOf(
Line("Sivu 4","Page 4","Page 4"),
Line("a","b","c"),Line("a","b","c"),
Line("a","b","c")
)),
Page(listOf(
Line("Sivu 5","Page 5","Page 5"),
Line("a","b","c"),
Line("a","b","c")
))
)
close()
(app as Ronove).table.refresh()
for (recent in Project.recent) {
field {
hyperlink(recent.first) {
action {
project.loadFile(recent.second)
(app as Ronove).table.refresh()
close()
}
}
}
}
progressbar(0.2)
}
field {
hyperlink("Dummy 2")
progressbar(0.3)
}
field {
hyperlink("Dummy 3")
progressbar(0.5)
}
field {
hyperlink("Dummy 4")
progressbar(0.9)
}
field {
hyperlink("Dummy 5")
progressbar(0.9)
}
field {
button("New project") { action {
project.new()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment