mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-07-29 18:30:12 +00:00
desktop: fix creating tmpDir and providing name for file to save (#2789)
* desktop: creating tmpDir * provide name for saved file * directories only selection on Mac * specified filename for file savers --------- Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
This commit is contained in:
co-authored by
Evgeny Poberezkin
parent
71d6410604
commit
02d00944ff
@@ -122,6 +122,7 @@ class SimplexWindowState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data class DialogParams(
|
data class DialogParams(
|
||||||
|
val filename: String? = null,
|
||||||
val allowMultiple: Boolean = false,
|
val allowMultiple: Boolean = false,
|
||||||
val fileFilter: ((File?) -> Boolean)? = null,
|
val fileFilter: ((File?) -> Boolean)? = null,
|
||||||
val fileFilterDescription: String = "",
|
val fileFilterDescription: String = "",
|
||||||
|
|||||||
+7
-3
@@ -37,15 +37,19 @@ actual class FileChooserLauncher actual constructor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
actual suspend fun launch(input: String) {
|
actual suspend fun launch(input: String) {
|
||||||
val res = if (getContent) {
|
var res: File?
|
||||||
|
if (getContent) {
|
||||||
val params = DialogParams(
|
val params = DialogParams(
|
||||||
allowMultiple = false,
|
allowMultiple = false,
|
||||||
fileFilter = fileFilter(input),
|
fileFilter = fileFilter(input),
|
||||||
fileFilterDescription = fileFilterDescription(input),
|
fileFilterDescription = fileFilterDescription(input),
|
||||||
)
|
)
|
||||||
simplexWindowState.openDialog.awaitResult(params)
|
res = simplexWindowState.openDialog.awaitResult(params)
|
||||||
} else {
|
} else {
|
||||||
simplexWindowState.saveDialog.awaitResult()
|
res = simplexWindowState.saveDialog.awaitResult(DialogParams(filename = input))
|
||||||
|
if (res != null && res.isDirectory) {
|
||||||
|
res = File(res, input)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
onResult(res?.toURI())
|
onResult(res?.toURI())
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-3
@@ -41,9 +41,9 @@ fun FrameWindowScope.FileDialogChooser(
|
|||||||
onResult: (result: List<File>) -> Unit
|
onResult: (result: List<File>) -> Unit
|
||||||
) {
|
) {
|
||||||
if (isLinux()) {
|
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 {
|
} 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(
|
fun FrameWindowScope.FileDialogChooserMultiple(
|
||||||
title: String,
|
title: String,
|
||||||
isLoad: Boolean,
|
isLoad: Boolean,
|
||||||
|
filename: String?,
|
||||||
allowMultiple: Boolean,
|
allowMultiple: Boolean,
|
||||||
fileFilter: ((File?) -> Boolean)? = null,
|
fileFilter: ((File?) -> Boolean)? = null,
|
||||||
fileFilterDescription: String? = null,
|
fileFilterDescription: String? = null,
|
||||||
@@ -73,7 +74,11 @@ fun FrameWindowScope.FileDialogChooserMultiple(
|
|||||||
val returned = if (isLoad) {
|
val returned = if (isLoad) {
|
||||||
fileChooser.showOpenDialog(window)
|
fileChooser.showOpenDialog(window)
|
||||||
} else {
|
} else {
|
||||||
fileChooser.fileSelectionMode = JFileChooser.DIRECTORIES_ONLY
|
if (filename != null) {
|
||||||
|
fileChooser.selectedFile = File(filename)
|
||||||
|
} else {
|
||||||
|
fileChooser.fileSelectionMode = JFileChooser.DIRECTORIES_ONLY
|
||||||
|
}
|
||||||
fileChooser.showSaveDialog(window)
|
fileChooser.showSaveDialog(window)
|
||||||
}
|
}
|
||||||
val result = when (returned) {
|
val result = when (returned) {
|
||||||
@@ -109,6 +114,7 @@ fun FrameWindowScope.FileDialogChooserMultiple(
|
|||||||
private fun FrameWindowScope.FileDialogAwt(
|
private fun FrameWindowScope.FileDialogAwt(
|
||||||
title: String,
|
title: String,
|
||||||
isLoad: Boolean,
|
isLoad: Boolean,
|
||||||
|
filename: String?,
|
||||||
allowMultiple: Boolean,
|
allowMultiple: Boolean,
|
||||||
fileFilter: ((File?) -> Boolean)? = null,
|
fileFilter: ((File?) -> Boolean)? = null,
|
||||||
onResult: (result: List<File>) -> Unit
|
onResult: (result: List<File>) -> Unit
|
||||||
@@ -128,6 +134,9 @@ private fun FrameWindowScope.FileDialogAwt(
|
|||||||
}.apply {
|
}.apply {
|
||||||
this.title = title
|
this.title = title
|
||||||
this.isMultipleMode = allowMultiple && isLoad
|
this.isMultipleMode = allowMultiple && isLoad
|
||||||
|
if (!isLoad && filename != null) {
|
||||||
|
this.file = filename
|
||||||
|
}
|
||||||
if (fileFilter != null) {
|
if (fileFilter != null) {
|
||||||
this.setFilenameFilter { dir, file ->
|
this.setFilenameFilter { dir, file ->
|
||||||
fileFilter(File(dir.absolutePath + File.separator + file))
|
fileFilter(File(dir.absolutePath + File.separator + file))
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ fun main() {
|
|||||||
initHaskell()
|
initHaskell()
|
||||||
initApp()
|
initApp()
|
||||||
tmpDir.deleteRecursively()
|
tmpDir.deleteRecursively()
|
||||||
|
tmpDir.mkdir()
|
||||||
return showApp()
|
return showApp()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user