Log code cleanup and added more comments
This commit is contained in:
parent
759d30014b
commit
e54ba6d8a0
39
src/main/kotlin/app/ui/context_menu/LogContextMenu.kt
Normal file
39
src/main/kotlin/app/ui/context_menu/LogContextMenu.kt
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package app.ui.context_menu
|
||||||
|
|
||||||
|
import androidx.compose.foundation.ContextMenuItem
|
||||||
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
|
|
||||||
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
|
fun logContextMenu(
|
||||||
|
onCheckoutCommit: () -> Unit,
|
||||||
|
onCreateNewBranch: () -> Unit,
|
||||||
|
onCreateNewTag: () -> Unit,
|
||||||
|
onRevertCommit: () -> Unit,
|
||||||
|
onCherryPickCommit: () -> Unit,
|
||||||
|
onResetBranch: () -> Unit,
|
||||||
|
) = listOf(
|
||||||
|
ContextMenuItem(
|
||||||
|
label = "Checkout commit",
|
||||||
|
onClick = onCheckoutCommit),
|
||||||
|
ContextMenuItem(
|
||||||
|
label = "Create branch",
|
||||||
|
onClick = onCreateNewBranch
|
||||||
|
),
|
||||||
|
ContextMenuItem(
|
||||||
|
label = "Create tag",
|
||||||
|
onClick = onCreateNewTag
|
||||||
|
),
|
||||||
|
ContextMenuItem(
|
||||||
|
label = "Revert commit",
|
||||||
|
onClick = onRevertCommit
|
||||||
|
),
|
||||||
|
ContextMenuItem(
|
||||||
|
label = "Cherry-pick commit",
|
||||||
|
onClick = onCherryPickCommit
|
||||||
|
),
|
||||||
|
|
||||||
|
ContextMenuItem(
|
||||||
|
label = "Reset current branch to this commit",
|
||||||
|
onClick = onResetBranch
|
||||||
|
)
|
||||||
|
)
|
@ -46,6 +46,7 @@ import app.ui.SelectedItem
|
|||||||
import app.ui.components.AvatarImage
|
import app.ui.components.AvatarImage
|
||||||
import app.ui.components.ScrollableLazyColumn
|
import app.ui.components.ScrollableLazyColumn
|
||||||
import app.ui.context_menu.branchContextMenuItems
|
import app.ui.context_menu.branchContextMenuItems
|
||||||
|
import app.ui.context_menu.logContextMenu
|
||||||
import app.ui.context_menu.tagContextMenuItems
|
import app.ui.context_menu.tagContextMenuItems
|
||||||
import app.ui.dialogs.*
|
import app.ui.dialogs.*
|
||||||
import app.viewmodels.LogStatus
|
import app.viewmodels.LogStatus
|
||||||
@ -91,7 +92,9 @@ fun Log(
|
|||||||
val hasUncommitedChanges = logStatus.hasUncommitedChanges
|
val hasUncommitedChanges = logStatus.hasUncommitedChanges
|
||||||
val commitList = logStatus.plotCommitList
|
val commitList = logStatus.plotCommitList
|
||||||
val verticalScrollState = rememberLazyListState()
|
val verticalScrollState = rememberLazyListState()
|
||||||
verticalScrollState.isScrollInProgress
|
|
||||||
|
// With this method, whenever the scroll changes, the log is recomposed and the graph list is updated with
|
||||||
|
// the proper scroll position
|
||||||
verticalScrollState.observeScrollChanges()
|
verticalScrollState.observeScrollChanges()
|
||||||
|
|
||||||
LaunchedEffect(selectedCommit) {
|
LaunchedEffect(selectedCommit) {
|
||||||
@ -139,6 +142,8 @@ fun Log(
|
|||||||
hasUncommitedChanges = hasUncommitedChanges,
|
hasUncommitedChanges = hasUncommitedChanges,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// The commits' messages list overlaps with the graph list to catch all the click events but leaves
|
||||||
|
// a padding, so it doesn't cover the graph
|
||||||
MessagesList(
|
MessagesList(
|
||||||
scrollState = verticalScrollState,
|
scrollState = verticalScrollState,
|
||||||
hasUncommitedChanges = hasUncommitedChanges,
|
hasUncommitedChanges = hasUncommitedChanges,
|
||||||
@ -240,12 +245,7 @@ fun GraphList(
|
|||||||
|
|
||||||
val graphRealWidth = remember(commitList, graphWidth) {
|
val graphRealWidth = remember(commitList, graphWidth) {
|
||||||
val maxLinePosition = commitList.maxOf { it.lane.position }
|
val maxLinePosition = commitList.maxOf { it.lane.position }
|
||||||
val calculatedGraphWidth = ((maxLinePosition + 2) * 30f).dp
|
((maxLinePosition + 2) * 30f).dp
|
||||||
|
|
||||||
if (calculatedGraphWidth < graphWidth)
|
|
||||||
graphWidth
|
|
||||||
else
|
|
||||||
calculatedGraphWidth
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
@ -524,35 +524,15 @@ fun CommitLine(
|
|||||||
onRebaseBranch: (Ref) -> Unit,
|
onRebaseBranch: (Ref) -> Unit,
|
||||||
onRevCommitSelected: (GraphNode) -> Unit,
|
onRevCommitSelected: (GraphNode) -> Unit,
|
||||||
) {
|
) {
|
||||||
val commitRefs = graphNode.refs
|
|
||||||
|
|
||||||
ContextMenuArea(
|
ContextMenuArea(
|
||||||
items = {
|
items = {
|
||||||
listOf(
|
logContextMenu(
|
||||||
ContextMenuItem(
|
onCheckoutCommit = { logViewModel.checkoutCommit(graphNode) },
|
||||||
label = "Checkout commit",
|
onCreateNewBranch = showCreateNewBranch,
|
||||||
onClick = { logViewModel.checkoutCommit(graphNode) }),
|
onCreateNewTag = showCreateNewTag,
|
||||||
ContextMenuItem(
|
onRevertCommit = { logViewModel.revertCommit(graphNode) },
|
||||||
label = "Create branch",
|
onCherryPickCommit = { logViewModel.cherrypickCommit(graphNode) },
|
||||||
onClick = showCreateNewBranch
|
onResetBranch = { resetBranch(graphNode) },
|
||||||
),
|
|
||||||
ContextMenuItem(
|
|
||||||
label = "Create tag",
|
|
||||||
onClick = showCreateNewTag
|
|
||||||
),
|
|
||||||
ContextMenuItem(
|
|
||||||
label = "Revert commit",
|
|
||||||
onClick = { logViewModel.revertCommit(graphNode) }
|
|
||||||
),
|
|
||||||
ContextMenuItem(
|
|
||||||
label = "Cherry-pick commit",
|
|
||||||
onClick = { logViewModel.cherrypickCommit(graphNode) }
|
|
||||||
),
|
|
||||||
|
|
||||||
ContextMenuItem(
|
|
||||||
label = "Reset current branch to this commit",
|
|
||||||
onClick = { resetBranch(graphNode) }
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
@ -572,7 +552,7 @@ fun CommitLine(
|
|||||||
modifier = Modifier.weight(1f),
|
modifier = Modifier.weight(1f),
|
||||||
commit = graphNode,
|
commit = graphNode,
|
||||||
selected = selected,
|
selected = selected,
|
||||||
refs = commitRefs,
|
refs = graphNode.refs,
|
||||||
nodeColor = nodeColor,
|
nodeColor = nodeColor,
|
||||||
currentBranch = currentBranch,
|
currentBranch = currentBranch,
|
||||||
onCheckoutRef = { ref -> logViewModel.checkoutRef(ref) },
|
onCheckoutRef = { ref -> logViewModel.checkoutRef(ref) },
|
||||||
|
Loading…
Reference in New Issue
Block a user