Added remotes to side panel
This commit is contained in:
parent
bc52221ef1
commit
c7954af9ad
@ -85,4 +85,11 @@ class BranchesManager @Inject constructor() {
|
||||
.setForce(true) // TODO Should it be forced?
|
||||
.call()
|
||||
}
|
||||
|
||||
suspend fun remoteBranches(git: Git) = withContext(Dispatchers.IO) {
|
||||
git
|
||||
.branchList()
|
||||
.setListMode(ListBranchCommand.ListMode.REMOTE)
|
||||
.call()
|
||||
}
|
||||
}
|
@ -15,6 +15,7 @@ import app.AppStateManager
|
||||
import app.app.ErrorsManager
|
||||
import app.app.newErrorNow
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import org.eclipse.jgit.transport.RemoteConfig
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
|
||||
@ -27,6 +28,7 @@ class GitManager @Inject constructor(
|
||||
private val stashManager: StashManager,
|
||||
private val diffManager: DiffManager,
|
||||
private val tagsManager: TagsManager,
|
||||
private val remotesManager: RemotesManager,
|
||||
val errorsManager: ErrorsManager,
|
||||
val appStateManager: AppStateManager,
|
||||
private val fileChangesWatcher: FileChangesWatcher,
|
||||
@ -58,6 +60,7 @@ class GitManager @Inject constructor(
|
||||
val stashStatus: StateFlow<StashStatus> = stashManager.stashStatus
|
||||
val credentialsState: StateFlow<CredentialsState> = credentialsStateManager.credentialsState
|
||||
val cloneStatus: StateFlow<CloneStatus> = remoteOperationsManager.cloneStatus
|
||||
val remotes: StateFlow<List<RemoteInfo>> = remotesManager.remotes
|
||||
|
||||
|
||||
private var git: Git? = null
|
||||
@ -194,6 +197,7 @@ class GitManager @Inject constructor(
|
||||
private suspend fun refreshRepositoryInfo() {
|
||||
statusManager.loadHasUncommitedChanges(safeGit)
|
||||
branchesManager.loadBranches(safeGit)
|
||||
remotesManager.loadRemotes(safeGit, branchesManager.remoteBranches(safeGit))
|
||||
tagsManager.loadTags(safeGit)
|
||||
stashManager.loadStashList(safeGit)
|
||||
coLoadLog()
|
||||
|
32
src/main/kotlin/app/git/RemotesManager.kt
Normal file
32
src/main/kotlin/app/git/RemotesManager.kt
Normal file
@ -0,0 +1,32 @@
|
||||
package app.git
|
||||
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.eclipse.jgit.lib.Ref
|
||||
import org.eclipse.jgit.transport.RemoteConfig
|
||||
import javax.inject.Inject
|
||||
|
||||
class RemotesManager @Inject constructor() {
|
||||
private val _remotes = MutableStateFlow<List<RemoteInfo>>(listOf())
|
||||
val remotes: StateFlow<List<RemoteInfo>>
|
||||
get() = _remotes
|
||||
|
||||
suspend fun loadRemotes(git: Git, allRemoteBranches: List<Ref>) = withContext(Dispatchers.IO) {
|
||||
val remotes = git.remoteList()
|
||||
.call()
|
||||
|
||||
val remoteInfoList = remotes.map { remoteConfig ->
|
||||
val remoteBranches = allRemoteBranches.filter { branch ->
|
||||
branch.name.startsWith("refs/remotes/${remoteConfig.name}")
|
||||
}
|
||||
RemoteInfo(remoteConfig, remoteBranches)
|
||||
}
|
||||
|
||||
_remotes.value = remoteInfoList
|
||||
}
|
||||
}
|
||||
|
||||
data class RemoteInfo(val remoteConfig: RemoteConfig, val branchesList: List<Ref>)
|
@ -33,7 +33,7 @@ fun Branches(gitManager: GitManager) {
|
||||
val currentBranch by gitManager.currentBranch.collectAsState()
|
||||
|
||||
Column {
|
||||
SideMenuEntry("Branches")
|
||||
SideMenuEntry("Local branches")
|
||||
|
||||
val branchesHeight = branches.count() * 40
|
||||
val maxHeight = if(branchesHeight < 300)
|
||||
|
62
src/main/kotlin/app/ui/Remotes.kt
Normal file
62
src/main/kotlin/app/ui/Remotes.kt
Normal file
@ -0,0 +1,62 @@
|
||||
package app.ui
|
||||
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import app.ui.components.ScrollableLazyColumn
|
||||
import app.extensions.simpleVisibleName
|
||||
import app.git.GitManager
|
||||
import app.git.RemoteInfo
|
||||
import app.ui.components.SideMenuEntry
|
||||
import app.ui.components.SideMenuSubentry
|
||||
|
||||
@Composable
|
||||
fun Remotes(gitManager: GitManager) {
|
||||
val remotes by gitManager.remotes.collectAsState()
|
||||
|
||||
Column {
|
||||
SideMenuEntry("Remotes")
|
||||
|
||||
val allBranches = remotes.map { it.branchesList }.flatten()
|
||||
val remotesHeight = (allBranches.count() + remotes.count()) * 40
|
||||
val maxHeight = if(remotesHeight < 300)
|
||||
remotesHeight
|
||||
else
|
||||
300
|
||||
|
||||
Box(modifier = Modifier.heightIn(max = maxHeight.dp)) {
|
||||
ScrollableLazyColumn(modifier = Modifier.fillMaxWidth()) {
|
||||
items(remotes) { remote ->
|
||||
RemoteRow(
|
||||
remote = remote,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun RemoteRow(
|
||||
remote: RemoteInfo,
|
||||
) {
|
||||
SideMenuSubentry(
|
||||
text = remote.remoteConfig.name,
|
||||
iconResourcePath = "cloud.svg",
|
||||
)
|
||||
|
||||
val branches = remote.branchesList
|
||||
Column {
|
||||
branches.forEach { branch ->
|
||||
SideMenuSubentry(
|
||||
text = branch.simpleVisibleName,
|
||||
extraPadding = 8.dp,
|
||||
iconResourcePath = "branch.svg",
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
@ -72,6 +72,7 @@ fun RepositoryOpenPage(gitManager: GitManager) {
|
||||
.fillMaxHeight()
|
||||
) {
|
||||
Branches(gitManager = gitManager)
|
||||
Remotes(gitManager = gitManager)
|
||||
Tags(gitManager = gitManager)
|
||||
Stashes(
|
||||
gitManager = gitManager,
|
||||
|
@ -14,6 +14,7 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import app.theme.primaryTextColor
|
||||
@ -23,6 +24,7 @@ fun SideMenuSubentry(
|
||||
text: String,
|
||||
iconResourcePath: String,
|
||||
bold: Boolean = false,
|
||||
extraPadding: Dp = 0.dp,
|
||||
onClick: () -> Unit = {},
|
||||
additionalInfo: @Composable () -> Unit = {}
|
||||
) {
|
||||
@ -30,7 +32,8 @@ fun SideMenuSubentry(
|
||||
modifier = Modifier
|
||||
.height(40.dp)
|
||||
.fillMaxWidth()
|
||||
.clickable(onClick = onClick),
|
||||
.clickable(onClick = onClick)
|
||||
.padding(start = extraPadding),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Icon(
|
||||
|
1
src/main/resources/cloud.svg
Normal file
1
src/main/resources/cloud.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0z" fill="none"/><path d="M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96z"/></svg>
|
After Width: | Height: | Size: 309 B |
Loading…
Reference in New Issue
Block a user