Added reset file button
This commit is contained in:
parent
c24908cc5a
commit
ccd345d5ea
@ -179,6 +179,14 @@ class GitManager {
|
||||
fun deleteBranch(branch: Ref) = managerScope.launch {
|
||||
branchesManager.deleteBranch(safeGit, branch)
|
||||
}
|
||||
|
||||
fun resetStaged(diffEntry: DiffEntry) = managerScope.launch {
|
||||
statusManager.reset(safeGit, diffEntry, staged = true)
|
||||
}
|
||||
|
||||
fun resetUnstaged(diffEntry: DiffEntry) = managerScope.launch {
|
||||
statusManager.reset(safeGit, diffEntry, staged = false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
@file:Suppress("UNUSED_PARAMETER")
|
||||
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.ExperimentalAnimationApi
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.*
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.itemsIndexed
|
||||
@ -15,10 +15,12 @@ import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.RectangleShape
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.platform.ContextMenuItem
|
||||
import androidx.compose.ui.platform.ContextMenuState
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
@ -68,6 +70,9 @@ fun UncommitedChanges(
|
||||
onDiffEntrySelected = onStagedDiffEntrySelected,
|
||||
onDiffEntryOptionSelected = {
|
||||
gitManager.unstage(it)
|
||||
},
|
||||
onReset = { diffEntry ->
|
||||
gitManager.resetStaged(diffEntry)
|
||||
}
|
||||
)
|
||||
|
||||
@ -82,6 +87,9 @@ fun UncommitedChanges(
|
||||
onDiffEntrySelected = onUnstagedDiffEntrySelected,
|
||||
onDiffEntryOptionSelected = {
|
||||
gitManager.stage(it)
|
||||
},
|
||||
onReset = { diffEntry ->
|
||||
gitManager.resetUnstaged(diffEntry)
|
||||
}
|
||||
)
|
||||
|
||||
@ -130,6 +138,7 @@ private fun EntriesList(
|
||||
diffEntries: List<DiffEntry>,
|
||||
onDiffEntrySelected: (DiffEntry) -> Unit,
|
||||
onDiffEntryOptionSelected: (DiffEntry) -> Unit,
|
||||
onReset: (DiffEntry) -> Unit,
|
||||
) {
|
||||
Card(
|
||||
modifier = modifier
|
||||
@ -157,6 +166,9 @@ private fun EntriesList(
|
||||
},
|
||||
onButtonClick = {
|
||||
onDiffEntryOptionSelected(diffEntry)
|
||||
},
|
||||
onReset = {
|
||||
onReset(diffEntry)
|
||||
}
|
||||
)
|
||||
|
||||
@ -169,13 +181,36 @@ private fun EntriesList(
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(
|
||||
ExperimentalComposeUiApi::class, ExperimentalFoundationApi::class,
|
||||
ExperimentalDesktopApi::class
|
||||
)
|
||||
@Composable
|
||||
private fun FileEntry(diffEntry: DiffEntry, icon: ImageVector, onClick: () -> Unit, onButtonClick: () -> Unit) {
|
||||
private fun FileEntry(
|
||||
diffEntry: DiffEntry,
|
||||
icon: ImageVector,
|
||||
onClick: () -> Unit,
|
||||
onButtonClick: () -> Unit,
|
||||
onReset: () -> Unit,
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.clickable { onClick() }
|
||||
) {
|
||||
ContextMenuArea(
|
||||
items = {
|
||||
listOf(
|
||||
ContextMenuItem(
|
||||
label = "Reset",
|
||||
onClick = onReset
|
||||
)
|
||||
)
|
||||
},
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.height(56.dp)
|
||||
.fillMaxWidth()
|
||||
.clickable(onClick = onClick),
|
||||
.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
|
||||
@ -210,3 +245,5 @@ private fun FileEntry(diffEntry: DiffEntry, icon: ImageVector, onClick: () -> Un
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -74,6 +74,24 @@ class StatusManager {
|
||||
|
||||
loadStatus(git)
|
||||
}
|
||||
|
||||
suspend fun reset(git: Git, diffEntry: DiffEntry, staged: Boolean) = withContext(Dispatchers.IO) {
|
||||
println("Staged $staged")
|
||||
|
||||
if(staged) {
|
||||
git
|
||||
.reset()
|
||||
.addPath(diffEntry.filePath)
|
||||
.call()
|
||||
}
|
||||
|
||||
git
|
||||
.checkout()
|
||||
.addPath(diffEntry.filePath)
|
||||
.call()
|
||||
|
||||
loadStatus(git)
|
||||
}
|
||||
}
|
||||
|
||||
sealed class StageStatus {
|
||||
|
Loading…
Reference in New Issue
Block a user