Allow Multiple files to parse
parent
87ed353f9e
commit
dbc1f8a354
|
@ -233,25 +233,25 @@ fun app() {
|
||||||
|
|
||||||
fun selectFile(extensions: Set<String>, onFileSelected: (String) -> Unit) {
|
fun selectFile(extensions: Set<String>, onFileSelected: (String) -> Unit) {
|
||||||
val fileDialog = FileDialog(Frame(), "Select a file", FileDialog.LOAD)
|
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.file = "*." + extensions.joinToString(";*.")
|
||||||
fileDialog.isVisible = true
|
fileDialog.isVisible = true
|
||||||
|
|
||||||
|
|
||||||
val selectedFile = fileDialog.file
|
val selectedFiles = fileDialog.files
|
||||||
val selectedDirectory = fileDialog.directory
|
|
||||||
|
|
||||||
if (selectedFile != null) {
|
|
||||||
val filePath = "$selectedDirectory$selectedFile"
|
|
||||||
|
|
||||||
|
if (selectedFiles != null) {
|
||||||
|
for (file in selectedFiles) {
|
||||||
|
println("Selected file: $file")
|
||||||
// Vérifier si l'extension est autorisée
|
// 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)) {
|
if (extensions.contains(fileExtension)) {
|
||||||
println("Opening: $filePath")
|
println("Opening: $file")
|
||||||
onFileSelected(filePath)
|
onFileSelected(file.absolutePath)
|
||||||
} else {
|
} else {
|
||||||
println("Invalid file extension.")
|
println("Invalid file extension.")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
println("Open command cancelled by user.")
|
println("Open command cancelled by user.")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue