Added pull with rebase
This commit is contained in:
parent
a4ce691679
commit
de9e982ff3
6 changed files with 152 additions and 15 deletions
|
@ -20,7 +20,7 @@ class RemoteOperationsManager @Inject constructor(
|
|||
val cloneStatus: StateFlow<CloneStatus>
|
||||
get() = _cloneStatus
|
||||
|
||||
suspend fun pull(git: Git) = withContext(Dispatchers.IO) {
|
||||
suspend fun pull(git: Git, rebase: Boolean) = withContext(Dispatchers.IO) {
|
||||
git
|
||||
.pull()
|
||||
.setTransportConfigCallback {
|
||||
|
@ -30,6 +30,7 @@ class RemoteOperationsManager @Inject constructor(
|
|||
it.credentialsProvider = HttpCredentialsProvider()
|
||||
}
|
||||
}
|
||||
.setRebase(rebase)
|
||||
.setCredentialsProvider(CredentialsProvider.getDefault())
|
||||
.call()
|
||||
}
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
@file:OptIn(ExperimentalComposeUiApi::class)
|
||||
@file:OptIn(ExperimentalComposeUiApi::class, ExperimentalFoundationApi::class)
|
||||
|
||||
package app.ui
|
||||
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.*
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material.MaterialTheme
|
||||
import androidx.compose.material.OutlinedButton
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.*
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ArrowDropDown
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||
import androidx.compose.ui.Modifier
|
||||
|
@ -17,7 +18,12 @@ import androidx.compose.ui.res.painterResource
|
|||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import app.theme.primaryTextColor
|
||||
import app.ui.context_menu.pullContextMenuItems
|
||||
import app.viewmodels.MenuViewModel
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.setValue
|
||||
import app.ui.context_menu.DropDownContent
|
||||
import app.ui.context_menu.DropDownContentData
|
||||
|
||||
// TODO Add tooltips to all the buttons
|
||||
@Composable
|
||||
|
@ -43,10 +49,15 @@ fun Menu(
|
|||
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
|
||||
MenuButton(
|
||||
ExtendedMenuButton(
|
||||
title = "Pull",
|
||||
icon = painterResource("download.svg"),
|
||||
onClick = { menuViewModel.pull() },
|
||||
extendedListItems = pullContextMenuItems(
|
||||
onPullRebase = {
|
||||
menuViewModel.pull(true)
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
MenuButton(
|
||||
|
@ -65,7 +76,6 @@ fun Menu(
|
|||
},
|
||||
)
|
||||
|
||||
|
||||
Spacer(modifier = Modifier.width(16.dp))
|
||||
|
||||
MenuButton(
|
||||
|
@ -103,11 +113,12 @@ fun MenuButton(
|
|||
MaterialTheme.colors.secondaryVariant
|
||||
}
|
||||
|
||||
OutlinedButton(
|
||||
Box(
|
||||
modifier = modifier
|
||||
.padding(horizontal = 2.dp),
|
||||
enabled = enabled,
|
||||
onClick = onClick,
|
||||
.padding(horizontal = 2.dp)
|
||||
.clickable { if (enabled) onClick() }
|
||||
.border(ButtonDefaults.outlinedBorder, RoundedCornerShape(3.dp))
|
||||
.padding(vertical = 8.dp, horizontal = 16.dp),
|
||||
) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
|
@ -127,7 +138,82 @@ fun MenuButton(
|
|||
color = MaterialTheme.colors.primaryTextColor
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ExtendedMenuButton(
|
||||
modifier: Modifier = Modifier,
|
||||
enabled: Boolean = true,
|
||||
title: String,
|
||||
icon: Painter,
|
||||
onClick: () -> Unit,
|
||||
extendedListItems: List<DropDownContentData>,
|
||||
) {
|
||||
val iconColor = if (enabled) {
|
||||
MaterialTheme.colors.primary
|
||||
} else {
|
||||
MaterialTheme.colors.secondaryVariant
|
||||
}
|
||||
|
||||
var showDropDownMenu by remember { mutableStateOf(false) }
|
||||
|
||||
Row(modifier = Modifier.height(IntrinsicSize.Min)) {
|
||||
Box(
|
||||
modifier = modifier
|
||||
.clickable { if (enabled) onClick() }
|
||||
.border(ButtonDefaults.outlinedBorder, RoundedCornerShape(topStart = 3.dp, bottomStart = 3.dp))
|
||||
.padding(vertical = 8.dp, horizontal = 16.dp),
|
||||
) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Image(
|
||||
painter = icon,
|
||||
contentDescription = title,
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 4.dp)
|
||||
.size(24.dp),
|
||||
colorFilter = ColorFilter.tint(iconColor),
|
||||
)
|
||||
Text(
|
||||
text = title,
|
||||
fontSize = 12.sp,
|
||||
color = MaterialTheme.colors.primaryTextColor
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Box(
|
||||
modifier = modifier
|
||||
.padding(end = 8.dp)
|
||||
.width(20.dp)
|
||||
.fillMaxHeight()
|
||||
.border(ButtonDefaults.outlinedBorder, RoundedCornerShape(topEnd = 3.dp, bottomEnd = 3.dp))
|
||||
.clickable {
|
||||
showDropDownMenu = true
|
||||
},
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Icon(
|
||||
Icons.Default.ArrowDropDown,
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colors.primaryTextColor,
|
||||
)
|
||||
|
||||
DropdownMenu(
|
||||
onDismissRequest = {
|
||||
showDropDownMenu = false
|
||||
},
|
||||
content = {
|
||||
for (item in extendedListItems) {
|
||||
DropDownContent(item, onDismiss = { showDropDownMenu = false })
|
||||
}
|
||||
},
|
||||
expanded = showDropDownMenu,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
26
src/main/kotlin/app/ui/context_menu/DropDownContent.kt
Normal file
26
src/main/kotlin/app/ui/context_menu/DropDownContent.kt
Normal file
|
@ -0,0 +1,26 @@
|
|||
package app.ui.context_menu
|
||||
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.material.DropdownMenuItem
|
||||
import androidx.compose.material.Icon
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.unit.sp
|
||||
|
||||
@Composable
|
||||
fun DropDownContent(dropDownContentData: DropDownContentData, onDismiss: () -> Unit) {
|
||||
DropdownMenuItem(
|
||||
onClick = {
|
||||
dropDownContentData.onClick()
|
||||
onDismiss()
|
||||
}
|
||||
) {
|
||||
Row {
|
||||
if (dropDownContentData.icon != null) {
|
||||
Icon(imageVector = dropDownContentData.icon, contentDescription = null)
|
||||
}
|
||||
|
||||
Text(dropDownContentData.label, fontSize = 14.sp)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package app.ui.context_menu
|
||||
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
|
||||
data class DropDownContentData(
|
||||
val label: String,
|
||||
val icon: ImageVector? = null,
|
||||
val onClick: () -> Unit,
|
||||
)
|
15
src/main/kotlin/app/ui/context_menu/PullContextMenu.kt
Normal file
15
src/main/kotlin/app/ui/context_menu/PullContextMenu.kt
Normal file
|
@ -0,0 +1,15 @@
|
|||
package app.ui.context_menu
|
||||
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
fun pullContextMenuItems(
|
||||
onPullRebase: () -> Unit,
|
||||
): List<DropDownContentData> {
|
||||
return mutableListOf(
|
||||
DropDownContentData(
|
||||
label = "Pull with rebase",
|
||||
onClick = onPullRebase,
|
||||
),
|
||||
)
|
||||
}
|
|
@ -12,8 +12,8 @@ class MenuViewModel @Inject constructor(
|
|||
private val remoteOperationsManager: RemoteOperationsManager,
|
||||
private val stashManager: StashManager,
|
||||
) {
|
||||
fun pull() = tabState.safeProcessing { git ->
|
||||
remoteOperationsManager.pull(git)
|
||||
fun pull(rebase: Boolean = false) = tabState.safeProcessing { git ->
|
||||
remoteOperationsManager.pull(git, rebase)
|
||||
|
||||
return@safeProcessing RefreshType.ONLY_LOG
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue