Double click on remote branch in the side panel now creates a local copy

This commit is contained in:
Abdelilah El Aissaoui 2023-04-29 00:11:27 +02:00
parent 5b5aa136d0
commit 73816089a6
No known key found for this signature in database
GPG Key ID: 7587FC860F594869
3 changed files with 22 additions and 10 deletions

View File

@ -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,
)
}
}

View File

@ -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()
}

View File

@ -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<String>
@ -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)