# File dialogs

Open, save and folder pickers with FileKit, set up for you by nucleusApplication.

Nucleus apps use [FileKit](https://filekit.mintlify.app) for native open, save and folder
pickers. Add the dependency and call FileKit: Nucleus does the setup. For the full API (file
types, multiple selection, savers, `PlatformFile`), see the
[FileKit documentation](https://filekit.mintlify.app/dialogs/setup).

```kotlin title="build.gradle.kts"
dependencies {
    implementation("io.github.vinceglb:filekit-dialogs:<filekit-version>")
}
```

## Pick a file

```kotlin
val scope = rememberCoroutineScope()

Button(onClick = {
    scope.launch {
        val file = FileKit.openFilePicker(type = FileKitType.Image)
        // file is null when the user cancels
    }
}) {
    Text("Open image")
}
```

## What Nucleus does for you

- **Initialization.** `nucleusApplication` calls `FileKit.init(NucleusApp.appId)` when FileKit is
  on the classpath. Dev runs, packaged apps and native images share one files directory.
- **Uninstall.** On Windows that directory is `%APPDATA%\<appId>`, which the NSIS uninstaller
  removes when you set `deleteAppDataOnUninstall`.
- **Native image.** The Nucleus plugin ships FileKit's GraalVM metadata, so the pickers work in a
  native image with no configuration.

The automatic `FileKit.init` is new. Your own `FileKit.init(…)` before `nucleusApplication` still
wins, a call inside `content` replaces the automatic one, and
`nucleusApplication(args, initializeFileKit = false)` turns it off. See
[Migrate from Nucleus 2.x](/docs/migrate/from-2.x#check-the-filekit-initialization).

## Attach the dialog to a window 

Wrap the FileKit call in `withFileKitDialogSettings` on the window that opens it. The picker then
stays above that window instead of floating free:

```kotlin
val window = LocalNucleusWindow.current

scope.launch {
    val file = window.withFileKitDialogSettings { settings ->
        FileKit.openFilePicker(dialogSettings = settings)
    }
}
```

Pass your own `FileKitDialogSettings` as the first argument to keep a title or macOS options:
Nucleus only fills in `parent`, and leaves settings that already have one untouched. It works on
Windows, X11 and Wayland. macOS needs no parent: the picker is already modal to the app.

## What's next

- [Application entry point](/docs/lifecycle/application): every `nucleusApplication` option.
- [FileKit documentation](https://filekit.mintlify.app): the full picker and file API.
- [Windows](/docs/windows): `nucleusWindow` and the native window handle.
