From 31d5a98f2ed02002ccd9c498d54c288e6e05b88a Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Thu, 27 Oct 2022 20:53:02 +0200 Subject: [PATCH] Removed automatic resume on rebase interactive --- .../gitnuro/ui/RebaseInteractive.kt | 20 +++++++++-- .../jetpackduba/gitnuro/ui/RepositoryOpen.kt | 33 ++++++++++++++++++- .../viewmodels/RebaseInteractiveViewModel.kt | 3 ++ .../gitnuro/viewmodels/TabViewModel.kt | 14 +++++--- 4 files changed, 61 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/ui/RebaseInteractive.kt b/src/main/kotlin/com/jetpackduba/gitnuro/ui/RebaseInteractive.kt index c74b743..5d88279 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/ui/RebaseInteractive.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/ui/RebaseInteractive.kt @@ -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, diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/ui/RepositoryOpen.kt b/src/main/kotlin/com/jetpackduba/gitnuro/ui/RepositoryOpen.kt index 5f962ff..eaae051 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/ui/RepositoryOpen.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/ui/RepositoryOpen.kt @@ -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) ) { diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/RebaseInteractiveViewModel.kt b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/RebaseInteractiveViewModel.kt index 3271858..6c29f4a 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/RebaseInteractiveViewModel.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/RebaseInteractiveViewModel.kt @@ -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, diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/TabViewModel.kt b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/TabViewModel.kt index 4f5741b..02cc924 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/TabViewModel.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/TabViewModel.kt @@ -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 + } }