BugFix double click on file dialog

main
Cemal Odabasioglu 2023-12-20 15:38:15 +01:00
parent 71bd09e88f
commit 6e3486ef98
4 changed files with 87 additions and 59 deletions

View File

@ -1,11 +1,10 @@
package main package main
import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.*
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.Button import androidx.compose.material.Button
import androidx.compose.material.MaterialTheme import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text import androidx.compose.material.Text
@ -66,24 +65,29 @@ fun commonWordsTable(
.height(500.dp) .height(500.dp)
.padding(10.dp) .padding(10.dp)
) { ) {
val scrollState = rememberLazyListState()
LazyColumn( LazyColumn(
modifier = Modifier.fillMaxSize().padding(16.dp), state = scrollState,
content = { modifier = Modifier.fillMaxSize().padding(16.dp),
stickyHeader { content = {
commonWordsHeaderRow() stickyHeader {
} commonWordsHeaderRow()
items(glossaryWords) { word -> }
commonWordsDataRow(word.name, codeWords, glossaryWordsSet) items(glossaryWords) { word ->
} commonWordsDataRow(word.name, codeWords, glossaryWordsSet)
items(codeWords) { word -> }
if (word !in glossaryWordsSet) { items(codeWords) { word ->
commonWordsDataRow(word, codeWords, glossaryWordsSet) if (word !in glossaryWordsSet) {
commonWordsDataRow(word, codeWords, glossaryWordsSet)
}
} }
} }
} )
) VerticalScrollbar(
} modifier = Modifier.align(Alignment.CenterEnd).fillMaxHeight(),
adapter = rememberScrollbarAdapter(scrollState)
)
}
} }
@Composable @Composable

View File

