Added confirm dialog for import export
parent
7edd584d7e
commit
5e26cc7fd6
|
@ -1,10 +1,7 @@
|
|||
package main
|
||||
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material.Button
|
||||
import androidx.compose.material.ButtonDefaults
|
||||
import androidx.compose.material.MaterialTheme
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.material.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
|
@ -23,6 +20,7 @@ import java.io.IOException
|
|||
data class Glossary(val name: String, val jsonFilePath: String)
|
||||
|
||||
|
||||
@OptIn(ExperimentalMaterialApi::class)
|
||||
@Composable
|
||||
fun glossaryPage(
|
||||
languageManager: LanguageManager,
|
||||
|
@ -76,6 +74,25 @@ fun glossaryPage(
|
|||
Text(languageManager.getImportText())
|
||||
}
|
||||
|
||||
if (importedSuccessfully.value) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { importedSuccessfully.value = false },
|
||||
title = { Text("Importation réussie") },
|
||||
text = { Text("Le fichier a été importé avec succès") },
|
||||
confirmButton = {
|
||||
Button(
|
||||
onClick = { importedSuccessfully.value = false },
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = customRedColor,
|
||||
contentColor = Color.White
|
||||
)
|
||||
) {
|
||||
Text("OK")
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = onExportClick,
|
||||
modifier = Modifier
|
||||
|
@ -88,6 +105,25 @@ fun glossaryPage(
|
|||
Text(languageManager.getExportText())
|
||||
}
|
||||
|
||||
if (exportedSuccessfully.value) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { exportedSuccessfully.value = false },
|
||||
title = { Text("Exportation réussie") },
|
||||
text = { Text("Le fichier a été exporté avec succès") },
|
||||
confirmButton = {
|
||||
Button(
|
||||
onClick = { exportedSuccessfully.value = false },
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = customRedColor,
|
||||
contentColor = Color.White
|
||||
)
|
||||
) {
|
||||
Text("OK")
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = onSeeGlossaryClick,
|
||||
modifier = Modifier
|
||||
|
@ -118,6 +154,8 @@ fun glossaryPage(
|
|||
}
|
||||
}
|
||||
|
||||
var importedSuccessfully = mutableStateOf(false)
|
||||
var exportedSuccessfully = mutableStateOf(false)
|
||||
fun selectFile(extensions: Set<String>, onFileSelected: (String) -> Unit) {
|
||||
val fileDialog = FileDialog(Frame(), "Select a file", FileDialog.LOAD)
|
||||
fileDialog.isMultipleMode = true // To enable selecting only one file
|
||||
|
@ -159,6 +197,7 @@ fun exportToCSV(glossary: Glossary, csvFilePath: String) {
|
|||
FileWriter(csvFilePath).use { fileWriter ->
|
||||
fileWriter.write(csvContent)
|
||||
}
|
||||
exportedSuccessfully.value = true
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
@ -182,6 +221,7 @@ fun importFile(glossary: Glossary, filePath: String) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
fun importCSVFile(glossary : Glossary, filePath: String) {
|
||||
val file = File(filePath).readText(Charsets.UTF_8)
|
||||
|
||||
|
@ -219,9 +259,12 @@ fun importCSVFile(glossary : Glossary, filePath: String) {
|
|||
}
|
||||
addWordToGlossary(glossary.jsonFilePath, nouveauWord)
|
||||
}
|
||||
importedSuccessfully.value = true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private fun importXLSXFile(glossary: Glossary, cheminFichier: String) {
|
||||
val workbook: Workbook
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue