Hidden rebase interactive on the last commit of the current branch

Fixes #64
This commit is contained in:
Abdelilah El Aissaoui 2023-03-14 10:53:38 +01:00
parent 4388ccb690
commit 3de2c6bd55
No known key found for this signature in database
GPG Key ID: 7587FC860F594869
2 changed files with 45 additions and 19 deletions

View File

@ -1,5 +1,7 @@
package com.jetpackduba.gitnuro.ui.context_menu
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.res.painterResource
import com.jetpackduba.gitnuro.AppIcons
@ -11,39 +13,59 @@ fun logContextMenu(
onCherryPickCommit: () -> Unit,
onResetBranch: () -> Unit,
onRebaseInteractive: () -> Unit,
) = listOf(
ContextMenuElement.ContextTextEntry(
isLastCommit: Boolean,
) = mutableListOf<ContextMenuElement>().apply {
addContextMenu(
label = "Checkout commit",
icon = { painterResource(AppIcons.START) },
onClick = onCheckoutCommit
),
ContextMenuElement.ContextTextEntry(
)
addContextMenu(
label = "Create branch",
icon = { painterResource(AppIcons.BRANCH) },
onClick = onCreateNewBranch
),
ContextMenuElement.ContextTextEntry(
)
addContextMenu(
label = "Create tag",
icon = { painterResource(AppIcons.TAG) },
onClick = onCreateNewTag
),
ContextMenuElement.ContextSeparator,
ContextMenuElement.ContextTextEntry(
label = "Rebase interactive",
onClick = onRebaseInteractive
),
ContextMenuElement.ContextTextEntry(
)
add(ContextMenuElement.ContextSeparator)
if (!isLastCommit) {
addContextMenu(
label = "Rebase interactive",
onClick = onRebaseInteractive
)
}
addContextMenu(
label = "Revert commit",
icon = { painterResource(AppIcons.REVERT) },
onClick = onRevertCommit
),
ContextMenuElement.ContextTextEntry(
)
addContextMenu(
label = "Cherry-pick commit",
onClick = onCherryPickCommit
),
ContextMenuElement.ContextTextEntry(
)
addContextMenu(
label = "Reset current branch to this commit",
icon = { painterResource(AppIcons.UNDO) },
onClick = onResetBranch
),
)
)
}
fun MutableList<ContextMenuElement>.addContextMenu(
label: String,
icon: @Composable (() -> Painter)? = null,
onClick: () -> Unit = {}
) {
this.add(
ContextMenuElement.ContextTextEntry(
label,
icon,
onClick,
)
)
}

View File

@ -41,6 +41,7 @@ import com.jetpackduba.gitnuro.AppIcons
import com.jetpackduba.gitnuro.extensions.*
import com.jetpackduba.gitnuro.git.graph.GraphCommitList
import com.jetpackduba.gitnuro.git.graph.GraphNode
import com.jetpackduba.gitnuro.git.graph.UncommitedChangesGraphNode
import com.jetpackduba.gitnuro.git.workspace.StatusSummary
import com.jetpackduba.gitnuro.keybindings.KeybindingOption
import com.jetpackduba.gitnuro.keybindings.matchesBinding
@ -773,6 +774,8 @@ fun CommitLine(
onRevCommitSelected: () -> Unit,
onRebaseInteractive: () -> Unit,
) {
val isLastCommitOfCurrentBranch = currentBranch?.objectId?.name == graphNode.id.name
ContextMenu(
items = {
logContextMenu(
@ -783,6 +786,7 @@ fun CommitLine(
onCherryPickCommit = { logViewModel.cherrypickCommit(graphNode) },
onRebaseInteractive = onRebaseInteractive,
onResetBranch = { resetBranch() },
isLastCommit = isLastCommitOfCurrentBranch
)
},
) {