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
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.*
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.material.Button
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
@ -66,8 +65,9 @@ fun commonWordsTable(
.height(500.dp)
.padding(10.dp)
) {
val scrollState = rememberLazyListState()
LazyColumn(
state = scrollState,
modifier = Modifier.fillMaxSize().padding(16.dp),
content = {
stickyHeader {
@ -83,7 +83,11 @@ fun commonWordsTable(
}
}
)
}
VerticalScrollbar(
modifier = Modifier.align(Alignment.CenterEnd).fillMaxHeight(),
adapter = rememberScrollbarAdapter(scrollState)
)
}
}
@Composable

View File

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

View File

@ -1,10 +1,10 @@
package main
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.*
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.material.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
@ -156,8 +156,10 @@ fun GlossaryList(glossaries: List<Glossary>, onGlossarySelected: (Glossary) -> U
.height(500.dp)
.padding(10.dp)
) {
val scrollState = rememberLazyListState()
LazyColumn(
modifier = Modifier.padding(10.dp),
state = scrollState,
modifier = Modifier.padding(10.dp).border(1.dp, Color.Black),
verticalArrangement = Arrangement.spacedBy(10.dp)
) {
items(glossaries) { glossary ->
@ -169,6 +171,9 @@ fun GlossaryList(glossaries: List<Glossary>, onGlossarySelected: (Glossary) -> U
onClick = {
onGlossarySelected(glossary)
},
modifier = Modifier
.width(150.dp)
.padding(10.dp, 0.dp, 0.dp, 0.dp),
colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor,
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))
}
}
}

View File

@ -1,9 +1,13 @@
package main
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.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
@ -70,8 +74,11 @@ fun app() {
modifier = Modifier
.height(300.dp)
.padding(10.dp)
.border(1.dp, Color.Black)
) {
val scrollState = rememberLazyListState()
LazyColumn(
state = scrollState,
modifier = Modifier.padding(10.dp),
verticalArrangement = Arrangement.spacedBy(10.dp)
) {
@ -108,6 +115,10 @@ fun app() {
}
}
}
VerticalScrollbar(
modifier = Modifier.align(Alignment.CenterEnd).fillMaxHeight(),
adapter = rememberScrollbarAdapter(scrollState)
)
}
Spacer(modifier = Modifier.height(16.dp))