Implemented manual refresh with F5

This commit is contained in:
Abdelilah El Aissaoui 2022-06-27 20:36:24 +02:00
parent 0f835edc35
commit 4c48cd995e
3 changed files with 195 additions and 159 deletions

View File

@ -115,6 +115,7 @@ class TabState @Inject constructor(
refreshEvenIfCrashes: Boolean = false, refreshEvenIfCrashes: Boolean = false,
block: suspend (git: Git) -> Unit block: suspend (git: Git) -> Unit
) = managerScope.launch(Dispatchers.IO) { ) = managerScope.launch(Dispatchers.IO) {
mutex.withLock {
var hasProcessFailed = false var hasProcessFailed = false
operationRunning = true operationRunning = true
@ -145,6 +146,7 @@ class TabState @Inject constructor(
_refreshData.emit(refreshType) _refreshData.emit(refreshType)
} }
} }
}
suspend fun coRunOperation( suspend fun coRunOperation(
showError: Boolean = false, showError: Boolean = false,
@ -152,6 +154,7 @@ class TabState @Inject constructor(
refreshEvenIfCrashes: Boolean = false, refreshEvenIfCrashes: Boolean = false,
block: suspend (git: Git) -> Unit block: suspend (git: Git) -> Unit
) = withContext(Dispatchers.IO) { ) = withContext(Dispatchers.IO) {
mutex.withLock {
var hasProcessFailed = false var hasProcessFailed = false
operationRunning = true operationRunning = true
@ -182,6 +185,7 @@ class TabState @Inject constructor(
_refreshData.emit(refreshType) _refreshData.emit(refreshType)
} }
} }
}
suspend fun refreshData(refreshType: RefreshType) { suspend fun refreshData(refreshType: RefreshType) {
_refreshData.emit(refreshType) _refreshData.emit(refreshType)

View File

@ -3,13 +3,21 @@
package app.ui package app.ui
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.material.MaterialTheme import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.key
import androidx.compose.ui.input.key.onKeyEvent
import androidx.compose.ui.input.key.onPreviewKeyEvent
import androidx.compose.ui.input.pointer.PointerIcon import androidx.compose.ui.input.pointer.PointerIcon
import androidx.compose.ui.input.pointer.pointerHoverIcon import androidx.compose.ui.input.pointer.pointerHoverIcon
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@ -79,7 +87,25 @@ fun RepositoryOpenPage(tabViewModel: TabViewModel) {
} }
} }
Column { val focusRequester = remember { FocusRequester() }
LaunchedEffect(selectedItem) {
focusRequester.requestFocus()
}
Column(
modifier = Modifier
.focusRequester(focusRequester)
.focusable()
.onKeyEvent { event ->
if (event.key == Key.F5) {
tabViewModel.refreshAll()
true
} else {
false
}
}
) {
val rebaseInteractiveViewModel = tabViewModel.rebaseInteractiveViewModel val rebaseInteractiveViewModel = tabViewModel.rebaseInteractiveViewModel
if (repositoryState == RepositoryState.REBASING_INTERACTIVE && rebaseInteractiveViewModel != null) { if (repositoryState == RepositoryState.REBASING_INTERACTIVE && rebaseInteractiveViewModel != null) {
@ -166,6 +192,7 @@ fun RepoContent(
} }
@OptIn(ExperimentalComposeUiApi::class)
@Composable @Composable
fun MainContentView( fun MainContentView(
tabViewModel: TabViewModel, tabViewModel: TabViewModel,
@ -174,10 +201,9 @@ fun MainContentView(
repositoryState: RepositoryState, repositoryState: RepositoryState,
blameState: BlameState blameState: BlameState
) { ) {
Row {
HorizontalSplitPane { HorizontalSplitPane {
first(minSize = 250.dp) { first(minSize = 250.dp) {
ScrollableColumn(modifier = Modifier.fillMaxHeight( )) { ScrollableColumn(modifier = Modifier.fillMaxHeight()) {
Branches( Branches(
branchesViewModel = tabViewModel.branchesViewModel, branchesViewModel = tabViewModel.branchesViewModel,
) )
@ -307,7 +333,6 @@ fun MainContentView(
} }
} }
} }
}
} }
fun SplitterScope.repositorySplitter() { fun SplitterScope.repositorySplitter() {

View File

@ -313,7 +313,7 @@ class TabViewModel @Inject constructor(
loadRepositoryState(git) loadRepositoryState(git)
} }
private suspend fun refreshRepositoryInfo() = tabState.safeProcessing( private fun refreshRepositoryInfo() = tabState.safeProcessing(
refreshType = RefreshType.NONE, refreshType = RefreshType.NONE,
) { git -> ) { git ->
loadRepositoryState(git) loadRepositoryState(git)
@ -427,6 +427,13 @@ class TabViewModel @Inject constructor(
_showHistory.value = false _showHistory.value = false
historyViewModel = null historyViewModel = null
} }
fun refreshAll() {
printLog(TAG, "Manual refresh triggered")
if (!tabState.operationRunning) {
refreshRepositoryInfo()
}
}
} }