Added option to copy git ID to clipboard
This commit is contained in:
parent
fe77505e7d
commit
57e8482218
@ -1,9 +1,15 @@
|
||||
package app.extensions
|
||||
|
||||
import app.logging.printLog
|
||||
import java.awt.Desktop
|
||||
import java.awt.Toolkit
|
||||
import java.awt.datatransfer.Clipboard
|
||||
import java.awt.datatransfer.StringSelection
|
||||
import java.net.URI
|
||||
import java.nio.file.FileSystems
|
||||
|
||||
private const val TAG = "SystemUtils"
|
||||
|
||||
val systemSeparator: String by lazy {
|
||||
FileSystems.getDefault().separator
|
||||
}
|
||||
@ -15,4 +21,15 @@ fun openUrlInBrowser(url: String) {
|
||||
println("Failed to open URL in browser")
|
||||
ex.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
@ -22,6 +22,9 @@ import app.ui.components.TooltipText
|
||||
import app.ui.context_menu.commitedChangesEntriesContextMenuItems
|
||||
import app.viewmodels.CommitChangesStatus
|
||||
import app.viewmodels.CommitChangesViewModel
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import org.eclipse.jgit.diff.DiffEntry
|
||||
import org.eclipse.jgit.lib.ObjectId
|
||||
import org.eclipse.jgit.lib.PersonIdent
|
||||
@ -134,6 +137,9 @@ fun Author(
|
||||
id: ObjectId,
|
||||
author: PersonIdent,
|
||||
) {
|
||||
var copied by remember(id) { mutableStateOf(false) }
|
||||
val scope = rememberCoroutineScope()
|
||||
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@ -160,14 +166,32 @@ fun Author(
|
||||
tooltipTitle = author.emailAddress,
|
||||
)
|
||||
|
||||
Row {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(
|
||||
text = id.abbreviate(7).name(),
|
||||
color = MaterialTheme.colors.secondaryTextColor,
|
||||
maxLines = 1,
|
||||
style = MaterialTheme.typography.body2,
|
||||
modifier = Modifier.handMouseClickable {
|
||||
scope.launch {
|
||||
copyInBrowser(id.name)
|
||||
copied = true
|
||||
delay(2000) // 2s
|
||||
copied = false
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
if (copied) {
|
||||
Text(
|
||||
text = "Copied!",
|
||||
color = MaterialTheme.colors.primaryVariant,
|
||||
maxLines = 1,
|
||||
style = MaterialTheme.typography.caption,
|
||||
modifier = Modifier.padding(start = 4.dp),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Spacer(modifier = Modifier.weight(1f, fill = true))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user