diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/ui/SidePanel.kt b/src/main/kotlin/com/jetpackduba/gitnuro/ui/SidePanel.kt index ead2643..b8f807f 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/ui/SidePanel.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/ui/SidePanel.kt @@ -228,6 +228,7 @@ fun LazyListScope.remotes( RemoteBranches( remoteBranch = remoteBranch, onBranchClicked = { remotesViewModel.selectBranch(remoteBranch) }, + onDoubleClick = { remotesViewModel.checkoutRemoteBranch(remoteBranch) }, onDeleteBranch = { remotesViewModel.deleteRemoteBranch(remoteBranch) }, ) } @@ -412,6 +413,7 @@ private fun Remote( private fun RemoteBranches( remoteBranch: Ref, onBranchClicked: () -> Unit, + onDoubleClick: () -> Unit, onDeleteBranch: () -> Unit, ) { ContextMenu( @@ -425,7 +427,8 @@ private fun RemoteBranches( text = remoteBranch.simpleName, extraPadding = 24.dp, iconResourcePath = AppIcons.BRANCH, - onClick = onBranchClicked + onClick = onBranchClicked, + onDoubleClick = onDoubleClick, ) } } diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/ui/context_menu/BranchContextMenu.kt b/src/main/kotlin/com/jetpackduba/gitnuro/ui/context_menu/BranchContextMenu.kt index ca82816..55d0967 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/ui/context_menu/BranchContextMenu.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/ui/context_menu/BranchContextMenu.kt @@ -46,15 +46,6 @@ fun branchContextMenuItems( add(ContextMenuElement.ContextSeparator) } } - if (isLocal && !isCurrentBranch) { - add( - ContextMenuElement.ContextTextEntry( - label = "Delete branch", - icon = { painterResource(AppIcons.DELETE) }, - onClick = onDeleteBranch - ) - ) - } if (!isLocal && currentBranch != null && !currentBranch.isHead) { add( ContextMenuElement.ContextTextEntry( @@ -89,6 +80,16 @@ fun branchContextMenuItems( ) } + if (isLocal && !isCurrentBranch) { + add( + ContextMenuElement.ContextTextEntry( + label = "Delete branch", + icon = { painterResource(AppIcons.DELETE) }, + onClick = onDeleteBranch + ) + ) + } + if (lastOrNull() == ContextMenuElement.ContextSeparator) { removeLast() } diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/sidepanel/RemotesViewModel.kt b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/sidepanel/RemotesViewModel.kt index 40c5478..20543af 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/sidepanel/RemotesViewModel.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/sidepanel/RemotesViewModel.kt @@ -5,6 +5,7 @@ import com.jetpackduba.gitnuro.extensions.lowercaseContains import com.jetpackduba.gitnuro.extensions.simpleName import com.jetpackduba.gitnuro.git.RefreshType import com.jetpackduba.gitnuro.git.TabState +import com.jetpackduba.gitnuro.git.branches.CheckoutRefUseCase import com.jetpackduba.gitnuro.git.branches.DeleteLocallyRemoteBranchesUseCase import com.jetpackduba.gitnuro.git.branches.GetRemoteBranchesUseCase import com.jetpackduba.gitnuro.git.remote_operations.DeleteRemoteBranchUseCase @@ -30,6 +31,7 @@ class RemotesViewModel @AssistedInject constructor( private val addRemoteUseCase: AddRemoteUseCase, private val updateRemoteUseCase: UpdateRemoteUseCase, private val deleteLocallyRemoteBranchesUseCase: DeleteLocallyRemoteBranchesUseCase, + private val checkoutRefUseCase: CheckoutRefUseCase, private val tabScope: CoroutineScope, @Assisted private val filter: StateFlow @@ -169,6 +171,12 @@ class RemotesViewModel @AssistedInject constructor( uriType = RemoteSetUrlCommand.UriType.PUSH ) } + + fun checkoutRemoteBranch(remoteBranch: Ref) = tabState.safeProcessing( + refreshType = RefreshType.ALL_DATA, + ) { git -> + checkoutRefUseCase(git, remoteBranch) + } } data class RemoteView(val remoteInfo: RemoteInfo, val isExpanded: Boolean)