Update selectedGlossary

main
Thomas Breil 2024-01-12 14:58:42 +01:00
parent 29368a1688
commit a5d3811b45
2 changed files with 9 additions and 8 deletions

View File

@ -39,7 +39,7 @@ val frame = Frame()
fun glossariesPage( fun glossariesPage(
currentPage: MutableState<String> currentPage: MutableState<String>
) { ) {
var selectedGlossary by remember { mutableStateOf<Glossary?>(null) }
var glossaries by remember { mutableStateOf(emptyList<Glossary>()) } var glossaries by remember { mutableStateOf(emptyList<Glossary>()) }
Column( Column(
@ -75,7 +75,7 @@ fun glossariesPage(
) { ) {
Button( Button(
onClick = { onClick = {
selectedGlossary = glossary appState.selectedGlossary = glossary
currentPage.value = "glossaireDetail" currentPage.value = "glossaireDetail"
}, },
modifier = Modifier modifier = Modifier

View File

@ -24,6 +24,7 @@ const val glossaryPath : String = "src/main/resources/projects/"
// Classe pour stocker l'état global // Classe pour stocker l'état global
object AppState { object AppState {
var selectedProject: Project? = null var selectedProject: Project? = null
var selectedGlossary: Glossary? = null
} }
@OptIn(ExperimentalMaterialApi::class, ExperimentalComposeUiApi::class) @OptIn(ExperimentalMaterialApi::class, ExperimentalComposeUiApi::class)
@ -36,7 +37,7 @@ fun app() {
val glossaryDetail: List<Word> by remember { mutableStateOf(emptyList()) } val glossaryDetail: List<Word> by remember { mutableStateOf(emptyList()) }
var isJavaScriptFileSelected by remember { mutableStateOf(false) } var isJavaScriptFileSelected by remember { mutableStateOf(false) }
val selectedGlossary by remember { mutableStateOf<Glossary?>(null) }
val isEmptySnackbarVisibleState = remember { mutableStateOf(false) } val isEmptySnackbarVisibleState = remember { mutableStateOf(false) }
val containsSpaceSnackbarVisibleState = remember { mutableStateOf(false) } val containsSpaceSnackbarVisibleState = remember { mutableStateOf(false) }
@ -82,19 +83,19 @@ fun app() {
"glossaireDetail" -> { "glossaireDetail" -> {
glossaryDetailedPage( glossaryDetailedPage(
glossary = glossaryDetail, glossary = glossaryDetail,
glossaryName = selectedGlossary?.name ?: "", glossaryName = appState.selectedGlossary?.name ?: "",
onBackClick = { currentPage.value = "glossaires" }, onBackClick = { currentPage.value = "glossaires" },
onAddWordClick = { currentPage.value = "formulaire" }, onAddWordClick = { currentPage.value = "formulaire" },
onExportClick = { onExportClick = {
val fileDialog = FileDialog(Frame(), "Save as CSV", FileDialog.SAVE) val fileDialog = FileDialog(Frame(), "Save as CSV", FileDialog.SAVE)
fileDialog.file = selectedGlossary?.name // Initial file name fileDialog.file = appState.selectedGlossary?.name // Initial file name
fileDialog.isVisible = true fileDialog.isVisible = true
val selectedFile = fileDialog.file val selectedFile = fileDialog.file
val selectedDirectory = fileDialog.directory val selectedDirectory = fileDialog.directory
if (selectedFile != null) { if (selectedFile != null) {
val csvFilePath = "$selectedDirectory$selectedFile" val csvFilePath = "$selectedDirectory$selectedFile"
println("Exporting to: $csvFilePath") println("Exporting to: $csvFilePath")
selectedGlossary?.let { exportToCSV(it, csvFilePath) } appState.selectedGlossary?.let { exportToCSV(it, csvFilePath) }
} else { } else {
println("Export command cancelled by user.") println("Export command cancelled by user.")
} }
@ -102,14 +103,14 @@ fun app() {
onImportClick = { onImportClick = {
selectFile(setOf("csv", "xlsx")) { filePath -> selectFile(setOf("csv", "xlsx")) { filePath ->
println("Importing file: $filePath") println("Importing file: $filePath")
selectedGlossary?.let { importFile(it, filePath) } appState.selectedGlossary?.let { importFile(it, filePath) }
} }
} }
) )
} }
"formulaire" -> { "formulaire" -> {
selectedGlossary?.let { formPage(it, onCancelClick = { currentPage.value = "glossaireDetail" }) } appState.selectedGlossary?.let { formPage(it, onCancelClick = { currentPage.value = "glossaireDetail" }) }
} }
"choixLangage" -> { "choixLangage" -> {