Added branch current branch identifier to log & branch sorting

This commit is contained in:
Abdelilah El Aissaoui 2021-12-06 23:52:51 +01:00
parent efab5b0bfa
commit 6d190614e5
3 changed files with 57 additions and 20 deletions

View File

@ -24,3 +24,11 @@ val Ref.isLocal: Boolean
val Ref.isRemote: Boolean val Ref.isRemote: Boolean
get() = this.name.startsWith("refs/remotes/") get() = this.name.startsWith("refs/remotes/")
fun Ref.isSameBranch(otherRef: Ref?): Boolean {
if(otherRef == null)
return false
return this.name == otherRef.name
}

View File

@ -48,7 +48,6 @@ fun Branches(gitManager: GitManager) {
branch = branch, branch = branch,
isCurrentBranch = currentBranch == branch.name isCurrentBranch = currentBranch == branch.name
) )
} }
} }
} }

View File

@ -134,6 +134,7 @@ fun Log(
selected = selectedIndex.value == index, selected = selectedIndex.value == index,
weightMod = weightMod, weightMod = weightMod,
graphWidth = graphWidth, graphWidth = graphWidth,
currentBranch = logStatus.currentBranch,
showCreateNewBranch = { showLogDialog.value = LogDialog.NewBranch(graphNode) }, showCreateNewBranch = { showLogDialog.value = LogDialog.NewBranch(graphNode) },
showCreateNewTag = { showLogDialog.value = LogDialog.NewTag(graphNode) }, showCreateNewTag = { showLogDialog.value = LogDialog.NewTag(graphNode) },
resetBranch = { showLogDialog.value = LogDialog.ResetBranch(graphNode) }, resetBranch = { showLogDialog.value = LogDialog.ResetBranch(graphNode) },
@ -305,6 +306,7 @@ fun CommitLine(
selected: Boolean, selected: Boolean,
weightMod: MutableState<Float>, weightMod: MutableState<Float>,
graphWidth: Dp, graphWidth: Dp,
currentBranch: Ref?,
showCreateNewBranch: () -> Unit, showCreateNewBranch: () -> Unit,
showCreateNewTag: () -> Unit, showCreateNewTag: () -> Unit,
resetBranch: (GraphNode) -> Unit, resetBranch: (GraphNode) -> Unit,
@ -373,6 +375,7 @@ fun CommitLine(
commit = graphNode, commit = graphNode,
selected = selected, selected = selected,
refs = commitRefs, refs = commitRefs,
currentBranch = currentBranch,
onCheckoutRef = { ref -> gitManager.checkoutRef(ref) }, onCheckoutRef = { ref -> gitManager.checkoutRef(ref) },
onMergeBranch = { ref -> onMergeBranch(ref) }, onMergeBranch = { ref -> onMergeBranch(ref) },
onDeleteBranch = { ref -> gitManager.deleteBranch(ref) }, onDeleteBranch = { ref -> gitManager.deleteBranch(ref) },
@ -389,6 +392,7 @@ fun CommitMessage(
commit: RevCommit, commit: RevCommit,
selected: Boolean, selected: Boolean,
refs: List<Ref>, refs: List<Ref>,
currentBranch: Ref?,
onCheckoutRef: (ref: Ref) -> Unit, onCheckoutRef: (ref: Ref) -> Unit,
onMergeBranch: (ref: Ref) -> Unit, onMergeBranch: (ref: Ref) -> Unit,
onDeleteBranch: (ref: Ref) -> Unit, onDeleteBranch: (ref: Ref) -> Unit,
@ -413,20 +417,30 @@ fun CommitMessage(
.fillMaxSize(), .fillMaxSize(),
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
) { ) {
refs.forEach { ref -> refs
if (ref.isTag) { .sortedWith { ref1, ref2 ->
TagChip( if (ref1.isSameBranch(currentBranch)) {
ref = ref, -1
onCheckoutTag = { onCheckoutRef(ref) }, } else {
onDeleteTag = { onDeleteTag(ref) }, ref1.name.compareTo(ref2.name)
) }
} else if (ref.isBranch) }
BranchChip( .forEach { ref ->
ref = ref, if (ref.isTag) {
onCheckoutBranch = { onCheckoutRef(ref) }, TagChip(
onMergeBranch = { onMergeBranch(ref) }, ref = ref,
onDeleteBranch = { onDeleteBranch(ref) } onCheckoutTag = { onCheckoutRef(ref) },
) onDeleteTag = { onDeleteTag(ref) },
)
} else if (ref.isBranch) {
BranchChip(
ref = ref,
isCurrentBranch = ref.isSameBranch(currentBranch),
onCheckoutBranch = { onCheckoutRef(ref) },
onMergeBranch = { onMergeBranch(ref) },
onDeleteBranch = { onDeleteBranch(ref) }
)
}
} }
Text( Text(
@ -631,12 +645,25 @@ fun BranchChip(
} }
} }
var endingContent: @Composable () -> Unit = {}
if(isCurrentBranch) {
endingContent = {
Icon(
painter = painterResource("location.svg"),
contentDescription = null,
modifier = Modifier.padding(end = 6.dp),
tint = MaterialTheme.colors.background,
)
}
}
RefChip( RefChip(
modifier, modifier = modifier,
ref, ref = ref,
"branch.svg", icon = "branch.svg",
onCheckoutRef = onCheckoutBranch, onCheckoutRef = onCheckoutBranch,
contextMenuItemsList = contextMenuItemsList contextMenuItemsList = contextMenuItemsList,
endingContent = endingContent,
) )
} }
@ -683,6 +710,7 @@ fun RefChip(
icon: String, icon: String,
onCheckoutRef: () -> Unit, onCheckoutRef: () -> Unit,
contextMenuItemsList: () -> List<ContextMenuItem>, contextMenuItemsList: () -> List<ContextMenuItem>,
endingContent: @Composable () -> Unit = {},
) { ) {
Box( Box(
modifier = Modifier modifier = Modifier
@ -716,6 +744,8 @@ fun RefChip(
modifier = Modifier modifier = Modifier
.padding(end = 6.dp) .padding(end = 6.dp)
) )
endingContent()
} }
} }
} }