Allow Multiple files to parse
parent
87ed353f9e
commit
dbc1f8a354
|
@ -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.")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue