Removing code duplication
parent
59448f4e4f
commit
25a24353f7
|
@ -134,57 +134,23 @@ fun app() {
|
||||||
formulairePage(onAnnulerClick = { currentPage.value = "glossaire" })
|
formulairePage(onAnnulerClick = { currentPage.value = "glossaire" })
|
||||||
}
|
}
|
||||||
"choixLangage" -> {
|
"choixLangage" -> {
|
||||||
|
val jsExtensions = setOf("js", "html")
|
||||||
|
val javaExtensions = setOf("java")
|
||||||
|
val pythonExtensions = setOf("py")
|
||||||
choixLangagePage(
|
choixLangagePage(
|
||||||
onRetourClick = { currentPage.value = "accueil" },
|
onRetourClick = { currentPage.value = "accueil" },
|
||||||
onPythonClick = {
|
onPythonClick = {
|
||||||
val fileDialog = FileDialog(Frame(), "Select a file", FileDialog.LOAD)
|
selectFile(pythonExtensions) { filePath ->
|
||||||
fileDialog.file = "Untitled.py" // Initial file name
|
println("Python file selected: $filePath") // Change by parser functions
|
||||||
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.")
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onJavaClick = {
|
onJavaClick = {
|
||||||
val fileDialog = FileDialog(Frame(), "Select a file", FileDialog.LOAD)
|
selectFile(javaExtensions) { filePath ->
|
||||||
fileDialog.file = "Untitled.java" // Initial file name
|
println("Java file selected: $filePath") // Change by parser functions
|
||||||
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.")
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onJavaScriptClick = {
|
onJavaScriptClick = {
|
||||||
val fileDialog = FileDialog(Frame(), "Select a file", FileDialog.LOAD)
|
selectFile(jsExtensions) { filePath ->
|
||||||
fileDialog.file = "Untitled.js" // Initial file name
|
println("JavaScript file selected: $filePath") // Change by parser functions
|
||||||
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.")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -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) {
|
fun exportToCSV(csvFilePath: String) {
|
||||||
val glossary = chargerDonneesDepuisFichier()
|
val glossary = chargerDonneesDepuisFichier()
|
||||||
val csvContent = buildString {
|
val csvContent = buildString {
|
||||||
|
|
Loading…
Reference in New Issue