Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ private const val PREF_CACHE_CREDENTIALS_IN_MEMORY = "credentialsInMemory"
private const val PREF_FIRST_PANE_WIDTH = "firstPaneWidth"
private const val PREF_THIRD_PANE_WIDTH = "thirdPaneWidth"

private const val PREF_GIT_DEFAULT_CLONE_DIR = "gitDefaultCloneDir"
private const val PREF_GIT_FF_MERGE = "gitFFMerge"
private const val PREF_GIT_MERGE_AUTOSTASH = "mergeAutoStash"
private const val PREF_GIT_PULL_REBASE = "gitPullRebase"
Expand Down Expand Up @@ -90,6 +91,9 @@ class AppSettingsRepository @Inject constructor() {
private val _verifySslFlow = MutableStateFlow(cacheCredentialsInMemory)
val verifySslFlow = _verifySslFlow.asStateFlow()

private val _defaultCloneDirFlow = MutableStateFlow(defaultCloneDir)
val defaultCloneDirFlow = _defaultCloneDirFlow.asStateFlow()

private val _ffMergeFlow = MutableStateFlow(ffMerge)
val ffMergeFlow = _ffMergeFlow.asStateFlow()

Expand Down Expand Up @@ -246,6 +250,17 @@ class AppSettingsRepository @Inject constructor() {
_scaleUiFlow.value = value
}

/*
* Property that holds the default directory to clone a repository into.
*/
var defaultCloneDir: String
get() = preferences.get(PREF_GIT_DEFAULT_CLONE_DIR, "")
set(value) {
preferences.put(PREF_GIT_DEFAULT_CLONE_DIR, value)

_defaultCloneDirFlow.value = value
}

/**
* Property that decides if the merge should fast-forward when possible
*/
Expand Down
29 changes: 29 additions & 0 deletions src/main/kotlin/com/jetpackduba/gitnuro/ui/dialogs/CloneDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ private fun CloneDialogView(
onCloneSubmodulesChange: (Boolean) -> Unit,
) {
val error by cloneViewModel.error.collectAsState()
val saveDirAsDefault by cloneViewModel.saveDirAsDefault.collectAsState()

val urlFocusRequester = remember { FocusRequester() }
val directoryFocusRequester = remember { FocusRequester() }
Expand Down Expand Up @@ -182,6 +183,34 @@ private fun CloneDialogView(
}
)

Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.handMouseClickable(
interactionSource = remember { MutableInteractionSource() },
indication = null,
) {
cloneViewModel.onSaveAsDefaultChanged(!saveDirAsDefault)
}
.fillMaxWidth()
.padding(top = 16.dp)
) {
Checkbox(
checked = saveDirAsDefault,
onCheckedChange = {
cloneViewModel.onSaveAsDefaultChanged(!saveDirAsDefault)
},
modifier = Modifier
.padding(all = 8.dp)
.size(12.dp)
)

Text(
"Save as Default",
style = MaterialTheme.typography.body2,
color = MaterialTheme.colors.onBackground,
)
}

TextInput(
modifier = Modifier.padding(top = 16.dp),
title = "Folder",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ val settings = listOf(
SettingsEntry.Entry(Res.drawable.layout, "Layout") { Layout(it) },
SettingsEntry.Entry(Res.drawable.schedule, "Date/Time") { DateTime(it) },
SettingsEntry.Section("GIT"),
SettingsEntry.Entry(Res.drawable.folder, "Environment") { Environment(it) },
SettingsEntry.Entry(Res.drawable.branch, "Branches") { Branches(it) },
SettingsEntry.Entry(Res.drawable.cloud, "Remote actions") { RemoteActions(it) },

Expand Down Expand Up @@ -383,6 +384,21 @@ fun Logs(settingsViewModel: SettingsViewModel) {
}


@Composable
private fun Environment(settingsViewModel: SettingsViewModel) {
var defaultCloneDir by remember { mutableStateOf(settingsViewModel.defaultCloneDir) }

SettingTextInput(
title = "Default Clone Directory",
subtitle = "Directory that will be used as default when cloning a repository",
value = defaultCloneDir,
onValueChanged = { value ->
defaultCloneDir = value
settingsViewModel.defaultCloneDir = value
},
)
}

@Composable
private fun Branches(settingsViewModel: SettingsViewModel) {
val ffMerge by settingsViewModel.ffMergeFlow.collectAsState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.ui.text.input.TextFieldValue
import com.jetpackduba.gitnuro.git.CloneState
import com.jetpackduba.gitnuro.git.TabState
import com.jetpackduba.gitnuro.git.remote_operations.CloneRepositoryUseCase
import com.jetpackduba.gitnuro.repositories.AppSettingsRepository
import com.jetpackduba.gitnuro.system.OpenFilePickerUseCase
import com.jetpackduba.gitnuro.system.PickerType
import kotlinx.coroutines.Dispatchers
Expand All @@ -19,13 +20,17 @@ class CloneViewModel @Inject constructor(
private val tabState: TabState,
private val cloneRepositoryUseCase: CloneRepositoryUseCase,
private val openFilePickerUseCase: OpenFilePickerUseCase,
private val appSettingsRepository: AppSettingsRepository,
) {
private val _repositoryUrl = MutableStateFlow(TextFieldValue(""))
val repositoryUrl = _repositoryUrl.asStateFlow()

private val _directoryPath = MutableStateFlow(TextFieldValue(""))
private val _directoryPath = MutableStateFlow(TextFieldValue(appSettingsRepository.defaultCloneDir))
val directoryPath = _directoryPath.asStateFlow()

private val _saveDirAsDefault = MutableStateFlow(false)
val saveDirAsDefault = _saveDirAsDefault.asStateFlow()

private val _folder = MutableStateFlow(TextFieldValue(""))
val folder = _folder.asStateFlow()

Expand Down Expand Up @@ -59,6 +64,9 @@ class CloneViewModel @Inject constructor(
if (!directory.exists()) {
directory.mkdirs()
}
if (_saveDirAsDefault.value) {
appSettingsRepository.defaultCloneDir = directoryPath
}

val repoDir = File(directory, folder)
if (!repoDir.exists()) {
Expand Down Expand Up @@ -108,6 +116,10 @@ class CloneViewModel @Inject constructor(
_directoryPath.value = directory
}

fun onSaveAsDefaultChanged(value: Boolean) {
_saveDirAsDefault.value = value
}

fun onRepositoryUrlChanged(repositoryUrl: TextFieldValue) {
_repositoryUrl.value = repositoryUrl
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class SettingsViewModel @Inject constructor(

val themeState = appSettingsRepository.themeState
val linesHeightTypeState = appSettingsRepository.linesHeightTypeState
var defaultCloneDirFlow = appSettingsRepository.defaultCloneDirFlow
val ffMergeFlow = appSettingsRepository.ffMergeFlow
val mergeAutoStashFlow = appSettingsRepository.mergeAutoStashFlow
val pullRebaseFlow = appSettingsRepository.pullRebaseFlow
Expand All @@ -53,6 +54,12 @@ class SettingsViewModel @Inject constructor(
appSettingsRepository.scaleUi = value
}

var defaultCloneDir: String
get() = appSettingsRepository.defaultCloneDir
set(value) {
appSettingsRepository.defaultCloneDir = value
}

var swapUncommittedChanges: Boolean
get() = appSettingsRepository.swapUncommittedChanges
set(value) {
Expand Down