WIP
This commit is contained in:
parent
c02ae6af39
commit
266fd7b294
@ -0,0 +1,68 @@
|
|||||||
|
package com.jetpackduba.gitnuro.preferences
|
||||||
|
|
||||||
|
import com.jetpackduba.gitnuro.di.TabScope
|
||||||
|
import com.jetpackduba.gitnuro.logging.printError
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlinx.serialization.decodeFromString
|
||||||
|
import kotlinx.serialization.encodeToString
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
import org.eclipse.jgit.lib.Repository
|
||||||
|
import java.io.File
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "RepositorySettings"
|
||||||
|
private const val GITNURO_CONFIG_FILE = "GITNURO_CONFIG"
|
||||||
|
|
||||||
|
class RepositorySettings @Inject constructor() {
|
||||||
|
fun getGraphWidth(repository: Repository): Float {
|
||||||
|
// return getConfig(repository)?.graphWidth ?: 0F // TODO use constants
|
||||||
|
return 0F
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setGraphWidth(repository: Repository, newValue: Float) {
|
||||||
|
val config = getConfig(repository) ?: RepositoryConfig(0F)
|
||||||
|
val newConfig = config.copy(graphWidth = newValue)
|
||||||
|
|
||||||
|
setConfig(repository, newConfig)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getConfig(repository: Repository): RepositoryConfig? {
|
||||||
|
if(repository.directory == null || !repository.directory.exists()) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
val configFile = File(repository.directory, GITNURO_CONFIG_FILE)
|
||||||
|
|
||||||
|
if (!configFile.exists()) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
val content = configFile.readText()
|
||||||
|
|
||||||
|
return try {
|
||||||
|
Json.decodeFromString<RepositoryConfig>(content)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
printError(TAG, "Error parsing repository config: ${e.message}", e)
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setConfig(repository: Repository, newConfig: RepositoryConfig) {
|
||||||
|
if(repository.directory == null || !repository.directory.exists()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val configFile = File(repository.directory, GITNURO_CONFIG_FILE)
|
||||||
|
|
||||||
|
if (!configFile.exists()) {
|
||||||
|
configFile.createNewFile()
|
||||||
|
}
|
||||||
|
|
||||||
|
configFile.writeText(Json.encodeToString(newConfig))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class RepositoryConfig(
|
||||||
|
val graphWidth: Float
|
||||||
|
)
|
@ -27,7 +27,6 @@ import androidx.compose.ui.graphics.Color
|
|||||||
import androidx.compose.ui.graphics.drawscope.clipRect
|
import androidx.compose.ui.graphics.drawscope.clipRect
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
import androidx.compose.ui.input.key.onPreviewKeyEvent
|
import androidx.compose.ui.input.key.onPreviewKeyEvent
|
||||||
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.platform.LocalDensity
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
@ -58,7 +57,6 @@ import kotlinx.coroutines.launch
|
|||||||
import org.eclipse.jgit.lib.Ref
|
import org.eclipse.jgit.lib.Ref
|
||||||
import org.eclipse.jgit.lib.RepositoryState
|
import org.eclipse.jgit.lib.RepositoryState
|
||||||
import org.eclipse.jgit.revwalk.RevCommit
|
import org.eclipse.jgit.revwalk.RevCommit
|
||||||
import java.awt.Cursor
|
|
||||||
|
|
||||||
private val colors = listOf(
|
private val colors = listOf(
|
||||||
Color(0xFF42a5f5),
|
Color(0xFF42a5f5),
|
||||||
@ -167,7 +165,10 @@ private fun LogLoaded(
|
|||||||
.background(MaterialTheme.colors.background)
|
.background(MaterialTheme.colors.background)
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
) {
|
) {
|
||||||
var graphPadding by remember(logViewModel) { mutableStateOf(logViewModel.graphPadding) }
|
var graphPadding by remember(logViewModel) {
|
||||||
|
mutableStateOf(logViewModel.graphPaddingPersisted())
|
||||||
|
}
|
||||||
|
|
||||||
var graphWidth = (CANVAS_DEFAULT_WIDTH + graphPadding).dp
|
var graphWidth = (CANVAS_DEFAULT_WIDTH + graphPadding).dp
|
||||||
|
|
||||||
if (graphWidth.value < CANVAS_MIN_WIDTH) graphWidth = CANVAS_MIN_WIDTH.dp
|
if (graphWidth.value < CANVAS_MIN_WIDTH) graphWidth = CANVAS_MIN_WIDTH.dp
|
||||||
@ -194,6 +195,9 @@ private fun LogLoaded(
|
|||||||
graphPadding += it
|
graphPadding += it
|
||||||
logViewModel.graphPadding = graphPadding
|
logViewModel.graphPadding = graphPadding
|
||||||
},
|
},
|
||||||
|
dragStopped = {
|
||||||
|
// logViewModel.persistGraphPadding()
|
||||||
|
},
|
||||||
onShowSearch = { scope.launch { logViewModel.onSearchValueChanged("") } }
|
onShowSearch = { scope.launch { logViewModel.onSearchValueChanged("") } }
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -566,6 +570,7 @@ fun LogDialogs(
|
|||||||
fun GraphHeader(
|
fun GraphHeader(
|
||||||
graphWidth: Dp,
|
graphWidth: Dp,
|
||||||
onPaddingChange: (Float) -> Unit,
|
onPaddingChange: (Float) -> Unit,
|
||||||
|
dragStopped: () -> Unit,
|
||||||
onShowSearch: () -> Unit
|
onShowSearch: () -> Unit
|
||||||
) {
|
) {
|
||||||
Box(
|
Box(
|
||||||
@ -593,8 +598,14 @@ fun GraphHeader(
|
|||||||
SimpleDividerLog(
|
SimpleDividerLog(
|
||||||
modifier = Modifier.draggable(
|
modifier = Modifier.draggable(
|
||||||
rememberDraggableState {
|
rememberDraggableState {
|
||||||
|
// println("OnDelta")
|
||||||
onPaddingChange(it * density) // Multiply by density for screens with scaling > 1
|
onPaddingChange(it * density) // Multiply by density for screens with scaling > 1
|
||||||
}, Orientation.Horizontal
|
},
|
||||||
|
Orientation.Horizontal,
|
||||||
|
onDragStopped = {
|
||||||
|
// println("Drag Stopped")
|
||||||
|
dragStopped()
|
||||||
|
}
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ import com.jetpackduba.gitnuro.git.workspace.CheckHasUncommitedChangesUseCase
|
|||||||
import com.jetpackduba.gitnuro.git.workspace.GetStatusSummaryUseCase
|
import com.jetpackduba.gitnuro.git.workspace.GetStatusSummaryUseCase
|
||||||
import com.jetpackduba.gitnuro.git.workspace.StatusSummary
|
import com.jetpackduba.gitnuro.git.workspace.StatusSummary
|
||||||
import com.jetpackduba.gitnuro.preferences.AppSettings
|
import com.jetpackduba.gitnuro.preferences.AppSettings
|
||||||
|
import com.jetpackduba.gitnuro.preferences.RepositorySettings
|
||||||
import com.jetpackduba.gitnuro.ui.SelectedItem
|
import com.jetpackduba.gitnuro.ui.SelectedItem
|
||||||
import com.jetpackduba.gitnuro.ui.log.LogDialog
|
import com.jetpackduba.gitnuro.ui.log.LogDialog
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
@ -70,6 +71,7 @@ class LogViewModel @Inject constructor(
|
|||||||
private val tabState: TabState,
|
private val tabState: TabState,
|
||||||
private val appSettings: AppSettings,
|
private val appSettings: AppSettings,
|
||||||
private val tabScope: CoroutineScope,
|
private val tabScope: CoroutineScope,
|
||||||
|
private val repositorySettings: RepositorySettings,
|
||||||
) : ViewModel {
|
) : ViewModel {
|
||||||
private val _logStatus = MutableStateFlow<LogStatus>(LogStatus.Loading)
|
private val _logStatus = MutableStateFlow<LogStatus>(LogStatus.Loading)
|
||||||
|
|
||||||
@ -78,6 +80,9 @@ class LogViewModel @Inject constructor(
|
|||||||
|
|
||||||
var savedSearchFilter: String = ""
|
var savedSearchFilter: String = ""
|
||||||
var graphPadding = 0f
|
var graphPadding = 0f
|
||||||
|
fun graphPaddingPersisted(): Float {
|
||||||
|
return 0f
|
||||||
|
}
|
||||||
|
|
||||||
private val scrollToItem: Flow<RevCommit> = tabState.taskEvent
|
private val scrollToItem: Flow<RevCommit> = tabState.taskEvent
|
||||||
.filterIsInstance<TaskEvent.ScrollToGraphItem>()
|
.filterIsInstance<TaskEvent.ScrollToGraphItem>()
|
||||||
@ -442,6 +447,10 @@ class LogViewModel @Inject constructor(
|
|||||||
) { git ->
|
) { git ->
|
||||||
deleteRemoteBranchUseCase(git, branch)
|
deleteRemoteBranchUseCase(git, branch)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fun persistGraphPadding() {
|
||||||
|
// repositorySettings.setGraphWidth(tabState.git.repository, graphPadding)
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class LogStatus {
|
sealed class LogStatus {
|
||||||
|
Loading…
Reference in New Issue
Block a user