A Kotlin/Java wrapper around the small C library by Bernard Teo (btzy/nativefiledialog-extended). As a fallback it uses default AWT file picker.
A library is a perfect fit for the Jetpack Compose for Desktop.
Supported platforms:
- Windows;
- MacOS;
- Linux (GTK).
repositories {
mavenCentral()
}
dependencies {
implementation("tv.wunderbox:nativefiledialog:$nativeFileDialogVersion")
}interfaceFileDialog {
funsave(
filters:List<Filter> = emptyList(),
defaultPath:String? = null,
defaultName:String? = null,
): FileDialogResult<File>
funpickFile(
filters:List<Filter> = emptyList(),
defaultPath:String? = null,
): FileDialogResult<File>
funpickFileMany(
filters:List<Filter> = emptyList(),
defaultPath:String? = null,
): FileDialogResult<List<File>>
funpickDirectory(
defaultPath:String? = null,
): FileDialogResult<File>
}val fileDialog =FileDialog.default(awtComponent)
val result = fileDialog.pickFile() // returns FileDialogResult<File>when (result) {
isFileDialogResult.Success-> {
val file = result.value
// Handle success
}
isFileDialogResult.Failure-> {
// Handle failure
}
}Internally there are two different implementations available,
instead of using the default NfdFileDialog with AwtFileDialog as
a fallback, you can use only one:
val nfdFileDialog =NfdFileDialog()
val awtFileDialog =AwtFileDialog(awtComponent)When using Kotlin Compose Multiplatform the awtComponent variable is a ComposeWindow object that might be obtained from androidx.compose.ui.window.WindowScope.