Removed automatic resume on rebase interactive

This commit is contained in:
Abdelilah El Aissaoui 2022-10-27 20:53:02 +02:00
parent 7a2692202d
commit 31d5a98f2e
4 changed files with 61 additions and 9 deletions

View File

@ -8,6 +8,7 @@ import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.jetpackduba.gitnuro.theme.textButtonColors
@ -165,14 +166,27 @@ fun ActionDropdown(
) {
var showDropDownMenu by remember { mutableStateOf(false) }
Box {
PrimaryButton(
TextButton(
onClick = { showDropDownMenu = true },
modifier = Modifier
.width(120.dp)
.height(40.dp)
.padding(end = 8.dp),
text = action.toToken().replaceFirstChar { it.uppercase() }
)
) {
Text(
action.toToken().replaceFirstChar { it.uppercase() },
color = MaterialTheme.colors.onBackground,
style = MaterialTheme.typography.body1,
modifier = Modifier.weight(1f)
)
Icon(
painterResource("expand_more.svg"),
contentDescription = null,
modifier = Modifier.size(20.dp),
tint = MaterialTheme.colors.onBackground,
)
}
DropdownMenu(
expanded = showDropDownMenu,

View File

@ -19,12 +19,14 @@ import androidx.compose.ui.input.pointer.PointerIcon
import androidx.compose.ui.input.pointer.pointerHoverIcon
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.*
import com.jetpackduba.gitnuro.extensions.handMouseClickable
import com.jetpackduba.gitnuro.git.DiffEntryType
import com.jetpackduba.gitnuro.keybindings.KeybindingOption
import com.jetpackduba.gitnuro.keybindings.matchesBinding
import com.jetpackduba.gitnuro.ui.components.PrimaryButton
import com.jetpackduba.gitnuro.ui.components.ScrollableColumn
import com.jetpackduba.gitnuro.ui.dialogs.*
import com.jetpackduba.gitnuro.ui.diff.Diff
@ -124,6 +126,10 @@ fun RepositoryOpenPage(
if (repositoryState == RepositoryState.REBASING_INTERACTIVE && rebaseInteractiveViewModel != null) {
RebaseInteractive(rebaseInteractiveViewModel)
} else if (repositoryState == RepositoryState.REBASING_INTERACTIVE) {
RebaseInteractiveStartedExternally(
onCancelRebaseInteractive = { tabViewModel.cancelRebaseInteractive() }
)
} else {
Column(modifier = Modifier.weight(1f)) {
Menu(
@ -163,6 +169,31 @@ fun RepositoryOpenPage(
}
}
@Composable
fun RebaseInteractiveStartedExternally(
onCancelRebaseInteractive: () -> Unit,
) {
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally,
) {
Text(
"Rebase interactive started externally or Gitnuro (or this repository's tab)\nhas been restarted during the rebase.",
textAlign = TextAlign.Center,
fontWeight = FontWeight.Medium,
style = MaterialTheme.typography.body1,
)
PrimaryButton(
modifier = Modifier.padding(top = 8.dp),
text = "Abort rebase interactive",
onClick = onCancelRebaseInteractive,
backgroundColor = MaterialTheme.colors.error,
textColor = MaterialTheme.colors.onError,
)
}
}
@Composable
private fun BottomInfoBar(tabViewModel: TabViewModel) {
val userInfo by tabViewModel.authorInfoSimple.collectAsState()
@ -262,7 +293,7 @@ fun MainContentView(
selectedItem: SelectedItem,
repositoryState: RepositoryState,
blameState: BlameState,
) {
) {
HorizontalSplitPane(
splitPaneState = rememberSplitPaneState(initialPositionPercentage = 0.20f)
) {

View File

@ -8,6 +8,7 @@ import com.jetpackduba.gitnuro.git.rebase.AbortRebaseUseCase
import com.jetpackduba.gitnuro.git.rebase.GetRebaseLinesFullMessageUseCase
import com.jetpackduba.gitnuro.git.rebase.ResumeRebaseInteractiveUseCase
import com.jetpackduba.gitnuro.git.rebase.StartRebaseInteractiveUseCase
import com.jetpackduba.gitnuro.logging.printLog
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.runBlocking
@ -19,6 +20,8 @@ import org.eclipse.jgit.lib.RebaseTodoLine.Action
import org.eclipse.jgit.revwalk.RevCommit
import javax.inject.Inject
private const val TAG = "RebaseInteractiveViewMo"
class RebaseInteractiveViewModel @Inject constructor(
private val tabState: TabState,
private val getRebaseLinesFullMessageUseCase: GetRebaseLinesFullMessageUseCase,

View File

@ -6,6 +6,7 @@ import com.jetpackduba.gitnuro.credentials.CredentialsState
import com.jetpackduba.gitnuro.credentials.CredentialsStateManager
import com.jetpackduba.gitnuro.git.*
import com.jetpackduba.gitnuro.git.branches.CreateBranchUseCase
import com.jetpackduba.gitnuro.git.rebase.AbortRebaseUseCase
import com.jetpackduba.gitnuro.git.repository.GetRepositoryStateUseCase
import com.jetpackduba.gitnuro.git.repository.InitLocalRepositoryUseCase
import com.jetpackduba.gitnuro.git.repository.OpenRepositoryUseCase
@ -55,6 +56,7 @@ class TabViewModel @Inject constructor(
private val createBranchUseCase: CreateBranchUseCase,
private val stashChangesUseCase: StashChangesUseCase,
private val stageUntrackedFileUseCase: StageUntrackedFileUseCase,
private val abortRebaseUseCase: AbortRebaseUseCase,
private val tabScope: CoroutineScope,
) {
val errorsManager: ErrorsManager = tabState.errorsManager
@ -183,11 +185,6 @@ class TabViewModel @Inject constructor(
loadAuthorInfo(git)
onRepositoryStateChanged(newRepoState)
if (newRepoState == RepositoryState.REBASING_INTERACTIVE && rebaseInteractiveViewModel == null) {
rebaseInteractiveViewModel = rebaseInteractiveViewModelProvider.get()
rebaseInteractiveViewModel?.resumeRebase()
}
}
private fun loadAuthorInfo(git: Git) {
@ -434,6 +431,13 @@ class TabViewModel @Inject constructor(
) { git ->
Desktop.getDesktop().open(git.repository.directory.parentFile)
}
fun cancelRebaseInteractive() = tabState.safeProcessing(
refreshType = RefreshType.ALL_DATA,
) { git ->
abortRebaseUseCase(git)
rebaseInteractiveViewModel = null // shouldn't be necessary but just to make sure
}
}