Added option to stage/unstage file from diff header
This commit is contained in:
parent
a24ae5fdad
commit
364fa53558
@ -11,7 +11,6 @@ import androidx.compose.material.LinearProgressIndicator
|
|||||||
import androidx.compose.material.MaterialTheme
|
import androidx.compose.material.MaterialTheme
|
||||||
import androidx.compose.material.Text
|
import androidx.compose.material.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
@ -26,6 +25,7 @@ import androidx.compose.ui.unit.dp
|
|||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import app.git.DiffEntryType
|
import app.git.DiffEntryType
|
||||||
import app.git.EntryContent
|
import app.git.EntryContent
|
||||||
|
import app.git.StatusEntry
|
||||||
import app.git.StatusType
|
import app.git.StatusType
|
||||||
import app.git.diff.DiffResult
|
import app.git.diff.DiffResult
|
||||||
import app.git.diff.Hunk
|
import app.git.diff.Hunk
|
||||||
@ -65,7 +65,13 @@ fun Diff(
|
|||||||
val diffEntry = viewDiffResult.diffResult.diffEntry
|
val diffEntry = viewDiffResult.diffResult.diffEntry
|
||||||
val diffResult = viewDiffResult.diffResult
|
val diffResult = viewDiffResult.diffResult
|
||||||
|
|
||||||
DiffHeader(diffEntry, onCloseDiffView)
|
DiffHeader(
|
||||||
|
diffEntryType = diffEntryType,
|
||||||
|
diffEntry = diffEntry,
|
||||||
|
onCloseDiffView = onCloseDiffView,
|
||||||
|
stageFile = { diffViewModel.stageFile(it) },
|
||||||
|
unstageFile = { diffViewModel.unstageFile(it) },
|
||||||
|
)
|
||||||
|
|
||||||
if (diffResult is DiffResult.Text) {
|
if (diffResult is DiffResult.Text) {
|
||||||
TextDiff(diffEntryType, diffViewModel, diffResult)
|
TextDiff(diffEntryType, diffViewModel, diffResult)
|
||||||
@ -266,7 +272,13 @@ fun HunkHeader(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun DiffHeader(diffEntry: DiffEntry, onCloseDiffView: () -> Unit) {
|
fun DiffHeader(
|
||||||
|
diffEntryType: DiffEntryType,
|
||||||
|
diffEntry: DiffEntry,
|
||||||
|
onCloseDiffView: () -> Unit,
|
||||||
|
stageFile: (StatusEntry) -> Unit,
|
||||||
|
unstageFile: (StatusEntry) -> Unit,
|
||||||
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
@ -287,6 +299,31 @@ fun DiffHeader(diffEntry: DiffEntry, onCloseDiffView: () -> Unit) {
|
|||||||
|
|
||||||
Spacer(modifier = Modifier.weight(1f))
|
Spacer(modifier = Modifier.weight(1f))
|
||||||
|
|
||||||
|
if(diffEntryType is DiffEntryType.UncommitedDiff) {
|
||||||
|
val buttonText: String
|
||||||
|
val color: Color
|
||||||
|
|
||||||
|
if (diffEntryType is DiffEntryType.StagedDiff) {
|
||||||
|
buttonText = "Unstage file"
|
||||||
|
color = MaterialTheme.colors.unstageButton
|
||||||
|
} else {
|
||||||
|
buttonText = "Stage file"
|
||||||
|
color = MaterialTheme.colors.stageButton
|
||||||
|
}
|
||||||
|
|
||||||
|
SecondaryButton(
|
||||||
|
text = buttonText,
|
||||||
|
backgroundButton = color,
|
||||||
|
onClick = {
|
||||||
|
if (diffEntryType is DiffEntryType.StagedDiff) {
|
||||||
|
unstageFile(diffEntryType.statusEntry)
|
||||||
|
} else {
|
||||||
|
stageFile(diffEntryType.statusEntry)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
IconButton(
|
IconButton(
|
||||||
onClick = onCloseDiffView
|
onClick = onCloseDiffView
|
||||||
) {
|
) {
|
||||||
|
@ -72,6 +72,18 @@ class DiffViewModel @Inject constructor(
|
|||||||
) { git ->
|
) { git ->
|
||||||
statusManager.unstageHunk(git, diffEntry, hunk)
|
statusManager.unstageHunk(git, diffEntry, hunk)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun stageFile(statusEntry: StatusEntry) = tabState.runOperation(
|
||||||
|
refreshType = RefreshType.UNCOMMITED_CHANGES,
|
||||||
|
) { git ->
|
||||||
|
statusManager.stage(git, statusEntry)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun unstageFile(statusEntry: StatusEntry) = tabState.runOperation(
|
||||||
|
refreshType = RefreshType.UNCOMMITED_CHANGES,
|
||||||
|
) { git ->
|
||||||
|
statusManager.unstage(git, statusEntry)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user