Hidden rebase interactive on the last commit of the current branch
Fixes #64
This commit is contained in:
parent
4388ccb690
commit
3de2c6bd55
@ -1,5 +1,7 @@
|
|||||||
package com.jetpackduba.gitnuro.ui.context_menu
|
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 androidx.compose.ui.res.painterResource
|
||||||
import com.jetpackduba.gitnuro.AppIcons
|
import com.jetpackduba.gitnuro.AppIcons
|
||||||
|
|
||||||
@ -11,39 +13,59 @@ fun logContextMenu(
|
|||||||
onCherryPickCommit: () -> Unit,
|
onCherryPickCommit: () -> Unit,
|
||||||
onResetBranch: () -> Unit,
|
onResetBranch: () -> Unit,
|
||||||
onRebaseInteractive: () -> Unit,
|
onRebaseInteractive: () -> Unit,
|
||||||
) = listOf(
|
isLastCommit: Boolean,
|
||||||
ContextMenuElement.ContextTextEntry(
|
) = mutableListOf<ContextMenuElement>().apply {
|
||||||
|
addContextMenu(
|
||||||
label = "Checkout commit",
|
label = "Checkout commit",
|
||||||
icon = { painterResource(AppIcons.START) },
|
icon = { painterResource(AppIcons.START) },
|
||||||
onClick = onCheckoutCommit
|
onClick = onCheckoutCommit
|
||||||
),
|
)
|
||||||
ContextMenuElement.ContextTextEntry(
|
addContextMenu(
|
||||||
label = "Create branch",
|
label = "Create branch",
|
||||||
icon = { painterResource(AppIcons.BRANCH) },
|
icon = { painterResource(AppIcons.BRANCH) },
|
||||||
onClick = onCreateNewBranch
|
onClick = onCreateNewBranch
|
||||||
),
|
)
|
||||||
ContextMenuElement.ContextTextEntry(
|
addContextMenu(
|
||||||
label = "Create tag",
|
label = "Create tag",
|
||||||
icon = { painterResource(AppIcons.TAG) },
|
icon = { painterResource(AppIcons.TAG) },
|
||||||
onClick = onCreateNewTag
|
onClick = onCreateNewTag
|
||||||
),
|
)
|
||||||
ContextMenuElement.ContextSeparator,
|
|
||||||
ContextMenuElement.ContextTextEntry(
|
add(ContextMenuElement.ContextSeparator)
|
||||||
label = "Rebase interactive",
|
|
||||||
onClick = onRebaseInteractive
|
if (!isLastCommit) {
|
||||||
),
|
addContextMenu(
|
||||||
ContextMenuElement.ContextTextEntry(
|
label = "Rebase interactive",
|
||||||
|
onClick = onRebaseInteractive
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
addContextMenu(
|
||||||
label = "Revert commit",
|
label = "Revert commit",
|
||||||
icon = { painterResource(AppIcons.REVERT) },
|
icon = { painterResource(AppIcons.REVERT) },
|
||||||
onClick = onRevertCommit
|
onClick = onRevertCommit
|
||||||
),
|
)
|
||||||
ContextMenuElement.ContextTextEntry(
|
addContextMenu(
|
||||||
label = "Cherry-pick commit",
|
label = "Cherry-pick commit",
|
||||||
onClick = onCherryPickCommit
|
onClick = onCherryPickCommit
|
||||||
),
|
)
|
||||||
ContextMenuElement.ContextTextEntry(
|
addContextMenu(
|
||||||
label = "Reset current branch to this commit",
|
label = "Reset current branch to this commit",
|
||||||
icon = { painterResource(AppIcons.UNDO) },
|
icon = { painterResource(AppIcons.UNDO) },
|
||||||
onClick = onResetBranch
|
onClick = onResetBranch
|
||||||
),
|
)
|
||||||
)
|
}
|
||||||
|
|
||||||
|
fun MutableList<ContextMenuElement>.addContextMenu(
|
||||||
|
label: String,
|
||||||
|
icon: @Composable (() -> Painter)? = null,
|
||||||
|
onClick: () -> Unit = {}
|
||||||
|
) {
|
||||||
|
this.add(
|
||||||
|
ContextMenuElement.ContextTextEntry(
|
||||||
|
label,
|
||||||
|
icon,
|
||||||
|
onClick,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
@ -41,6 +41,7 @@ import com.jetpackduba.gitnuro.AppIcons
|
|||||||
import com.jetpackduba.gitnuro.extensions.*
|
import com.jetpackduba.gitnuro.extensions.*
|
||||||
import com.jetpackduba.gitnuro.git.graph.GraphCommitList
|
import com.jetpackduba.gitnuro.git.graph.GraphCommitList
|
||||||
import com.jetpackduba.gitnuro.git.graph.GraphNode
|
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.git.workspace.StatusSummary
|
||||||
import com.jetpackduba.gitnuro.keybindings.KeybindingOption
|
import com.jetpackduba.gitnuro.keybindings.KeybindingOption
|
||||||
import com.jetpackduba.gitnuro.keybindings.matchesBinding
|
import com.jetpackduba.gitnuro.keybindings.matchesBinding
|
||||||
@ -773,6 +774,8 @@ fun CommitLine(
|
|||||||
onRevCommitSelected: () -> Unit,
|
onRevCommitSelected: () -> Unit,
|
||||||
onRebaseInteractive: () -> Unit,
|
onRebaseInteractive: () -> Unit,
|
||||||
) {
|
) {
|
||||||
|
val isLastCommitOfCurrentBranch = currentBranch?.objectId?.name == graphNode.id.name
|
||||||
|
|
||||||
ContextMenu(
|
ContextMenu(
|
||||||
items = {
|
items = {
|
||||||
logContextMenu(
|
logContextMenu(
|
||||||
@ -783,6 +786,7 @@ fun CommitLine(
|
|||||||
onCherryPickCommit = { logViewModel.cherrypickCommit(graphNode) },
|
onCherryPickCommit = { logViewModel.cherrypickCommit(graphNode) },
|
||||||
onRebaseInteractive = onRebaseInteractive,
|
onRebaseInteractive = onRebaseInteractive,
|
||||||
onResetBranch = { resetBranch() },
|
onResetBranch = { resetBranch() },
|
||||||
|
isLastCommit = isLastCommitOfCurrentBranch
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
|
Loading…
Reference in New Issue
Block a user