diff --git a/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/DesktopApp.kt b/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/DesktopApp.kt index 81e506a25..416fca3cc 100644 --- a/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/DesktopApp.kt +++ b/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/DesktopApp.kt @@ -122,6 +122,7 @@ class SimplexWindowState { } data class DialogParams( + val filename: String? = null, val allowMultiple: Boolean = false, val fileFilter: ((File?) -> Boolean)? = null, val fileFilterDescription: String = "", diff --git a/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/platform/Files.desktop.kt b/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/platform/Files.desktop.kt index 5cec4f2a7..3e60a1c9b 100644 --- a/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/platform/Files.desktop.kt +++ b/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/platform/Files.desktop.kt @@ -37,15 +37,19 @@ actual class FileChooserLauncher actual constructor() { } actual suspend fun launch(input: String) { - val res = if (getContent) { + var res: File? + if (getContent) { val params = DialogParams( allowMultiple = false, fileFilter = fileFilter(input), fileFilterDescription = fileFilterDescription(input), ) - simplexWindowState.openDialog.awaitResult(params) + res = simplexWindowState.openDialog.awaitResult(params) } else { - simplexWindowState.saveDialog.awaitResult() + res = simplexWindowState.saveDialog.awaitResult(DialogParams(filename = input)) + if (res != null && res.isDirectory) { + res = File(res, input) + } } onResult(res?.toURI()) } diff --git a/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/views/helpers/DefaultDialog.desktop.kt b/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/views/helpers/DefaultDialog.desktop.kt index 58edc0d88..e485ee479 100644 --- a/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/views/helpers/DefaultDialog.desktop.kt +++ b/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/views/helpers/DefaultDialog.desktop.kt @@ -41,9 +41,9 @@ fun FrameWindowScope.FileDialogChooser( onResult: (result: List) -> Unit ) { if (isLinux()) { - FileDialogChooserMultiple(title, isLoad, params.allowMultiple, params.fileFilter, params.fileFilterDescription, onResult) + FileDialogChooserMultiple(title, isLoad, params.filename, params.allowMultiple, params.fileFilter, params.fileFilterDescription, onResult) } else { - FileDialogAwt(title, isLoad, params.allowMultiple, params.fileFilter, onResult) + FileDialogAwt(title, isLoad, params.filename, params.allowMultiple, params.fileFilter, onResult) } } @@ -51,6 +51,7 @@ fun FrameWindowScope.FileDialogChooser( fun FrameWindowScope.FileDialogChooserMultiple( title: String, isLoad: Boolean, + filename: String?, allowMultiple: Boolean, fileFilter: ((File?) -> Boolean)? = null, fileFilterDescription: String? = null, @@ -73,7 +74,11 @@ fun FrameWindowScope.FileDialogChooserMultiple( val returned = if (isLoad) { fileChooser.showOpenDialog(window) } else { - fileChooser.fileSelectionMode = JFileChooser.DIRECTORIES_ONLY + if (filename != null) { + fileChooser.selectedFile = File(filename) + } else { + fileChooser.fileSelectionMode = JFileChooser.DIRECTORIES_ONLY + } fileChooser.showSaveDialog(window) } val result = when (returned) { @@ -109,6 +114,7 @@ fun FrameWindowScope.FileDialogChooserMultiple( private fun FrameWindowScope.FileDialogAwt( title: String, isLoad: Boolean, + filename: String?, allowMultiple: Boolean, fileFilter: ((File?) -> Boolean)? = null, onResult: (result: List) -> Unit @@ -128,6 +134,9 @@ private fun FrameWindowScope.FileDialogAwt( }.apply { this.title = title this.isMultipleMode = allowMultiple && isLoad + if (!isLoad && filename != null) { + this.file = filename + } if (fileFilter != null) { this.setFilenameFilter { dir, file -> fileFilter(File(dir.absolutePath + File.separator + file)) diff --git a/apps/multiplatform/desktop/src/jvmMain/kotlin/chat/simplex/desktop/Main.kt b/apps/multiplatform/desktop/src/jvmMain/kotlin/chat/simplex/desktop/Main.kt index 542ade961..4d97bc49b 100644 --- a/apps/multiplatform/desktop/src/jvmMain/kotlin/chat/simplex/desktop/Main.kt +++ b/apps/multiplatform/desktop/src/jvmMain/kotlin/chat/simplex/desktop/Main.kt @@ -10,6 +10,7 @@ fun main() { initHaskell() initApp() tmpDir.deleteRecursively() + tmpDir.mkdir() return showApp() }