Removing code duplication
parent
59448f4e4f
commit
25a24353f7
|
@ -134,57 +134,23 @@ fun app() {
|
|||
formulairePage(onAnnulerClick = { currentPage.value = "glossaire" })
|
||||
}
|
||||
"choixLangage" -> {
|
||||
val jsExtensions = setOf("js", "html")
|
||||
val javaExtensions = setOf("java")
|
||||
val pythonExtensions = setOf("py")
|
||||
choixLangagePage(
|
||||
onRetourClick = { currentPage.value = "accueil" },
|
||||
onPythonClick = {
|
||||
val fileDialog = FileDialog(Frame(), "Select a file", FileDialog.LOAD)
|
||||
fileDialog.file = "Untitled.py" // Initial file name
|
||||
fileDialog.isMultipleMode = false // To enable selecting only one file
|
||||
fileDialog.setFile("*.py")
|
||||
fileDialog.isVisible = true
|
||||
|
||||
val selectedFile = fileDialog.file
|
||||
val selectedDirectory = fileDialog.directory
|
||||
|
||||
if (selectedFile != null) {
|
||||
val filePath = selectedDirectory + selectedFile
|
||||
println("Opening: $filePath")
|
||||
} else {
|
||||
println("Open command cancelled by user.")
|
||||
}
|
||||
},
|
||||
selectFile(pythonExtensions) { filePath ->
|
||||
println("Python file selected: $filePath") // Change by parser functions
|
||||
} },
|
||||
onJavaClick = {
|
||||
val fileDialog = FileDialog(Frame(), "Select a file", FileDialog.LOAD)
|
||||
fileDialog.file = "Untitled.java" // Initial file name
|
||||
fileDialog.isMultipleMode = false // To enable selecting only one file
|
||||
fileDialog.setFile("*.java")
|
||||
fileDialog.isVisible = true
|
||||
|
||||
val selectedFile = fileDialog.file
|
||||
val selectedDirectory = fileDialog.directory
|
||||
|
||||
if (selectedFile != null) {
|
||||
val filePath = selectedDirectory + selectedFile
|
||||
println("Opening: $filePath")
|
||||
} else {
|
||||
println("Open command cancelled by user.")
|
||||
selectFile(javaExtensions) { filePath ->
|
||||
println("Java file selected: $filePath") // Change by parser functions
|
||||
}
|
||||
},
|
||||
onJavaScriptClick = {
|
||||
val fileDialog = FileDialog(Frame(), "Select a file", FileDialog.LOAD)
|
||||
fileDialog.file = "Untitled.js" // Initial file name
|
||||
fileDialog.isMultipleMode = false // To enable selecting only one file
|
||||
fileDialog.setFile("*.js")
|
||||
fileDialog.isVisible = true
|
||||
|
||||
val selectedFile = fileDialog.file
|
||||
val selectedDirectory = fileDialog.directory
|
||||
|
||||
if (selectedFile != null) {
|
||||
val filePath = selectedDirectory + selectedFile
|
||||
println("Opening: $filePath")
|
||||
} else {
|
||||
println("Open command cancelled by user.")
|
||||
selectFile(jsExtensions) { filePath ->
|
||||
println("JavaScript file selected: $filePath") // Change by parser functions
|
||||
}
|
||||
}
|
||||
)
|
||||
|
@ -194,6 +160,30 @@ fun app() {
|
|||
}
|
||||
}
|
||||
|
||||
fun selectFile(allowedExtensions: Set<String>, onFileSelected: (String) -> Unit) {
|
||||
val fileDialog = FileDialog(Frame(), "Select a file", FileDialog.LOAD)
|
||||
fileDialog.isMultipleMode = false // To enable selecting only one file
|
||||
fileDialog.isVisible = true
|
||||
|
||||
val selectedFile = fileDialog.file
|
||||
val selectedDirectory = fileDialog.directory
|
||||
|
||||
if (selectedFile != null) {
|
||||
val filePath = "$selectedDirectory$selectedFile"
|
||||
|
||||
// Vérifier si l'extension est autorisée
|
||||
val fileExtension = File(filePath).extension.toLowerCase()
|
||||
if (allowedExtensions.contains(fileExtension)) {
|
||||
println("Opening: $filePath")
|
||||
onFileSelected(filePath)
|
||||
} else {
|
||||
println("Invalid file extension.")
|
||||
}
|
||||
} else {
|
||||
println("Open command cancelled by user.")
|
||||
}
|
||||
}
|
||||
|
||||
fun exportToCSV(csvFilePath: String) {
|
||||
val glossary = chargerDonneesDepuisFichier()
|
||||
val csvContent = buildString {
|
||||
|
|
Loading…
Reference in New Issue