Add ScrollBar on ProjectList
parent
6631008fcc
commit
60d7cf84c6
|
@ -188,23 +188,34 @@ fun newGlossary(
|
|||
.fillMaxWidth()
|
||||
.onKeyEvent { event ->
|
||||
if (event.key == Key.Enter && event.type == KeyEventType.KeyDown) {
|
||||
if (nouveauGlossaireName.isEmpty()) {
|
||||
when {
|
||||
nouveauGlossaireName.isEmpty() -> {
|
||||
println("Veuillez saisir un nom pour le nouveau glossaire")
|
||||
isEmptySnackbarVisibleState.value = true
|
||||
} else if (nouveauGlossaireName.contains(" ")) {
|
||||
}
|
||||
nouveauGlossaireName.contains(" ") -> {
|
||||
println("Le nom du glossaire ne doit pas contenir d'espace")
|
||||
containsSpaceSnackbarVisibleState.value = true
|
||||
} else if (glossaries.any { it.name == nouveauGlossaireName }) {
|
||||
}
|
||||
glossaries.any { it.name == nouveauGlossaireName } -> {
|
||||
println("Le nom du glossaire existe déjà")
|
||||
glossaryAlreadyExistsSnackbarVisibleState.value = true
|
||||
} else if (!isValidFileName(nouveauGlossaireName)) {
|
||||
}
|
||||
!isValidFileName(nouveauGlossaireName) -> {
|
||||
println("Le nom du glossaire contient des caractères non autorisés")
|
||||
invalidCharacterSnackbarVisibleState.value = true
|
||||
} else {
|
||||
val directory = File("src/main/resources/projects/${appState.selectedProject}/$nouveauGlossaireName")
|
||||
directory.mkdirs()
|
||||
println("Project $nouveauGlossaireName created")
|
||||
currentPage.value = "projects"
|
||||
}
|
||||
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 {
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package main
|
||||
|
||||
import androidx.compose.foundation.VerticalScrollbar
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.foundation.rememberScrollbarAdapter
|
||||
import androidx.compose.material.*
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Delete
|
||||
|
@ -39,28 +42,32 @@ fun projectsPage(
|
|||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
LazyColumn(
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.height(300.dp)
|
||||
.width(250.dp)
|
||||
.padding(10.dp)
|
||||
.width(200.dp)
|
||||
.height(300.dp),
|
||||
) {
|
||||
val scrollState = rememberLazyListState()
|
||||
projects = loadProjects()
|
||||
if (projects.isEmpty()) {
|
||||
Text("Aucun proje n'a été créé")
|
||||
} else {
|
||||
LazyColumn(
|
||||
state = scrollState,
|
||||
modifier = Modifier.padding(10.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(10.dp)
|
||||
) {
|
||||
if (projects.isEmpty()) {
|
||||
item {
|
||||
Text("Aucun projet n'a été créé")
|
||||
}
|
||||
} else {
|
||||
items(projects, key = { project -> project.name }) { project ->
|
||||
println(projects)
|
||||
items(projects) { project ->
|
||||
Row(
|
||||
modifier = Modifier.width(200.dp).fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
Button(
|
||||
onClick = {
|
||||
appState.selectedProject = project
|
||||
main.appState.selectedProject = project
|
||||
currentPage.value = "glossaires"
|
||||
|
||||
},
|
||||
modifier = Modifier
|
||||
.width(150.dp),
|
||||
|
@ -74,20 +81,27 @@ fun projectsPage(
|
|||
|
||||
IconButton(
|
||||
onClick = {
|
||||
// Handle delete project action
|
||||
projects = projects.filterNot { it.name == project.name }
|
||||
println(projects)
|
||||
// Handle delete glossary action
|
||||
projects = projects.filterNot { it == project }
|
||||
val directory = File("src/main/resources/projects/${project.name}/")
|
||||
directory.deleteRecursively()
|
||||
currentPage.value = "projects"
|
||||
}
|
||||
) {
|
||||
Icon(imageVector = Icons.Default.Delete, contentDescription = "Delete Project")
|
||||
Icon(
|
||||
imageVector = Icons.Default.Delete,
|
||||
contentDescription = "Delete Project"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
VerticalScrollbar(
|
||||
modifier = Modifier.align(Alignment.CenterEnd).fillMaxHeight(),
|
||||
adapter = rememberScrollbarAdapter(scrollState)
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
|
|
Loading…
Reference in New Issue