diff --git a/client/src/main/kotlin/org/hso/texturesyncclient/view/importView/ImportViewController.kt b/client/src/main/kotlin/org/hso/texturesyncclient/view/importView/ImportViewController.kt index 097bb7b..26acfa3 100644 --- a/client/src/main/kotlin/org/hso/texturesyncclient/view/importView/ImportViewController.kt +++ b/client/src/main/kotlin/org/hso/texturesyncclient/view/importView/ImportViewController.kt @@ -3,28 +3,42 @@ package org.hso.texturesyncclient.view.importView import javafx.stage.FileChooser.ExtensionFilter import org.hso.texturesyncclient.controller.RootController import tornadofx.Controller -import tornadofx.FileChooserMode -import tornadofx.chooseFile +import javafx.stage.FileChooser +import java.io.File + class ImportViewController : Controller() { private val iv = find(ImportView::class) private val rootc = find(RootController::class) - fun btnFileChooserAction() { - val list = listOf("*.png", "*.PNG", "*.jpg", "*.JPG", "*.jpeg", "*.JPEG") - val arrayFilter = arrayOf(ExtensionFilter("Texturen vom Bildformat: PNG oder JPG", list)) - val file = chooseFile("Textur auswählen", arrayFilter, FileChooserMode.Single, owner = null) + private var lastImportDir: String = System.getProperty("user.home") - if (file.isNotEmpty()) { - iv.tfFilePath.text = file[0].absolutePath - iv.tfName.text = file[0].nameWithoutExtension + fun btnFileChooserAction() { + val fileChooser = FileChooser() + val fileExtensions = FileChooser.ExtensionFilter( + "Texturen vom Bildformat: PNG oder JPEG", "*.png", "*.PNG", "*.jpg", "*.JPG", "*.jpeg", "*.JPEG" + ) + + fileChooser.extensionFilters.addAll(fileExtensions) + fileChooser.initialDirectory = File(lastImportDir) + fileChooser.title = "Textur auswählen" + + val file = fileChooser.showOpenDialog(null) + + if (file != null) { + iv.tfFilePath.text = file.absolutePath + iv.tfName.text = file.nameWithoutExtension + lastImportDir = file.parent.toString() //store last user chosen dir } } fun btnImportAction() { rootc.importTexture(iv.tfFilePath.text, iv.tfName.text, iv.cvTags.chips) rootc.switchImportToMain() + iv.tfFilePath.clear() + iv.tfName.clear() + iv.cvTags.chips.clear() } fun validateImport() {