Skip to content

Commit

Permalink
Merge pull request #106 from MohamedRejeb/0.5.x
Browse files Browse the repository at this point in the history
Fix issue in windows picker when selecting FilePickerFileType.All
  • Loading branch information
MohamedRejeb committed Jun 30, 2024
2 parents 68fc21a + 1c1477e commit 3818a28
Showing 1 changed file with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import kotlinx.coroutines.withContext
import java.awt.Window
import java.io.File

internal class WindowsFilePicker: PlatformFilePicker {
internal class WindowsFilePicker : PlatformFilePicker {
override suspend fun launchFilePicker(
initialDirectory: String?,
type: FilePickerFileType,
Expand All @@ -35,27 +35,33 @@ internal class WindowsFilePicker: PlatformFilePicker {

// Set initial directory, title and file extensions
val fileExtensions =
if (type is FilePickerFileType.Extension)
type.extensions
else
type.value
.map {
MimeTypes.findExtensionsByMimeTypes(it, it.contains('*'))
}
.flatten()
.distinct()
when (type) {
is FilePickerFileType.All ->
emptyList()

is FilePickerFileType.Extension ->
type.extensions

else ->
type.value
.map {
MimeTypes.findExtensionsByMimeTypes(it, it.contains('*'))
}
.flatten()
.distinct()
}
setup(initialDirectory, fileExtensions, title)
}

// Show file chooser
fileChooser.showOpenDialog(parentWindow)

// Return selected files
val result =
if (selectionMode == FilePickerSelectionMode.Single)
listOfNotNull(fileChooser.selectedFile)
else
fileChooser.selectedFiles.mapNotNull { it }
val result =
if (selectionMode == FilePickerSelectionMode.Single)
listOfNotNull(fileChooser.selectedFile)
else
fileChooser.selectedFiles.mapNotNull { it }
onResult(result)
}

Expand Down

0 comments on commit 3818a28

Please sign in to comment.