diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index a6745bf..6d5986a 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -12,11 +12,8 @@ import androidx.compose.ui.unit.dp import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Check import androidx.compose.material.icons.filled.Close -import javax.swing.JFileChooser -import javax.swing.filechooser.FileNameExtensionFilter -import java.io.File - - +import java.awt.FileDialog +import java.awt.Frame @Composable @@ -69,15 +66,22 @@ fun App() { glossairePage( onAjouterMotClick = { currentPage.value = "formulaire" }, onImporterClick = { - val fileChooser = JFileChooser() - fileChooser.fileFilter = FileNameExtensionFilter("CSV Files", "csv") - val returnVal = fileChooser.showOpenDialog(null) - if (returnVal == JFileChooser.APPROVE_OPTION) { - val file = fileChooser.selectedFile - println("Opening: " + file.name + ".") - } else { - println("Open command cancelled by user.") - } + val fileDialog = FileDialog(Frame(), "Select a file", FileDialog.LOAD) + fileDialog.file = "Untitled.csv" // Initial file name + fileDialog.isMultipleMode = false // To enable selecting only one file + + fileDialog.setFile("*.csv") + 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.") + } }, onExporterClick = { /* Action d'export */ }, onRetourClick = { currentPage.value = "accueil" } @@ -90,37 +94,55 @@ fun App() { ChoixLangagePage( onRetourClick = { currentPage.value = "accueil" }, onPythonClick = { - val fileChooser = JFileChooser() - fileChooser.fileFilter = FileNameExtensionFilter("Python Files", "py") - val returnVal = fileChooser.showOpenDialog(null) - if (returnVal == JFileChooser.APPROVE_OPTION) { - val file = fileChooser.selectedFile - println("Opening: " + file.name + ".") - } else { - println("Open command cancelled by user.") - } + 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.") + } }, onJavaClick = { - val fileChooser = JFileChooser() - fileChooser.fileFilter = FileNameExtensionFilter("Java Files", "java") - val returnVal = fileChooser.showOpenDialog(null) - if (returnVal == JFileChooser.APPROVE_OPTION) { - val file = fileChooser.selectedFile - println("Opening: " + file.name + ".") - } else { - println("Open command cancelled by user.") - } + 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.") + } }, onJavaScriptClick = { - val fileChooser = JFileChooser() - fileChooser.fileFilter = FileNameExtensionFilter("JavaScript Files", "js") - val returnVal = fileChooser.showOpenDialog(null) - if (returnVal == JFileChooser.APPROVE_OPTION) { - val file = fileChooser.selectedFile - println("Opening: " + file.name + ".") - } else { - println("Open command cancelled by user.") - } + 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.") + } } ) }