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

View File

@ -97,6 +97,23 @@ class StatusManager @Inject constructor() {
loadStatus(git) 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 { sealed class StageStatus {

View File

@ -72,6 +72,7 @@ fun UncommitedChanges(
.weight(5f) .weight(5f)
.fillMaxWidth(), .fillMaxWidth(),
title = "Staged", title = "Staged",
allActionTitle = "Unstage all",
actionTitle = "Unstage", actionTitle = "Unstage",
actionColor = MaterialTheme.colors.error, actionColor = MaterialTheme.colors.error,
diffEntries = staged, diffEntries = staged,
@ -81,6 +82,9 @@ fun UncommitedChanges(
}, },
onReset = { diffEntry -> onReset = { diffEntry ->
gitManager.resetStaged(diffEntry) gitManager.resetStaged(diffEntry)
},
onAllAction = {
gitManager.unstageAll()
} }
) )
@ -99,7 +103,11 @@ fun UncommitedChanges(
}, },
onReset = { diffEntry -> onReset = { diffEntry ->
gitManager.resetUnstaged(diffEntry) gitManager.resetUnstaged(diffEntry)
} },
{
gitManager.stageAll()
},
allActionTitle = "Stage all"
) )
Card( Card(
@ -143,6 +151,7 @@ fun UncommitedChanges(
} }
} }
@OptIn(ExperimentalAnimationApi::class)
@Composable @Composable
private fun EntriesList( private fun EntriesList(
modifier: Modifier, modifier: Modifier,
@ -153,12 +162,15 @@ private fun EntriesList(
onDiffEntrySelected: (DiffEntry) -> Unit, onDiffEntrySelected: (DiffEntry) -> Unit,
onDiffEntryOptionSelected: (DiffEntry) -> Unit, onDiffEntryOptionSelected: (DiffEntry) -> Unit,
onReset: (DiffEntry) -> Unit, onReset: (DiffEntry) -> Unit,
onAllAction: () -> Unit,
allActionTitle: String,
) { ) {
Card( Card(
modifier = modifier modifier = modifier
) { ) {
Column { Column {
Box {
Text( Text(
modifier = Modifier modifier = Modifier
.background(color = MaterialTheme.colors.headerBackground) .background(color = MaterialTheme.colors.headerBackground)
@ -172,6 +184,19 @@ private fun EntriesList(
maxLines = 1, 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( ScrollableLazyColumn(
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),
) { ) {