feat: show directory picker

This commit is contained in:
aro 2022-11-27 17:25:46 +01:00
parent 62731eb74d
commit b77de56091
3 changed files with 33 additions and 7 deletions

View file

@ -4,7 +4,7 @@ import androidx.compose.ui.awt.ComposeWindow
import java.io.File import java.io.File
import javax.swing.JFileChooser import javax.swing.JFileChooser
fun createFileChooser( fun showFilePicker(
onResult: (file: File) -> Unit, onResult: (file: File) -> Unit,
onNoResult: () -> Unit onNoResult: () -> Unit
) { ) {
@ -17,3 +17,17 @@ fun createFileChooser(
filePicker.showOpenDialog(ComposeWindow()) filePicker.showOpenDialog(ComposeWindow())
if (filePicker.selectedFile != null) onResult.invoke(filePicker.selectedFile) else onNoResult.invoke() if (filePicker.selectedFile != null) onResult.invoke(filePicker.selectedFile) else onNoResult.invoke()
} }
fun showDirectoryPicker(
onResult: (file: File) -> Unit,
onNoResult: () -> Unit
) {
val filePicker = JFileChooser(System.getProperty("user.home")).apply {
fileSelectionMode = JFileChooser.DIRECTORIES_ONLY
dialogTitle = "Select a directory"
approveButtonText = "Confirm"
approveButtonToolTipText = "Select source file"
}
filePicker.showOpenDialog(ComposeWindow())
if (filePicker.selectedFile != null) onResult.invoke(filePicker.selectedFile) else onNoResult.invoke()
}

View file

@ -19,7 +19,7 @@ fun AddButton(
) { ) {
FloatingActionButton( FloatingActionButton(
{ {
createFileChooser({ showFilePicker({
Logger.info("Path: ${it.absolutePath}") Logger.info("Path: ${it.absolutePath}")
watcherManager.addFile(it) watcherManager.addFile(it)
}, { }, {

View file

@ -14,9 +14,12 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import xyz.atnrch.wrench.components.center.showDirectoryPicker
import xyz.atnrch.wrench.logger.Logger
import xyz.atnrch.wrench.ui.UIColors import xyz.atnrch.wrench.ui.UIColors
import xyz.atnrch.wrench.watcher.WatcherEntry import xyz.atnrch.wrench.watcher.WatcherEntry
import xyz.atnrch.wrench.watcher.WatcherManager import xyz.atnrch.wrench.watcher.WatcherManager
import kotlin.io.path.pathString
@Composable @Composable
fun OutputEntries( fun OutputEntries(
@ -41,17 +44,26 @@ fun OutputEntries(
Box( Box(
contentAlignment = Alignment.Center contentAlignment = Alignment.Center
) { ) {
Column ( Column(
verticalArrangement = Arrangement.SpaceEvenly, verticalArrangement = Arrangement.SpaceEvenly,
horizontalAlignment = Alignment.CenterHorizontally horizontalAlignment = Alignment.CenterHorizontally
) { ) {
if (entry.map.isEmpty()) {
Text("No output") Text("No output")
Spacer(Modifier.height(28.dp)) } else {
Text("CURRENT SELECTED FILE IS: ${entry.file.absolutePath}") entry.map.forEach {
Text(it.pathString)
}
}
Spacer(Modifier.height(28.dp)) Spacer(Modifier.height(28.dp))
Button( Button(
onClick = { onClick = {
println("test") showDirectoryPicker({
Logger.info("Path: ${it.absolutePath}")
entry.map.add(it.toPath())
}, {
Logger.info("No file selected.")
})
} }
) { ) {
Icon( Icon(