```@Composable fun CharacterModuleView() { But...
# compose-desktop
x
Copy code
@Composable
fun CharacterModuleView() {
    Button(
        onClick = {
            LOG().info("clicked")
        }
    ){
        Text("Import Characters")
    }
}
When clicking the button I'd like to open a new window like a dialog-popup to ask the user for a file path. I tried to put a "Window" in there which did not work. However there is a way to do that I assume eh?
i
You can also open native file chooser:
Copy code
import androidx.compose.desktop.AppWindowAmbient
import androidx.compose.desktop.Window
import androidx.compose.material.Button
import androidx.compose.material.Text

fun main() = Window {
    val window = AppWindowAmbient.current!!
    Button(onClick = {
        java.awt.FileDialog(window.window).isVisible = true
    }) {
        Text("Button")
    }
}
❤️ 3
x
New to Desktop apps! Thanks for the hint
@Igor Demin
Copy code
@Composable
fun CharacterModuleView() {
    Button(
        onClick = {
            FileDialog(AppWindowAmbient.current!!.window).isVisible = true
        }
    ){
        Text("Import Characters")
    }
}
Renders the following error:
Copy code
e: /home/xetra11/Development/projects/CK3-Workbench/src/main/kotlin/com/github/xetra11/ck3workbench/module/character/view/CharacterModuleView.kt: (32, 41): @Composable invocations can only happen from the context of a @Composable function
Is soemthing missing?
i
Copy code
AppWindowAmbient.current
Should be called outside of onClick callback
1