Nucleus
OS integration

File dialogs

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

View as Markdown

Nucleus apps use FileKit 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.

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

Pick a file

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.

Changed in 3.0

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.

Attach the dialog to a windowNew

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

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

Was this page helpful?
Edit on GitHub

Last updated on