From 39236c192c22ce701270a43159e8d52c1b39e077 Mon Sep 17 00:00:00 2001 From: Kaj Koivunen <kalakoiv@jyu.fi> Date: Thu, 27 Apr 2023 17:21:08 +0300 Subject: [PATCH] recent projektit --- src/main/kotlin/Project.kt | 46 ++++++++++++++++++++++-- src/main/kotlin/SplashScreen.kt | 62 +++++---------------------------- 2 files changed, 53 insertions(+), 55 deletions(-) diff --git a/src/main/kotlin/Project.kt b/src/main/kotlin/Project.kt index 5169c65..eee97cc 100644 --- a/src/main/kotlin/Project.kt +++ b/src/main/kotlin/Project.kt @@ -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}") + } + } + } + } } /** diff --git a/src/main/kotlin/SplashScreen.kt b/src/main/kotlin/SplashScreen.kt index 6e37e13..32553d2 100644 --- a/src/main/kotlin/SplashScreen.kt +++ b/src/main/kotlin/SplashScreen.kt @@ -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() -- GitLab