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

@ -53,7 +53,7 @@ class StatusManager @Inject constructor() {
} }
suspend fun stage(git: Git, diffEntry: DiffEntry) = withContext(Dispatchers.IO) { suspend fun stage(git: Git, diffEntry: DiffEntry) = withContext(Dispatchers.IO) {
if(diffEntry.changeType == DiffEntry.ChangeType.DELETE) { if (diffEntry.changeType == DiffEntry.ChangeType.DELETE) {
git.rm() git.rm()
.addFilepattern(diffEntry.filePath) .addFilepattern(diffEntry.filePath)
.call() .call()
@ -83,7 +83,7 @@ class StatusManager @Inject constructor() {
} }
suspend fun reset(git: Git, diffEntry: DiffEntry, staged: Boolean) = withContext(Dispatchers.IO) { suspend fun reset(git: Git, diffEntry: DiffEntry, staged: Boolean) = withContext(Dispatchers.IO) {
if(staged) { if (staged) {
git git
.reset() .reset()
.addPath(diffEntry.filePath) .addPath(diffEntry.filePath)
@ -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,24 +162,40 @@ 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 {
Text( Box {
modifier = Modifier Text(
.background(color = MaterialTheme.colors.headerBackground) modifier = Modifier
.padding(vertical = 8.dp) .background(color = MaterialTheme.colors.headerBackground)
.fillMaxWidth(), .padding(vertical = 8.dp)
text = title, .fillMaxWidth(),
fontWeight = FontWeight.Bold, text = title,
textAlign = TextAlign.Center, fontWeight = FontWeight.Bold,
color = MaterialTheme.colors.primary, textAlign = TextAlign.Center,
fontSize = 14.sp, color = MaterialTheme.colors.primary,
maxLines = 1, 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( ScrollableLazyColumn(
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),