Thomas
01/12/2021, 8:01 PMKirill Grouchnikov
01/13/2021, 5:14 AMThomas
01/13/2021, 6:35 AMAlertDialog
. As you can see the code makes a couple of assumptions, that's why I call it a hack. 🙂 For example: will AppManager.windows.last().window
really always refer to the dialog? Also, upon recompositions we may get unwanted double listener registrations, so I need to make sure the listeners are set only if needed (will likely use client properties). Finally, clicking and dragging inteferes with normal Compose behavior. So, again, in this version it's a hack, yet a cool one.
if (isConfirmDialogVisible.value) {
AlertDialog(onDismissRequest = {
isConfirmDialogVisible.value = false
},
properties = DesktopDialogProperties(undecorated = true),
modifier = Modifier.border(width = 1.dp,
MaterialTheme.colors.primary),
title = {
Text(RESOURCE_BUNDLE.getString("confirm_deletion"))
},
text = {
ScrollableColumn {
val sb = StringBuilder()
selectedFiles.forEach {
sb.append(checksums[currentPos], it.name).appendLine()
}
Text(sb.toString())
}
},
dismissButton = {
Button(onClick = {
isConfirmDialogVisible.value = false
}) {
Text(RESOURCE_BUNDLE.getString("cancel"))
}
},
confirmButton = {
Button(onClick = {
isConfirmDialogVisible.value = false
selectedFiles.forEach {
df.deleteFile(checksums[currentPos], it)
}
selected.clear()
}) {
Text(RESOURCE_BUNDLE.getString("delete"))
}
})
val window = AppManager.windows.last().window
val component = window.contentPane.getComponent(0)
val adapter = object : MouseInputAdapter() {
private lateinit var initialClick: Point
override fun mousePressed(e: MouseEvent) {
initialClick = e.point
}
override fun mouseDragged(e: MouseEvent) {
val dx = e.x - initialClick.x
val dy = e.y - initialClick.y
window.setLocation(window.location.x + dx,
window.location.y + dy)
}
}
component.addMouseMotionListener(adapter)
component.addMouseListener(adapter)
}