mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-04-26 19:35:48 +00:00
desktop: offer rename or overwrite file on save
This commit is contained in:
@@ -482,6 +482,10 @@
|
||||
<string name="loading_remote_file_desc">Please, wait while the file is being loaded from the linked mobile</string>
|
||||
<string name="file_error">File error</string>
|
||||
<string name="temporary_file_error">Temporary file error</string>
|
||||
<string name="file_already_exists">File already exists</string>
|
||||
<string name="what_would_you_like_to_do_with_file">What would you like to do?</string>
|
||||
<string name="save_file_as">Save as %s</string>
|
||||
<string name="overwrite_file">Overwrite file</string>
|
||||
|
||||
<!-- Voice messages -->
|
||||
<string name="voice_message">Voice message</string>
|
||||
|
||||
+43
-3
@@ -1,9 +1,16 @@
|
||||
package chat.simplex.common.platform
|
||||
|
||||
import SectionItemView
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.material.MaterialTheme
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import chat.simplex.common.*
|
||||
import chat.simplex.common.views.helpers.AlertManager
|
||||
import chat.simplex.common.views.helpers.generalGetString
|
||||
import chat.simplex.common.views.chatlist.acceptContactRequest
|
||||
import chat.simplex.common.views.helpers.*
|
||||
import chat.simplex.res.MR
|
||||
import java.awt.Desktop
|
||||
import java.io.*
|
||||
@@ -75,10 +82,43 @@ actual class FileChooserLauncher actual constructor() {
|
||||
res = File(res, input)
|
||||
}
|
||||
}
|
||||
onResult(res?.toURI())
|
||||
if (res == null) {
|
||||
onResult(null)
|
||||
} else if (!res.exists()) {
|
||||
onResult(res.toURI())
|
||||
} else {
|
||||
showSaveRenameFileAlert(res, onResult)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun showSaveRenameFileAlert(file: File, onResult: (URI?) -> Unit) {
|
||||
val newFileName = uniqueCombine(file.name, file.parentFile.absoluteFile)
|
||||
AlertManager.shared.showAlertDialogButtonsColumn(
|
||||
title = generalGetString(MR.strings.file_already_exists),
|
||||
text = generalGetString(MR.strings.what_would_you_like_to_do_with_file),
|
||||
buttons = {
|
||||
Column {
|
||||
SectionItemView({
|
||||
AlertManager.shared.hideAlert()
|
||||
onResult(file.toURI())
|
||||
}) {
|
||||
Text(generalGetString(MR.strings.overwrite_file), Modifier.fillMaxWidth(), textAlign = TextAlign.Center, color = MaterialTheme.colors.error)
|
||||
}
|
||||
SectionItemView({
|
||||
AlertManager.shared.hideAlert()
|
||||
onResult(File(file.parentFile, newFileName).toURI())
|
||||
}) {
|
||||
Text(generalGetString(MR.strings.save_file_as).format(newFileName), Modifier.fillMaxWidth(), textAlign = TextAlign.Center, color = MaterialTheme.colors.primary)
|
||||
}
|
||||
}
|
||||
},
|
||||
onDismissRequest = {
|
||||
onResult(null)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
actual class FileChooserMultipleLauncher actual constructor() {
|
||||
lateinit var onResult: (List<URI>) -> Unit
|
||||
|
||||
|
||||
Reference in New Issue
Block a user