in sample/src/main/kotlin/org/jetbrains/desktop/sample/linux/SkikoSampleLinux.kt [1525:1553]
fun getDataTransferData(dataSource: DataSource, mimeType: String): ByteArray {
val content = when (dataSource) {
DataSource.Clipboard -> currentClipboard
DataSource.DragAndDrop -> currentDragContent
DataSource.PrimarySelection -> currentPrimarySelectionContent
}
return when (content) {
is DataTransferContentType.Text -> {
check(mimeType == TEXT_MIME_TYPE) { "Unsupported mime type for text content: $mimeType" }
content.text.encodeToByteArray()
}
is DataTransferContentType.UriList -> {
when (mimeType) {
TEXT_MIME_TYPE -> {
content.files.joinToString("\n").encodeToByteArray()
}
URI_LIST_MIME_TYPE -> {
content.files.joinToString("\r\n", postfix = "\r\n") { Path(it).toUri().toString() }.encodeToByteArray()
}
else -> {
error("Unsupported mime type: $mimeType")
}
}
}
null -> {
error("Trying to paste from $dataSource with empty content")
}
}
}