Are there any APIs for file dropping? Like, draggi...
# jewel
f
Are there any APIs for file dropping? Like, dragging a file from the system file manager and dropping it on a Jewel window
s
Use the compose drag&drop APIs
There's nothing Jewel specific about that
f
Oh cool, I didn't think those would respond to system d&d events. Thanks!
s
Yeah they do, they piggyback the AWT system :)
f
I have
Copy code
fun main() = application {
    IntUiTheme(
        theme = JewelTheme.darkThemeDefinition(),
        styling = ComponentStyling.default().decoratedWindow(
            windowStyle = DecoratedWindowStyle.dark(), titleBarStyle = TitleBarStyle.dark()
        ),
    ) {
        DecoratedWindow(onCloseRequest = { exitApplication() }) {
            TitleBar {}
            Box(
                Modifier.dragAndDropTarget({
                    when (val e = it.nativeEvent) {
                        is DropTargetDropEvent -> println(e.currentDataFlavorsAsList)
                        is DropTargetDragEvent -> println(e.currentDataFlavorsAsList)
                    }
                    true
                }, object : DragAndDropTarget {
                    override fun onDrop(event: DragAndDropEvent): Boolean {
                        return true
                    }
                }).background(JewelTheme.globalColors.panelBackground).fillMaxSize()
            ) {}
        }
    }
}
but it seems random whether it'll actually appear as a valid drop target or not
You can see it in the video, the cursor switches between the plus icon and the deny icon
When it's got the deny icon, the onDrop callback doesn't get called
I've simplified it to just
Copy code
@OptIn(ExperimentalComposeUiApi::class)
fun main() = application {
    IntUiTheme(
        theme = JewelTheme.darkThemeDefinition(),
        styling = ComponentStyling.default().decoratedWindow(
            windowStyle = DecoratedWindowStyle.dark(), titleBarStyle = TitleBarStyle.dark()
        ),
    ) {
        DecoratedWindow(onCloseRequest = { exitApplication() }) {
            TitleBar {}
            Box(
                Modifier.dragAndDropTarget({
                    it.dragData() is DragData.FilesList
                }, object : DragAndDropTarget {
                    override fun onDrop(event: DragAndDropEvent): Boolean {
                        return true
                    }
                }).background(JewelTheme.globalColors.panelBackground).fillMaxSize()
            ) {}
        }
    }
}
but it still happens
Oh, all I had to do was
remember
the DragAndDropTarget