diff --git a/src/main/kotlin/app/extensions/SystemUtils.kt b/src/main/kotlin/app/extensions/SystemUtils.kt index d6f1e7c..ee74721 100644 --- a/src/main/kotlin/app/extensions/SystemUtils.kt +++ b/src/main/kotlin/app/extensions/SystemUtils.kt @@ -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() + } } \ No newline at end of file diff --git a/src/main/kotlin/app/ui/CommitChanges.kt b/src/main/kotlin/app/ui/CommitChanges.kt index 83b99b4..9316e5e 100644 --- a/src/main/kotlin/app/ui/CommitChanges.kt +++ b/src/main/kotlin/app/ui/CommitChanges.kt @@ -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))