Merge remote-tracking branch 'origin/main'
commit
eb82898daf
|
@ -1,5 +1,11 @@
|
|||
package main
|
||||
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import org.apache.poi.ss.usermodel.CellType
|
||||
import org.apache.poi.ss.usermodel.Workbook
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook
|
||||
|
@ -9,12 +15,149 @@ import java.io.FileInputStream
|
|||
import java.io.FileWriter
|
||||
import java.io.IOException
|
||||
import java.io.File
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.input.key.*
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
|
||||
data class Glossary(val name: String, val jsonFilePath: String)
|
||||
|
||||
val frame = Frame()
|
||||
|
||||
@OptIn(ExperimentalStdlibApi::class, ExperimentalComposeUiApi::class)
|
||||
@Composable
|
||||
fun newGlossary(
|
||||
currentPage: MutableState<String>,
|
||||
) {
|
||||
val isEmptySnackbarVisibleState = remember { mutableStateOf(false) }
|
||||
val containsSpaceSnackbarVisibleState = remember { mutableStateOf(false) }
|
||||
val glossaryAlreadyExistsSnackbarVisibleState = remember { mutableStateOf(false) }
|
||||
val invalidCharacterSnackbarVisibleState = remember { mutableStateOf(false) }
|
||||
|
||||
var glossaries by remember { mutableStateOf(emptyList<Glossary>()) }
|
||||
|
||||
var nouveauGlossaireName by remember { mutableStateOf("") }
|
||||
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
TextField(
|
||||
value = nouveauGlossaireName,
|
||||
onValueChange = { nouveauGlossaireName = it },
|
||||
singleLine = true,
|
||||
label = { Text("Nom du nouveau glossaire") },
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.fillMaxWidth()
|
||||
.onKeyEvent { event ->
|
||||
if (event.key == Key.Enter && event.type == KeyEventType.KeyDown) {
|
||||
// Handle the Enter key event by calling the common function
|
||||
when {
|
||||
nouveauGlossaireName.isEmpty() -> {
|
||||
println("Veuillez saisir un nom pour le nouveau glossaire")
|
||||
isEmptySnackbarVisibleState.value = true
|
||||
}
|
||||
nouveauGlossaireName.contains(" ") -> {
|
||||
println("Le nom du glossaire ne doit pas contenir d'espace")
|
||||
containsSpaceSnackbarVisibleState.value = true
|
||||
}
|
||||
glossaries.any { it.name == nouveauGlossaireName } -> {
|
||||
println("Le nom du glossaire existe déjà")
|
||||
glossaryAlreadyExistsSnackbarVisibleState.value = true
|
||||
}
|
||||
!isValidFileName(nouveauGlossaireName) -> {
|
||||
println("Le nom du glossaire contient des caractères non autorisés")
|
||||
invalidCharacterSnackbarVisibleState.value = true
|
||||
}
|
||||
else -> {
|
||||
val newGlossary = Glossary(nouveauGlossaireName, "$nouveauGlossaireName.json")
|
||||
glossaries = glossaries + newGlossary
|
||||
// create new json file
|
||||
val newFile =
|
||||
File(glossaryPath + (appState.selectedProject?.name) + "/" + newGlossary.jsonFilePath)
|
||||
newFile.createNewFile()
|
||||
// update glossaries list
|
||||
glossaries = loadGlossaries(appState.selectedProject!!)
|
||||
currentPage.value = "glossaires" // Revenir à la liste des glossaires
|
||||
}
|
||||
}
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
},
|
||||
colors = TextFieldDefaults.textFieldColors(
|
||||
backgroundColor = Color.White,
|
||||
focusedIndicatorColor = customRedColor,
|
||||
unfocusedIndicatorColor = Color.Gray
|
||||
)
|
||||
)
|
||||
|
||||
Button(
|
||||
onClick = {
|
||||
// Handle the Enter key event by calling the common function
|
||||
when {
|
||||
nouveauGlossaireName.isEmpty() -> {
|
||||
println("Veuillez saisir un nom pour le nouveau glossaire")
|
||||
isEmptySnackbarVisibleState.value = true
|
||||
}
|
||||
nouveauGlossaireName.contains(" ") -> {
|
||||
println("Le nom du glossaire ne doit pas contenir d'espace")
|
||||
containsSpaceSnackbarVisibleState.value = true
|
||||
}
|
||||
glossaries.any { it.name == nouveauGlossaireName } -> {
|
||||
println("Le nom du glossaire existe déjà")
|
||||
glossaryAlreadyExistsSnackbarVisibleState.value = true
|
||||
}
|
||||
!isValidFileName(nouveauGlossaireName) -> {
|
||||
println("Le nom du glossaire contient des caractères non autorisés")
|
||||
invalidCharacterSnackbarVisibleState.value = true
|
||||
}
|
||||
else -> {
|
||||
val newGlossary = Glossary(nouveauGlossaireName, "$nouveauGlossaireName.json")
|
||||
glossaries = glossaries + newGlossary
|
||||
// create new json file
|
||||
val newFile =
|
||||
File(glossaryPath + (appState.selectedProject?.name) + "/" + newGlossary.jsonFilePath)
|
||||
newFile.createNewFile()
|
||||
// update glossaries list
|
||||
glossaries = loadGlossaries(appState.selectedProject!!)
|
||||
currentPage.value = "glossaires" // Revenir à la liste des glossaires
|
||||
}
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.width(200.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = customRedColor,
|
||||
contentColor = Color.White
|
||||
)
|
||||
) {
|
||||
Text("Créer")
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = {
|
||||
currentPage.value = "glossaires"
|
||||
},
|
||||
modifier = Modifier
|
||||
.width(200.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = customRedColor,
|
||||
contentColor = Color.White
|
||||
)
|
||||
) {
|
||||
Text("Annuler")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun selectFile(extensions: Set<String>, onFileSelected: (String) -> Unit) {
|
||||
|
||||
val fileDialog = FileDialog(frame, "Select a file", FileDialog.LOAD)
|
||||
|
|
|
@ -177,122 +177,9 @@ fun app() {
|
|||
|
||||
// Nouvelle page pour créer un nouveau glossaire
|
||||
"nouveauGlossaire" -> {
|
||||
var nouveauGlossaireName by remember { mutableStateOf("") }
|
||||
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
TextField(
|
||||
value = nouveauGlossaireName,
|
||||
onValueChange = { nouveauGlossaireName = it },
|
||||
singleLine = true,
|
||||
label = { Text("Nom du nouveau glossaire") },
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.fillMaxWidth()
|
||||
.onKeyEvent { event ->
|
||||
if (event.key == Key.Enter && event.type == KeyEventType.KeyDown) {
|
||||
// Handle the Enter key event by calling the common function
|
||||
when {
|
||||
nouveauGlossaireName.isEmpty() -> {
|
||||
println("Veuillez saisir un nom pour le nouveau glossaire")
|
||||
isEmptySnackbarVisibleState.value = true
|
||||
}
|
||||
nouveauGlossaireName.contains(" ") -> {
|
||||
println("Le nom du glossaire ne doit pas contenir d'espace")
|
||||
containsSpaceSnackbarVisibleState.value = true
|
||||
}
|
||||
glossaries.any { it.name == nouveauGlossaireName } -> {
|
||||
println("Le nom du glossaire existe déjà")
|
||||
glossaryAlreadyExistsSnackbarVisibleState.value = true
|
||||
}
|
||||
!isValidFileName(nouveauGlossaireName) -> {
|
||||
println("Le nom du glossaire contient des caractères non autorisés")
|
||||
invalidCharacterSnackbarVisibleState.value = true
|
||||
}
|
||||
else -> {
|
||||
val newGlossary = Glossary(nouveauGlossaireName, "$nouveauGlossaireName.json")
|
||||
glossaries = glossaries + newGlossary
|
||||
// create new json file
|
||||
val newFile =
|
||||
File(glossaryPath + (appState.selectedProject?.name) + "/" + newGlossary.jsonFilePath)
|
||||
newFile.createNewFile()
|
||||
// update glossaries list
|
||||
glossaries = loadGlossaries(appState.selectedProject!!)
|
||||
currentPage.value = "glossaires" // Revenir à la liste des glossaires
|
||||
}
|
||||
}
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
},
|
||||
colors = TextFieldDefaults.textFieldColors(
|
||||
backgroundColor = Color.White,
|
||||
focusedIndicatorColor = customRedColor,
|
||||
unfocusedIndicatorColor = Color.Gray
|
||||
newGlossary(
|
||||
currentPage = currentPage,
|
||||
)
|
||||
)
|
||||
|
||||
Button(
|
||||
onClick = {
|
||||
// Handle the Enter key event by calling the common function
|
||||
when {
|
||||
nouveauGlossaireName.isEmpty() -> {
|
||||
println("Veuillez saisir un nom pour le nouveau glossaire")
|
||||
isEmptySnackbarVisibleState.value = true
|
||||
}
|
||||
nouveauGlossaireName.contains(" ") -> {
|
||||
println("Le nom du glossaire ne doit pas contenir d'espace")
|
||||
containsSpaceSnackbarVisibleState.value = true
|
||||
}
|
||||
glossaries.any { it.name == nouveauGlossaireName } -> {
|
||||
println("Le nom du glossaire existe déjà")
|
||||
glossaryAlreadyExistsSnackbarVisibleState.value = true
|
||||
}
|
||||
!isValidFileName(nouveauGlossaireName) -> {
|
||||
println("Le nom du glossaire contient des caractères non autorisés")
|
||||
invalidCharacterSnackbarVisibleState.value = true
|
||||
}
|
||||
else -> {
|
||||
val newGlossary = Glossary(nouveauGlossaireName, "$nouveauGlossaireName.json")
|
||||
glossaries = glossaries + newGlossary
|
||||
// create new json file
|
||||
val newFile =
|
||||
File(glossaryPath + (appState.selectedProject?.name) + "/" + newGlossary.jsonFilePath)
|
||||
newFile.createNewFile()
|
||||
// update glossaries list
|
||||
glossaries = loadGlossaries(appState.selectedProject!!)
|
||||
currentPage.value = "glossaires" // Revenir à la liste des glossaires
|
||||
}
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.width(200.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = customRedColor,
|
||||
contentColor = Color.White
|
||||
)
|
||||
) {
|
||||
Text("Créer")
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = {
|
||||
currentPage.value = "glossaires"
|
||||
},
|
||||
modifier = Modifier
|
||||
.width(200.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = customRedColor,
|
||||
contentColor = Color.White
|
||||
)
|
||||
) {
|
||||
Text("Annuler")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
"projects" -> {
|
||||
|
|
Loading…
Reference in New Issue