I am trying to copy text to clipboard and access o...
# compose-desktop
e
I am trying to copy text to clipboard and access outside of compose app. Appears to be on the clipboard but I can't paste outside the compose app. Am I using the correct Clipboard code?
fun copyToClipboard(value: String) {
val c = Clipboard("")
val s = StringSelection(value)
c.setContents(s, s)
//Test
val stringValue = c.getData(DataFlavor.stringFlavor)
val data = c.getContents(null)
}
j
Copy code
Toolkit.getDefaultToolkit()
        .getSystemClipboard()
        .setContents(
                new StringSelection(value),
                null
        );
👍 3
e
thanks. Will try. Looks like I was using the wrong code.
k
This is probably something that needs to be expected/actual with platform-specific implementations
s
We do have a clipboard manager in compose, but maybe it wasn't implemented as mpp on desktop
j
Ah, that's right. It is implemented for Desktop, btw. So
DesktopClipboardManager
should be available via
AmbientClipboardManager.current
- much as I hate ambients. 😧
DesktopClipboardManager
is literally just a wrapper around
Toolkit.getDefaultToolkit()
, but at least it'll make your widgets be somewhat more platform independent.
e
Will look into the
DesktopClipboardManager
. My current app is only for the desktop.
j
You never know when you might want to port your app to Android 😉
👍 2
e
I rather be android programing. Just writing a simple tool to convert sql statments int linq statments for a project at work. They will be upset that I wrote it in Kotlin & Compose Desktop since it is a microsoft shop.
493 Views