Allow Multiple files to parse

main
Thomas BREIL 2023-12-07 16:21:48 +01:00
parent 87ed353f9e
commit dbc1f8a354
1 changed files with 13 additions and 13 deletions

View File

@ -233,25 +233,25 @@ fun app() {
fun selectFile(extensions: Set<String>, onFileSelected: (String) -> Unit) {
val fileDialog = FileDialog(Frame(), "Select a file", FileDialog.LOAD)
fileDialog.isMultipleMode = false // To enable selecting only one file
fileDialog.isMultipleMode = true // To enable selecting only one file
fileDialog.file = "*." + extensions.joinToString(";*.")
fileDialog.isVisible = true
val selectedFile = fileDialog.file
val selectedDirectory = fileDialog.directory
if (selectedFile != null) {
val filePath = "$selectedDirectory$selectedFile"
val selectedFiles = fileDialog.files
if (selectedFiles != null) {
for (file in selectedFiles) {
println("Selected file: $file")
// Vérifier si l'extension est autorisée
val fileExtension = File(filePath).extension.lowercase()
val fileExtension = File(file.absolutePath).extension.lowercase()
if (extensions.contains(fileExtension)) {
println("Opening: $filePath")
onFileSelected(filePath)
println("Opening: $file")
onFileSelected(file.absolutePath)
} else {
println("Invalid file extension.")
}
}
} else {
println("Open command cancelled by user.")
}