Clicking on a ref now selects the log's commit
This commit is contained in:
parent
2d32b77a69
commit
912397b257
@ -15,6 +15,7 @@ import app.AppStateManager
|
||||
import app.app.ErrorsManager
|
||||
import app.app.newErrorNow
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import org.eclipse.jgit.lib.ObjectId
|
||||
import org.eclipse.jgit.transport.RemoteConfig
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
@ -350,6 +351,10 @@ class GitManager @Inject constructor(
|
||||
fun clone(directory: File, url: String) = managerScope.launch {
|
||||
remoteOperationsManager.clone(directory, url)
|
||||
}
|
||||
|
||||
fun findCommit(objectId: ObjectId): RevCommit {
|
||||
return safeGit.repository.parseCommit(objectId)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -33,7 +33,11 @@ import app.ui.context_menu.branchContextMenuItems
|
||||
import app.ui.dialogs.MergeDialog
|
||||
|
||||
@Composable
|
||||
fun Branches(gitManager: GitManager) {
|
||||
fun Branches(
|
||||
gitManager: GitManager,
|
||||
onBranchClicked: (Ref) -> Unit,
|
||||
|
||||
) {
|
||||
val branches by gitManager.branches.collectAsState()
|
||||
val currentBranch by gitManager.currentBranch.collectAsState()
|
||||
val (mergeBranch, setMergeBranch) = remember { mutableStateOf<Ref?>(null) }
|
||||
@ -53,6 +57,7 @@ fun Branches(gitManager: GitManager) {
|
||||
BranchRow(
|
||||
branch = branch,
|
||||
isCurrentBranch = currentBranch == branch.name,
|
||||
onBranchClicked = { onBranchClicked(branch) },
|
||||
onCheckoutBranch = { gitManager.checkoutRef(branch) },
|
||||
onMergeBranch = { setMergeBranch(branch) },
|
||||
onDeleteBranch = { gitManager.deleteBranch(branch) },
|
||||
@ -77,6 +82,7 @@ fun Branches(gitManager: GitManager) {
|
||||
private fun BranchRow(
|
||||
branch: Ref,
|
||||
isCurrentBranch: Boolean,
|
||||
onBranchClicked: () -> Unit,
|
||||
onCheckoutBranch: () -> Unit,
|
||||
onMergeBranch: () -> Unit,
|
||||
onDeleteBranch: () -> Unit,
|
||||
@ -96,6 +102,7 @@ private fun BranchRow(
|
||||
text = branch.simpleName,
|
||||
iconResourcePath = "branch.svg",
|
||||
bold = isCurrentBranch,
|
||||
onClick = onBranchClicked
|
||||
) {
|
||||
if (isCurrentBranch) {
|
||||
Icon(
|
||||
|
@ -71,9 +71,21 @@ fun RepositoryOpenPage(gitManager: GitManager) {
|
||||
.weight(0.15f)
|
||||
.fillMaxHeight()
|
||||
) {
|
||||
Branches(gitManager = gitManager)
|
||||
Branches(
|
||||
gitManager = gitManager,
|
||||
onBranchClicked = {
|
||||
val commit = gitManager.findCommit(it.objectId)
|
||||
setSelectedItem(SelectedItem.Ref(commit))
|
||||
}
|
||||
)
|
||||
Remotes(gitManager = gitManager)
|
||||
Tags(gitManager = gitManager)
|
||||
Tags(
|
||||
gitManager = gitManager,
|
||||
onTagClicked = {
|
||||
val commit = gitManager.findCommit(it.objectId)
|
||||
setSelectedItem(SelectedItem.Ref(commit))
|
||||
}
|
||||
)
|
||||
Stashes(
|
||||
gitManager = gitManager,
|
||||
onStashSelected = { stash ->
|
||||
@ -154,6 +166,7 @@ sealed class SelectedItem {
|
||||
object None : SelectedItem()
|
||||
object UncommitedChanges : SelectedItem()
|
||||
sealed class CommitBasedItem(val revCommit: RevCommit) : SelectedItem()
|
||||
class Ref(revCommit: RevCommit) : CommitBasedItem(revCommit)
|
||||
class Commit(revCommit: RevCommit) : CommitBasedItem(revCommit)
|
||||
class Stash(revCommit: RevCommit) : CommitBasedItem(revCommit)
|
||||
}
|
@ -19,7 +19,10 @@ import app.ui.context_menu.tagContextMenuItems
|
||||
import org.eclipse.jgit.lib.Ref
|
||||
|
||||
@Composable
|
||||
fun Tags(gitManager: GitManager) {
|
||||
fun Tags(
|
||||
gitManager: GitManager,
|
||||
onTagClicked: (Ref) -> Unit,
|
||||
) {
|
||||
val tagsState = gitManager.tags.collectAsState()
|
||||
val tags = tagsState.value
|
||||
|
||||
@ -39,6 +42,7 @@ fun Tags(gitManager: GitManager) {
|
||||
items(items = tags) { tag ->
|
||||
TagRow(
|
||||
tag = tag,
|
||||
onTagClicked = { onTagClicked(tag) },
|
||||
onCheckoutTag = { gitManager.checkoutRef(tag) },
|
||||
onDeleteTag = { gitManager.deleteTag(tag) }
|
||||
)
|
||||
@ -53,6 +57,7 @@ fun Tags(gitManager: GitManager) {
|
||||
@Composable
|
||||
private fun TagRow(
|
||||
tag: Ref,
|
||||
onTagClicked: () -> Unit,
|
||||
onCheckoutTag: () -> Unit,
|
||||
onDeleteTag: () -> Unit,
|
||||
) {
|
||||
@ -67,6 +72,7 @@ private fun TagRow(
|
||||
SideMenuSubentry(
|
||||
text = tag.simpleName,
|
||||
iconResourcePath = "tag.svg",
|
||||
onClick = onTagClicked,
|
||||
)
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.LazyListScope
|
||||
import androidx.compose.foundation.lazy.LazyListState
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.foundation.rememberScrollbarAdapter
|
||||
import androidx.compose.runtime.Composable
|
||||
@ -14,10 +15,9 @@ import androidx.compose.ui.Modifier
|
||||
@Composable
|
||||
fun ScrollableLazyColumn(
|
||||
modifier: Modifier,
|
||||
state: LazyListState = rememberLazyListState(),
|
||||
content: LazyListScope.() -> Unit
|
||||
) {
|
||||
val state = rememberLazyListState()
|
||||
|
||||
Box(
|
||||
modifier = modifier,
|
||||
) {
|
||||
|
@ -10,6 +10,7 @@ import androidx.compose.foundation.gestures.draggable
|
||||
import androidx.compose.foundation.gestures.rememberDraggableState
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.Icon
|
||||
@ -77,14 +78,21 @@ fun Log(
|
||||
|
||||
val showLogDialog = remember { mutableStateOf<LogDialog>(LogDialog.None) }
|
||||
|
||||
val selectedCommit = if (selectedItem is SelectedItem.Commit) {
|
||||
val selectedCommit = if (selectedItem is SelectedItem.CommitBasedItem) {
|
||||
selectedItem.revCommit
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
|
||||
if (logStatus is LogStatus.Loaded) {
|
||||
val commitList = logStatus.plotCommitList
|
||||
val scrollState = rememberLazyListState()
|
||||
|
||||
LaunchedEffect(selectedCommit) {
|
||||
if(selectedItem is SelectedItem.Ref)
|
||||
scrollState.scrollToItem(commitList.indexOfFirst { it.name == selectedCommit?.name })
|
||||
}
|
||||
|
||||
LogDialogs(
|
||||
gitManager,
|
||||
@ -111,6 +119,7 @@ fun Log(
|
||||
weightMod = weightMod,
|
||||
)
|
||||
ScrollableLazyColumn(
|
||||
state = scrollState,
|
||||
modifier = Modifier
|
||||
.background(MaterialTheme.colors.background)
|
||||
.fillMaxSize(),
|
||||
|
Loading…
Reference in New Issue
Block a user