将目录拖拽进去,复制全路径,感觉挺方便的。
经常去顶部复制时路径只会复制父级目录,有时频繁的操作会很烦。使用compse配合awt写的一个小工具
import androidx.compose.foundation.layout.*
import androidx.compose.material.Button
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.material.TextField
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.LastBaseline
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import androidx.compose.ui.window.rememberWindowState
import java.awt.Toolkit
import java.awt.datatransfer.DataFlavor
import java.awt.datatransfer.StringSelection
import java.awt.dnd.DnDConstants
import java.awt.dnd.DropTarget
import java.awt.dnd.DropTargetDropEvent
import java.io.File
fun main() = application {
val name = remember { mutableStateOf(System.getProperty("user.home")) }
Window(
onCloseRequest = ::exitApplication,
title = "LogParse",
state = rememberWindowState(width = 350.dp, height = 300.dp),
icon = painterResource("app_icon.svg")
) {
MaterialTheme {
Column() {
Row(
modifier = Modifier.fillMaxWidth()
.padding(8.dp),
) {
TextField(
value = name.value,
placeholder = {
Text("Base directory")
},
modifier = Modifier.alignBy(LastBaseline)
.weight(1.0f),
onValueChange = {
name.value = it
},
)
}
Row(
modifier = Modifier.fillMaxWidth()
.padding(8.dp),
) {
Button(
onClick = {
val selection = StringSelection(name.value)
val clipboard = Toolkit.getDefaultToolkit().systemClipboard
clipboard.setContents(selection, null)
println(name.value)
},
modifier = Modifier.alignByBaseline(),
) {
Text("Copy")
}
}
}
val target = object : DropTarget() {
@Synchronized
override fun drop(evt: DropTargetDropEvent) {
try {
evt.acceptDrop(DnDConstants.ACTION_REFERENCE)
val droppedFiles = evt
.transferable.getTransferData(
DataFlavor.javaFileListFlavor
) as List<*>
droppedFiles.first()?.let {
name.value = TextFieldValue((it as File).absolutePath).text
}
} catch (ex: Exception) {
ex.printStackTrace()
}
}
}
window.contentPane.dropTarget = target
}
}
}