diff --git a/console/src/main/kotlin/notes/multi/console/Console.kt b/console/src/main/kotlin/notes/multi/console/Console.kt index dbddf4575ccbea53ef25f953675f30cdd8024dde..3dcc0cf61cce3acacb8f2df8d7d66f9cd2337de0 100644 --- a/console/src/main/kotlin/notes/multi/console/Console.kt +++ b/console/src/main/kotlin/notes/multi/console/Console.kt @@ -10,6 +10,7 @@ import java.lang.IllegalArgumentException import notes.multi.utilities.Note import notes.multi.utilities.TextWindow import javafx.application.Application +import javafx.stage.Stage fun main(args: Array<String>) { if (args.isEmpty()) { @@ -71,13 +72,13 @@ fun main(args: Array<String>) { // fun main() { // // thesea re test functions feel free to use // val n = Note() -// val noteTitle = n.title -// val noteContent = n.text.toString() -// println(noteContent) -// Application.launch(TextWindow()::class.java, "--title=${noteTitle}", "--text=${noteContent}") +// val noteTitle = "testver2.txt" +// val path = "${System.getProperty("user.dir")}/test/" +// Application.launch(TextWindow()::class.java, "--title=${noteTitle}", "--text=${path}") // // // val f = Filemanager("${System.getProperty("user.dir")}/test/", "hello.txt") // // f.writefile("hello world") // // f.deletefile() // // println(f.openfile()) // } + diff --git a/console/test/hello.txt b/console/test/hello.txt new file mode 100644 index 0000000000000000000000000000000000000000..beb93541bd9e16c9846d23cb9124a459cd67c822 --- /dev/null +++ b/console/test/hello.txt @@ -0,0 +1 @@ +"dude this is annoying" \ No newline at end of file diff --git a/utilities/src/main/kotlin/notes/multi/utilities/Filemanager.kt b/utilities/src/main/kotlin/notes/multi/utilities/Filemanager.kt index e6393910583e3249fefce73153a3536f0995e83e..ffff0dba2ca137c58f84dac4cb702958042bbabc 100644 --- a/utilities/src/main/kotlin/notes/multi/utilities/Filemanager.kt +++ b/utilities/src/main/kotlin/notes/multi/utilities/Filemanager.kt @@ -3,7 +3,7 @@ package notes.multi.utilities import java.io.File import java.io.InputStream -class Filemanager(private val dir: String, private val name: String) { +class Filemanager(private val dir: String, val name: String) { private val directory = File(dir) private val filepath = File("$dir/$name") private val listfiles = mutableListOf<File>() diff --git a/utilities/src/main/kotlin/notes/multi/utilities/NoteTextWindow.kt b/utilities/src/main/kotlin/notes/multi/utilities/NoteTextWindow.kt index e8fafe2d2943428b1e42edcd97552e940243f907..4c2b14a7aafadc2b19c8dfac33bf91eee66845fb 100644 --- a/utilities/src/main/kotlin/notes/multi/utilities/NoteTextWindow.kt +++ b/utilities/src/main/kotlin/notes/multi/utilities/NoteTextWindow.kt @@ -1,4 +1,5 @@ package notes.multi.utilities +import notes.multi.utilities.Filemanager import javafx.application.Application import javafx.stage.Stage @@ -8,10 +9,17 @@ import javafx.scene.control.TextArea import javafx.scene.layout.VBox import javafx.scene.layout.AnchorPane import javafx.application.Application.Parameters +import javafx.application.Platform +import javafx.scene.control.Alert +import javafx.scene.control.ButtonType +import javafx.scene.input.KeyCode import javafx.scene.layout.Priority class TextWindow(): Application() { var paramsMap = mutableMapOf<String, String>() + + + var controlpressed = false override fun init() { super.init() val params = getParameters() @@ -19,9 +27,12 @@ class TextWindow(): Application() { } override fun start(stage: Stage) { + val path = paramsMap["text"]!! + val filecontroller = Filemanager(path, paramsMap["title"]!!) stage.setTitle(paramsMap["title"]) val textarea = TextArea() - textarea.setText(paramsMap["text"]) + //textarea.setText(paramsMap["text"]) + textarea.setText(filecontroller.openfile()) textarea.setWrapText(true) val scroll = ScrollPane() val anchor = AnchorPane(textarea) @@ -45,6 +56,51 @@ class TextWindow(): Application() { VBox.setVgrow(anchor, Priority.ALWAYS) stage.scene = Scene(box, 300.0, 300.0) + + + stage.scene.setOnKeyPressed { event-> + if (event.code == KeyCode.CONTROL) { + controlpressed = true + } else if (event.code == KeyCode.S && controlpressed) { + val warning = Alert(Alert.AlertType.CONFIRMATION) + warning.title = "SAVE" + warning.contentText = "Do you want to save this file?" + val result = warning.showAndWait() + if (result.isPresent) { + when (result.get()) { + ButtonType.OK -> filecontroller.writefile(textarea.getText()) + } + } + } else if (event.code == KeyCode.D && controlpressed) { + val warning = Alert(Alert.AlertType.CONFIRMATION) + warning.title = "DELETE" + warning.contentText = "Do you delete this file?" + val result = warning.showAndWait() + if (result.isPresent) { + when (result.get()) { + ButtonType.OK -> {filecontroller.deletefile() + Platform.exit()} + } + } + } else if (event.code == KeyCode.W && controlpressed) { + val warning = Alert(Alert.AlertType.CONFIRMATION) + warning.title = "WARNING" + warning.contentText = "The current work will not be saved. Are you sure you want to quit?" + val result = warning.showAndWait() + if (result.isPresent) { + when (result.get()) { + ButtonType.OK -> { + Platform.exit() + } + } + } + } + } + + stage.scene.setOnKeyReleased { event-> + if (controlpressed) {controlpressed = false} + } + stage.show() } } \ No newline at end of file