Replaced custom clipboard method by the built-in

This commit is contained in:
Abdelilah El Aissaoui 2022-10-15 19:06:12 +02:00
parent 7203ee162b
commit 578f30b7c9
3 changed files with 5 additions and 13 deletions

View File

@ -65,17 +65,6 @@ private fun openFileJdk(filePath: String) {
} }
} }
fun copyInBrowser(textToCopy: String) {
try {
val selection = StringSelection(textToCopy)
val clipboard: Clipboard = Toolkit.getDefaultToolkit().systemClipboard
clipboard.setContents(selection, selection)
} catch (ex: Exception) {
printLog(TAG, "Failed to copy text")
ex.printStackTrace()
}
}
enum class OS { enum class OS {
LINUX, LINUX,
WINDOWS, WINDOWS,

View File

@ -8,6 +8,8 @@ import androidx.compose.material.*
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
@ -138,6 +140,7 @@ fun Author(
) { ) {
var copied by remember(id) { mutableStateOf(false) } var copied by remember(id) { mutableStateOf(false) }
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
val clipboard = LocalClipboardManager.current
Row( Row(
modifier = Modifier modifier = Modifier
@ -173,7 +176,7 @@ fun Author(
style = MaterialTheme.typography.body2, style = MaterialTheme.typography.body2,
modifier = Modifier.handMouseClickable { modifier = Modifier.handMouseClickable {
scope.launch { scope.launch {
copyInBrowser(id.name) clipboard.setText(AnnotatedString(id.name))
copied = true copied = true
delay(2000) // 2s delay(2000) // 2s
copied = false copied = false

View File

@ -33,7 +33,7 @@ private const val TAG = "TabViewModel"
/** /**
* Contains all the information related to a tab and its subcomponents (smaller composables like the log, branches, * Contains all the information related to a tab and its subcomponents (smaller composables like the log, branches,
* commit changes, etc.). It holds a reference to every view model because this class lives as long as the tab is open (survives * commit changes, etc.). It holds a reference to every view model because this class lives as long as the tab is open (survives
* across full com.jetpackduba.gitnuro.app recompositions), therefore, tab's content can be recreated with these view models. * across full app recompositions), therefore, tab's content can be recreated with these view models.
*/ */
class TabViewModel @Inject constructor( class TabViewModel @Inject constructor(
val logViewModel: LogViewModel, val logViewModel: LogViewModel,