Compare commits

...

4 Commits

Author SHA1 Message Date
Avently bfea71342d mac no alert 2024-12-13 16:31:17 +07:00
Evgeny Poberezkin a2048b6ade Merge branch 'master' into av/desktop-saving-file-with-prompt 2024-12-12 17:48:21 +00:00
Avently 63406bd806 one button 2024-12-10 18:48:37 +07:00
Avently 9b5e650af0 desktop: offer rename or overwrite file on save 2024-12-10 14:09:11 +07:00
2 changed files with 45 additions and 3 deletions
@@ -482,6 +482,9 @@
<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="overwrite_file">Overwrite file</string>
<!-- Voice messages -->
<string name="voice_message">Voice message</string>
@@ -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,42 @@ actual class FileChooserLauncher actual constructor() {
res = File(res, input)
}
}
onResult(res?.toURI())
if (res == null) {
onResult(null)
} else if (desktopPlatform.isMac() || !res.exists()) { // mac has an alert confirmation if the file exists
onResult(res.toURI())
} else {
showSaveRenameFileAlert(res, onResult)
}
}
}
private fun showSaveRenameFileAlert(file: File, onResult: (URI?) -> Unit) {
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(null)
}) {
Text(generalGetString(MR.strings.cancel_verb), Modifier.fillMaxWidth(), textAlign = TextAlign.Center, color = MaterialTheme.colors.primary)
}
}
},
onDismissRequest = {
onResult(null)
}
)
}
actual class FileChooserMultipleLauncher actual constructor() {
lateinit var onResult: (List<URI>) -> Unit