From 7edd584d7ef65c64c97102a8125697b01d43c9c2 Mon Sep 17 00:00:00 2001 From: cemal Date: Tue, 19 Dec 2023 11:04:05 +0100 Subject: [PATCH] Added delete glossary --- src/main/kotlin/main/Main.kt | 44 ++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/main/Main.kt b/src/main/kotlin/main/Main.kt index e57996f..8adadc5 100644 --- a/src/main/kotlin/main/Main.kt +++ b/src/main/kotlin/main/Main.kt @@ -5,6 +5,8 @@ import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.material.* +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Delete import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -17,6 +19,7 @@ import java.awt.Frame import java.io.File import java.util.* + val customRedColor = Color(0xFFB70D1B) @OptIn(ExperimentalMaterialApi::class) @@ -68,19 +71,35 @@ fun app() { verticalArrangement = Arrangement.spacedBy(10.dp) ) { items(glossaries) { glossary -> - Button( - onClick = { - selectedGlossary = glossary - currentPage.value = "glossaireOptions" - }, - modifier = Modifier - .width(200.dp), - colors = ButtonDefaults.buttonColors( - backgroundColor = customRedColor, - contentColor = Color.White - ) + Row( + modifier = Modifier.width(200.dp).fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceBetween ) { - Text(glossary.name) + Button( + onClick = { + selectedGlossary = glossary + currentPage.value = "glossaireOptions" + }, + modifier = Modifier + .width(150.dp), + colors = ButtonDefaults.buttonColors( + backgroundColor = customRedColor, + contentColor = Color.White + ) + ) { + Text(glossary.name) + } + + IconButton( + onClick = { + // Handle delete glossary action + glossaries = glossaries.filterNot { it == glossary } + val file = File(glossary.jsonFilePath) + file.delete() + } + ) { + Icon(imageVector = Icons.Default.Delete, contentDescription = "Delete Glossary") + } } } } @@ -119,6 +138,7 @@ fun app() { } } + // Nouvelle page pour créer un nouveau glossaire "nouveauGlossaire" -> { var nouveauGlossaireName by remember { mutableStateOf("") }