Added un/stage all buttons

This commit is contained in:
Abdelilah El Aissaoui 2021-10-10 02:59:26 +02:00
parent 6d0f621bcd
commit ee745bd4e0
3 changed files with 67 additions and 15 deletions

View File

@ -86,6 +86,8 @@ class GitManager @Inject constructor(
}
fun openRepository(directory: File) {
println("Trying to open repository ${directory.absoluteFile}")
val gitDirectory = if (directory.name == ".git") {
directory
} else {
@ -199,6 +201,14 @@ class GitManager @Inject constructor(
suspend fun diffListFromCommit(commit: RevCommit): List<DiffEntry> {
return diffManager.commitDiffEntries(safeGit, commit)
}
fun unstageAll() = managerScope.launch {
statusManager.unstageAll(safeGit)
}
fun stageAll() = managerScope.launch {
statusManager.stageAll(safeGit)
}
}

View File

@ -53,7 +53,7 @@ class StatusManager @Inject constructor() {
}
suspend fun stage(git: Git, diffEntry: DiffEntry) = withContext(Dispatchers.IO) {
if(diffEntry.changeType == DiffEntry.ChangeType.DELETE) {
if (diffEntry.changeType == DiffEntry.ChangeType.DELETE) {
git.rm()
.addFilepattern(diffEntry.filePath)
.call()
@ -83,7 +83,7 @@ class StatusManager @Inject constructor() {
}
suspend fun reset(git: Git, diffEntry: DiffEntry, staged: Boolean) = withContext(Dispatchers.IO) {
if(staged) {
if (staged) {
git
.reset()
.addPath(diffEntry.filePath)
@ -97,6 +97,23 @@ class StatusManager @Inject constructor() {
loadStatus(git)
}
suspend fun unstageAll(git: Git) = withContext(Dispatchers.IO) {
git
.reset()
.call()
loadStatus(git)
}
suspend fun stageAll(git: Git) = withContext(Dispatchers.IO) {
git
.add()
.addFilepattern(".")
.call()
loadStatus(git)
}
}
sealed class StageStatus {

View File

@ -72,6 +72,7 @@ fun UncommitedChanges(
.weight(5f)
.fillMaxWidth(),
title = "Staged",
allActionTitle = "Unstage all",
actionTitle = "Unstage",
actionColor = MaterialTheme.colors.error,
diffEntries = staged,
@ -81,6 +82,9 @@ fun UncommitedChanges(
},
onReset = { diffEntry ->
gitManager.resetStaged(diffEntry)
},
onAllAction = {
gitManager.unstageAll()
}
)
@ -99,7 +103,11 @@ fun UncommitedChanges(
},
onReset = { diffEntry ->
gitManager.resetUnstaged(diffEntry)
}
},
{
gitManager.stageAll()
},
allActionTitle = "Stage all"
)
Card(
@ -143,6 +151,7 @@ fun UncommitedChanges(
}
}
@OptIn(ExperimentalAnimationApi::class)
@Composable
private fun EntriesList(
modifier: Modifier,
@ -153,24 +162,40 @@ private fun EntriesList(
onDiffEntrySelected: (DiffEntry) -> Unit,
onDiffEntryOptionSelected: (DiffEntry) -> Unit,
onReset: (DiffEntry) -> Unit,
onAllAction: () -> Unit,
allActionTitle: String,
) {
Card(
modifier = modifier
) {
Column {
Text(
modifier = Modifier
.background(color = MaterialTheme.colors.headerBackground)
.padding(vertical = 8.dp)
.fillMaxWidth(),
text = title,
fontWeight = FontWeight.Bold,
textAlign = TextAlign.Center,
color = MaterialTheme.colors.primary,
fontSize = 14.sp,
maxLines = 1,
)
Box {
Text(
modifier = Modifier
.background(color = MaterialTheme.colors.headerBackground)
.padding(vertical = 8.dp)
.fillMaxWidth(),
text = title,
fontWeight = FontWeight.Bold,
textAlign = TextAlign.Center,
color = MaterialTheme.colors.primary,
fontSize = 14.sp,
maxLines = 1,
)
Button(
onClick = onAllAction,
modifier = Modifier
.padding(horizontal = 16.dp)
.align(Alignment.CenterEnd),
elevation = ButtonDefaults.elevation(0.dp, 0.dp, 0.dp),
colors = ButtonDefaults.buttonColors(backgroundColor = actionColor)
) {
Text(allActionTitle, fontSize = 10.sp)
}
}
ScrollableLazyColumn(
modifier = Modifier.fillMaxSize(),