Added submodules listing support
This commit is contained in:
parent
7cc3c069b6
commit
1217d401ed
@ -217,6 +217,7 @@ enum class RefreshType {
|
||||
REPO_STATE,
|
||||
ONLY_LOG,
|
||||
STASHES,
|
||||
SUBMODULES,
|
||||
UNCOMMITED_CHANGES,
|
||||
UNCOMMITED_CHANGES_AND_LOG,
|
||||
REMOTES,
|
||||
|
15
src/main/kotlin/app/git/submodules/GetSubmodulesUseCase.kt
Normal file
15
src/main/kotlin/app/git/submodules/GetSubmodulesUseCase.kt
Normal file
@ -0,0 +1,15 @@
|
||||
package app.git.submodules
|
||||
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.eclipse.jgit.submodule.SubmoduleStatus
|
||||
import javax.inject.Inject
|
||||
|
||||
class GetSubmodulesUseCase @Inject constructor() {
|
||||
suspend operator fun invoke(git: Git): Map<String, SubmoduleStatus> = withContext(Dispatchers.IO) {
|
||||
return@withContext git
|
||||
.submoduleStatus()
|
||||
.call()
|
||||
}
|
||||
}
|
@ -209,6 +209,9 @@ fun MainContentView(
|
||||
Stashes(
|
||||
stashesViewModel = tabViewModel.stashesViewModel,
|
||||
)
|
||||
Submodules(
|
||||
submodulesViewModel = tabViewModel.submodulesViewModel,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
62
src/main/kotlin/app/ui/Submodules.kt
Normal file
62
src/main/kotlin/app/ui/Submodules.kt
Normal file
@ -0,0 +1,62 @@
|
||||
package app.ui
|
||||
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.MaterialTheme
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import app.theme.secondaryTextColor
|
||||
import app.ui.components.SideMenuPanel
|
||||
import app.ui.components.SideMenuSubentry
|
||||
import app.ui.components.Tooltip
|
||||
import app.viewmodels.SubmodulesViewModel
|
||||
import org.eclipse.jgit.submodule.SubmoduleStatus
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
fun Submodules(
|
||||
submodulesViewModel: SubmodulesViewModel,
|
||||
) {
|
||||
val submodules by submodulesViewModel.submodules.collectAsState()
|
||||
val isExpanded by submodulesViewModel.isExpanded.collectAsState()
|
||||
|
||||
SideMenuPanel(
|
||||
title = "Submodules",
|
||||
icon = painterResource("topic.svg"),
|
||||
items = submodules,
|
||||
isExpanded = isExpanded,
|
||||
onExpand = { submodulesViewModel.onExpand() },
|
||||
itemContent = { submodule ->
|
||||
SubmoduleLineEntry(
|
||||
submodulePair = submodule,
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
private fun SubmoduleLineEntry(
|
||||
submodulePair: Pair<String, SubmoduleStatus>,
|
||||
) {
|
||||
submodulePair.second.type
|
||||
SideMenuSubentry(
|
||||
text = submodulePair.first,
|
||||
iconResourcePath = "topic.svg",
|
||||
) {
|
||||
val stateName = submodulePair.second.type.toString()
|
||||
Tooltip(stateName) {
|
||||
Text(
|
||||
text = stateName.first().toString(),
|
||||
color = MaterialTheme.colors.secondaryTextColor,
|
||||
style = MaterialTheme.typography.body2,
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
25
src/main/kotlin/app/viewmodels/SubmodulesViewModel.kt
Normal file
25
src/main/kotlin/app/viewmodels/SubmodulesViewModel.kt
Normal file
@ -0,0 +1,25 @@
|
||||
package app.viewmodels
|
||||
|
||||
import app.git.submodules.GetSubmodulesUseCase
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.eclipse.jgit.lib.Ref
|
||||
import org.eclipse.jgit.submodule.SubmoduleStatus
|
||||
import javax.inject.Inject
|
||||
|
||||
class SubmodulesViewModel @Inject constructor(
|
||||
private val getSubmodulesUseCase: GetSubmodulesUseCase
|
||||
): ExpandableViewModel() {
|
||||
private val _submodules = MutableStateFlow<List<Pair<String, SubmoduleStatus>>>(listOf())
|
||||
val submodules: StateFlow<List<Pair<String, SubmoduleStatus>>>
|
||||
get() = _submodules
|
||||
|
||||
private suspend fun loadSubmodules(git: Git) {
|
||||
_submodules.value = getSubmodulesUseCase(git).toList()
|
||||
}
|
||||
|
||||
suspend fun refresh(git: Git) {
|
||||
loadSubmodules(git)
|
||||
}
|
||||
}
|
@ -44,6 +44,7 @@ class TabViewModel @Inject constructor(
|
||||
val statusViewModel: StatusViewModel,
|
||||
val menuViewModel: MenuViewModel,
|
||||
val stashesViewModel: StashesViewModel,
|
||||
val submodulesViewModel: SubmodulesViewModel,
|
||||
val commitChangesViewModel: CommitChangesViewModel,
|
||||
val cloneViewModel: CloneViewModel,
|
||||
private val getRepositoryStateUseCase: GetRepositoryStateUseCase,
|
||||
@ -118,6 +119,7 @@ class TabViewModel @Inject constructor(
|
||||
RefreshType.REPO_STATE -> refreshRepositoryState()
|
||||
RefreshType.ONLY_LOG -> refreshLog()
|
||||
RefreshType.STASHES -> refreshStashes()
|
||||
RefreshType.SUBMODULES -> refreshSubmodules()
|
||||
RefreshType.UNCOMMITED_CHANGES -> checkUncommitedChanges()
|
||||
RefreshType.UNCOMMITED_CHANGES_AND_LOG -> checkUncommitedChanges(true)
|
||||
RefreshType.REMOTES -> refreshRemotes()
|
||||
@ -157,6 +159,12 @@ class TabViewModel @Inject constructor(
|
||||
stashesViewModel.refresh(git)
|
||||
}
|
||||
|
||||
private fun refreshSubmodules() = tabState.runOperation(
|
||||
refreshType = RefreshType.NONE
|
||||
) { git ->
|
||||
submodulesViewModel.refresh(git)
|
||||
}
|
||||
|
||||
private fun refreshLog() = tabState.runOperation(
|
||||
refreshType = RefreshType.NONE,
|
||||
) { git ->
|
||||
@ -328,6 +336,7 @@ class TabViewModel @Inject constructor(
|
||||
tagsViewModel.refresh(git)
|
||||
statusViewModel.refresh(git)
|
||||
stashesViewModel.refresh(git)
|
||||
submodulesViewModel.refresh(git)
|
||||
}
|
||||
|
||||
fun credentialsDenied() {
|
||||
|
1
src/main/resources/topic.svg
Normal file
1
src/main/resources/topic.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><g><rect fill="none" height="24" width="24"/><path d="M20,6h-8l-2-2H4C2.9,4,2.01,4.9,2.01,6L2,18c0,1.1,0.9,2,2,2h16c1.1,0,2-0.9,2-2V8C22,6.9,21.1,6,20,6z M14,16H6v-2h8V16z M18,12H6v-2h12V12z"/></g></svg>
|
After Width: | Height: | Size: 339 B |
Loading…
Reference in New Issue
Block a user