@ -12,14 +12,15 @@ import org.apache.poi.ss.usermodel.Workbook
import org.apache.poi.xssf.usermodel.XSSFWorkbook import org.apache.poi.xssf.usermodel.XSSFWorkbook
import java.awt.FileDialog import java.awt.FileDialog
import java.awt.Frame import java.awt.Frame
import java.io.File
import java.io.FileInputStream import java.io.FileInputStream
import java.io.FileWriter import java.io.FileWriter
import java.io.IOException import java.io.IOException
import java.io.File
data class Glossary(val name: String, val jsonFilePath: String) data class Glossary(val name: String, val jsonFilePath: String)
val frame = Frame()
@OptIn(ExperimentalMaterialApi::class) @OptIn(ExperimentalMaterialApi::class)
@Composable @Composable
fun glossaryPage( fun glossaryPage(
@ -81,7 +82,10 @@ fun glossaryPage(
text = { Text("Le fichier a été importé avec succès") }, text = { Text("Le fichier a été importé avec succès") },
confirmButton = { confirmButton = {
Button( Button(
onClick = { importedSuccessfully.value = false }, onClick = {
importedSuccessfully.value = false
frame.dispose()
},
colors = ButtonDefaults.buttonColors( colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor, backgroundColor = customRedColor,
contentColor = Color.White contentColor = Color.White
@ -157,12 +161,12 @@ fun glossaryPage(
var importedSuccessfully = mutableStateOf(false) var importedSuccessfully = mutableStateOf(false)
var exportedSuccessfully = mutableStateOf(false) var exportedSuccessfully = mutableStateOf(false)
fun selectFile(extensions: Set<String>, onFileSelected: (String) -> Unit) { fun selectFile(extensions: Set<String>, onFileSelected: (String) -> Unit) {
val fileDialog = FileDialog(Frame(), "Select a file", FileDialog.LOAD)
val fileDialog = FileDialog(frame, "Select a file", FileDialog.LOAD)
fileDialog.isMultipleMode = true // To enable selecting only one file fileDialog.isMultipleMode = true // To enable selecting only one file
fileDialog.file = "*." + extensions.joinToString(";*.") fileDialog.file = "*." + extensions.joinToString(";*.")
fileDialog.isVisible = true fileDialog.isVisible = true
val selectedFiles = fileDialog.files val selectedFiles = fileDialog.files
if (selectedFiles != null) { if (selectedFiles != null) {
@ -180,6 +184,7 @@ fun selectFile(extensions: Set<String>, onFileSelected: (String) -> Unit) {
} else { } else {
println("Open command cancelled by user.") println("Open command cancelled by user.")
} }
frame.dispose()
} }
fun exportToCSV(glossary: Glossary, csvFilePath: String) { fun exportToCSV(glossary: Glossary, csvFilePath: String) {

View File

@ -1,10 +1,10 @@
package main package main
import androidx.compose.foundation.Image import androidx.compose.foundation.*
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.* import androidx.compose.material.*
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
@ -156,8 +156,10 @@ fun GlossaryList(glossaries: List<Glossary>, onGlossarySelected: (Glossary) -> U
.height(500.dp) .height(500.dp)
.padding(10.dp) .padding(10.dp)
) { ) {
val scrollState = rememberLazyListState()
LazyColumn( LazyColumn(
modifier = Modifier.padding(10.dp), state = scrollState,
modifier = Modifier.padding(10.dp).border(1.dp, Color.Black),
verticalArrangement = Arrangement.spacedBy(10.dp) verticalArrangement = Arrangement.spacedBy(10.dp)
) { ) {
items(glossaries) { glossary -> items(glossaries) { glossary ->
@ -169,6 +171,9 @@ fun GlossaryList(glossaries: List<Glossary>, onGlossarySelected: (Glossary) -> U
onClick = { onClick = {
onGlossarySelected(glossary) onGlossarySelected(glossary)
}, },
modifier = Modifier
.width(150.dp)
.padding(10.dp, 0.dp, 0.dp, 0.dp),
colors = ButtonDefaults.buttonColors( colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor, backgroundColor = customRedColor,
contentColor = Color.White contentColor = Color.White
@ -179,8 +184,11 @@ fun GlossaryList(glossaries: List<Glossary>, onGlossarySelected: (Glossary) -> U
} }
} }
} }
VerticalScrollbar(
modifier = Modifier.align(Alignment.CenterEnd).fillMaxHeight(),
adapter = rememberScrollbarAdapter(scrollState)
)
Spacer(modifier = Modifier.height(6.dp)) Spacer(modifier = Modifier.height(6.dp))
} }
} }
} }

View File

@ -1,9 +1,13 @@
package main package main
import androidx.compose.desktop.ui.tooling.preview.Preview import androidx.compose.desktop.ui.tooling.preview.Preview
import androidx.compose.foundation.VerticalScrollbar
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items 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.*
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Delete import androidx.compose.material.icons.filled.Delete
@ -70,44 +74,51 @@ fun app() {
modifier = Modifier modifier = Modifier
.height(300.dp) .height(300.dp)
.padding(10.dp) .padding(10.dp)
.border(1.dp, Color.Black)
) { ) {
val scrollState = rememberLazyListState()
LazyColumn( LazyColumn(
modifier = Modifier.padding(10.dp), state = scrollState,
verticalArrangement = Arrangement.spacedBy(10.dp) modifier = Modifier.padding(10.dp),
) { verticalArrangement = Arrangement.spacedBy(10.dp)
items(glossaries) { glossary -> ) {
Row( items(glossaries) { glossary ->
modifier = Modifier.width(200.dp).fillMaxWidth(), Row(
horizontalArrangement = Arrangement.SpaceBetween modifier = Modifier.width(200.dp).fillMaxWidth(),
) { horizontalArrangement = Arrangement.SpaceBetween
Button(
onClick = {
selectedGlossary = glossary
currentPage.value = "glossaireOptions"
},
modifier = Modifier
.width(150.dp),
colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor,
contentColor = Color.White
)
) { ) {
Text(glossary.name) Button(
} onClick = {
selectedGlossary = glossary
IconButton( currentPage.value = "glossaireOptions"
onClick = { },
// Handle delete glossary action modifier = Modifier
glossaries = glossaries.filterNot { it == glossary } .width(150.dp),
val file = File(glossary.jsonFilePath) colors = ButtonDefaults.buttonColors(
file.delete() 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")
} }
) {
Icon(imageVector = Icons.Default.Delete, contentDescription = "Delete Glossary")
} }
} }
} }
} VerticalScrollbar(
modifier = Modifier.align(Alignment.CenterEnd).fillMaxHeight(),
adapter = rememberScrollbarAdapter(scrollState)
)
} }
Spacer(modifier = Modifier.height(16.dp)) Spacer(modifier = Modifier.height(16.dp))