Removed merge dialog. Fast forward config is now in the settings
This commit is contained in:
parent
7ce311d9b5
commit
befc7d1740
@ -24,6 +24,9 @@ private const val PREF_COMMITS_LIMIT_ENABLED = "commitsLimitEnabled"
|
||||
private const val PREF_WINDOW_PLACEMENT = "windowsPlacement"
|
||||
private const val PREF_CUSTOM_THEME = "customTheme"
|
||||
|
||||
|
||||
private const val PREF_GIT_FF_MERGE = "gitFFMerge"
|
||||
|
||||
private const val DEFAULT_COMMITS_LIMIT = 1000
|
||||
private const val DEFAULT_COMMITS_LIMIT_ENABLED = true
|
||||
|
||||
@ -34,9 +37,12 @@ class AppPreferences @Inject constructor() {
|
||||
private val _themeState = MutableStateFlow(theme)
|
||||
val themeState: StateFlow<Themes> = _themeState
|
||||
|
||||
private val _commitsLimitEnabledFlow = MutableStateFlow(true)
|
||||
private val _commitsLimitEnabledFlow = MutableStateFlow(commitsLimitEnabled)
|
||||
val commitsLimitEnabledFlow: StateFlow<Boolean> = _commitsLimitEnabledFlow
|
||||
|
||||
private val _ffMergeFlow = MutableStateFlow(ffMerge)
|
||||
val ffMergeFlow: StateFlow<Boolean> = _ffMergeFlow
|
||||
|
||||
private val _commitsLimitFlow = MutableStateFlow(commitsLimit)
|
||||
val commitsLimitFlow: StateFlow<Int> = _commitsLimitFlow
|
||||
|
||||
@ -79,6 +85,18 @@ class AppPreferences @Inject constructor() {
|
||||
_commitsLimitEnabledFlow.value = value
|
||||
}
|
||||
|
||||
/**
|
||||
* Property that decides if the merge should fast-forward when possible
|
||||
*/
|
||||
var ffMerge: Boolean
|
||||
get() {
|
||||
return preferences.getBoolean(PREF_GIT_FF_MERGE, true)
|
||||
}
|
||||
set(value) {
|
||||
preferences.putBoolean(PREF_GIT_FF_MERGE, value)
|
||||
_ffMergeFlow.value = value
|
||||
}
|
||||
|
||||
var commitsLimit: Int
|
||||
get() {
|
||||
return preferences.getInt(PREF_COMMITS_LIMIT, DEFAULT_COMMITS_LIMIT)
|
||||
|
@ -14,7 +14,6 @@ import app.extensions.simpleName
|
||||
import app.ui.components.SideMenuPanel
|
||||
import app.ui.components.SideMenuSubentry
|
||||
import app.ui.context_menu.branchContextMenuItems
|
||||
import app.ui.dialogs.MergeDialog
|
||||
import app.viewmodels.BranchesViewModel
|
||||
import org.eclipse.jgit.lib.Ref
|
||||
|
||||
@ -28,8 +27,6 @@ fun Branches(
|
||||
val isExpanded by branchesViewModel.isExpanded.collectAsState()
|
||||
val currentBranch = currentBranchState.value
|
||||
|
||||
val (mergeBranch, setMergeBranch) = remember { mutableStateOf<Ref?>(null) }
|
||||
|
||||
SideMenuPanel(
|
||||
title = "Local branches",
|
||||
icon = painterResource("branch.svg"),
|
||||
@ -44,7 +41,7 @@ fun Branches(
|
||||
onBranchClicked = { branchesViewModel.selectBranch(branch) },
|
||||
onBranchDoubleClicked = { branchesViewModel.checkoutRef(branch) },
|
||||
onCheckoutBranch = { branchesViewModel.checkoutRef(branch) },
|
||||
onMergeBranch = { setMergeBranch(branch) },
|
||||
onMergeBranch = { branchesViewModel.mergeBranch(branch) },
|
||||
onDeleteBranch = { branchesViewModel.deleteBranch(branch) },
|
||||
onRebaseBranch = { branchesViewModel.rebaseBranch(branch) },
|
||||
onPushToRemoteBranch = { branchesViewModel.pushToRemoteBranch(branch) },
|
||||
@ -52,15 +49,6 @@ fun Branches(
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
if (mergeBranch != null && currentBranch != null) {
|
||||
MergeDialog(
|
||||
currentBranchName = currentBranch.simpleName,
|
||||
mergeBranchName = mergeBranch.name,
|
||||
onReject = { setMergeBranch(null) },
|
||||
onAccept = { ff -> branchesViewModel.mergeBranch(mergeBranch, ff) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
|
@ -1,109 +0,0 @@
|
||||
package app.ui.dialogs
|
||||
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.mouseClickable
|
||||
import androidx.compose.material.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.input.pointer.isPrimaryPressed
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import app.theme.primaryTextColor
|
||||
import app.theme.textButtonColors
|
||||
import app.ui.components.PrimaryButton
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
fun MergeDialog(
|
||||
currentBranchName: String,
|
||||
mergeBranchName: String,
|
||||
fastForward: Boolean = false,
|
||||
onReject: () -> Unit,
|
||||
onAccept: (fastForward: Boolean) -> Unit
|
||||
) {
|
||||
var fastForwardCheck by remember { mutableStateOf(fastForward) }
|
||||
|
||||
MaterialDialog(onCloseRequested = onReject) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.background(MaterialTheme.colors.background),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center,
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(
|
||||
text = mergeBranchName,
|
||||
fontWeight = FontWeight.Medium,
|
||||
color = MaterialTheme.colors.primaryTextColor,
|
||||
)
|
||||
|
||||
|
||||
Text(
|
||||
text = "will be merged into",
|
||||
modifier = Modifier.padding(horizontal = 8.dp),
|
||||
color = MaterialTheme.colors.primaryTextColor,
|
||||
)
|
||||
|
||||
Text(
|
||||
text = currentBranchName,
|
||||
fontWeight = FontWeight.Medium,
|
||||
color = MaterialTheme.colors.primaryTextColor,
|
||||
)
|
||||
}
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.mouseClickable {
|
||||
if (this.buttons.isPrimaryPressed) {
|
||||
fastForwardCheck = !fastForwardCheck
|
||||
}
|
||||
}
|
||||
) {
|
||||
Checkbox(
|
||||
checked = fastForwardCheck,
|
||||
onCheckedChange = { checked ->
|
||||
fastForwardCheck = checked
|
||||
}
|
||||
)
|
||||
|
||||
Text(
|
||||
text = "Fast forward if possible",
|
||||
color = MaterialTheme.colors.primaryTextColor,
|
||||
modifier = Modifier
|
||||
.padding(start = 8.dp)
|
||||
)
|
||||
|
||||
}
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.padding(top = 16.dp)
|
||||
.align(Alignment.End)
|
||||
) {
|
||||
TextButton(
|
||||
modifier = Modifier.padding(end = 8.dp),
|
||||
colors = textButtonColors(),
|
||||
onClick = {
|
||||
onReject()
|
||||
}
|
||||
) {
|
||||
Text("Cancel")
|
||||
}
|
||||
PrimaryButton(
|
||||
onClick = {
|
||||
onAccept(fastForwardCheck)
|
||||
},
|
||||
text = "Merge"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -25,6 +25,7 @@ fun SettingsDialog(
|
||||
) {
|
||||
val currentTheme by appPreferences.themeState.collectAsState()
|
||||
val commitsLimitEnabled by appPreferences.commitsLimitEnabledFlow.collectAsState()
|
||||
val ffMerge by appPreferences.ffMergeFlow.collectAsState()
|
||||
var commitsLimit by remember { mutableStateOf(appPreferences.commitsLimit) }
|
||||
|
||||
MaterialDialog(
|
||||
@ -89,6 +90,15 @@ fun SettingsDialog(
|
||||
}
|
||||
)
|
||||
|
||||
SettingToogle(
|
||||
title = "Fast-forward merge",
|
||||
subtitle = "Try to fast-forward merges when possible",
|
||||
value = ffMerge,
|
||||
onValueChanged = { value ->
|
||||
appPreferences.ffMerge = value
|
||||
}
|
||||
)
|
||||
|
||||
TextButton(
|
||||
modifier = Modifier
|
||||
.padding(end = 8.dp)
|
||||
|
@ -129,7 +129,6 @@ fun Log(
|
||||
|
||||
LogDialogs(
|
||||
logViewModel,
|
||||
currentBranch = logStatus.currentBranch,
|
||||
onResetShowLogDialog = { logViewModel.showDialog(LogDialog.None) },
|
||||
showLogDialog = showLogDialog,
|
||||
)
|
||||
@ -179,6 +178,9 @@ fun Log(
|
||||
logViewModel = logViewModel,
|
||||
graphWidth = graphWidth,
|
||||
commitsLimit = logStatus.commitsLimit,
|
||||
onMerge = { ref ->
|
||||
logViewModel.mergeBranch(ref)
|
||||
},
|
||||
onRebase = { ref ->
|
||||
logViewModel.rebaseBranch(ref)
|
||||
},
|
||||
@ -367,6 +369,7 @@ fun MessagesList(
|
||||
commitList: GraphCommitList,
|
||||
logViewModel: LogViewModel,
|
||||
commitsLimit: Int,
|
||||
onMerge: (Ref) -> Unit,
|
||||
onRebase: (Ref) -> Unit,
|
||||
onShowLogDialog: (LogDialog) -> Unit,
|
||||
graphWidth: Dp,
|
||||
@ -404,8 +407,8 @@ fun MessagesList(
|
||||
showCreateNewBranch = { onShowLogDialog(LogDialog.NewBranch(graphNode)) },
|
||||
showCreateNewTag = { onShowLogDialog(LogDialog.NewTag(graphNode)) },
|
||||
resetBranch = { onShowLogDialog(LogDialog.ResetBranch(graphNode)) },
|
||||
onMergeBranch = { ref -> onShowLogDialog(LogDialog.MergeBranch(ref)) },
|
||||
onRebaseBranch = { ref -> onRebase(ref ) },
|
||||
onMergeBranch = onMerge,
|
||||
onRebaseBranch = onRebase,
|
||||
onRebaseInteractive = { logViewModel.rebaseInteractive(graphNode) },
|
||||
onRevCommitSelected = { logViewModel.selectLogLine(graphNode) },
|
||||
)
|
||||
@ -528,7 +531,6 @@ fun LogDialogs(
|
||||
logViewModel: LogViewModel,
|
||||
onResetShowLogDialog: () -> Unit,
|
||||
showLogDialog: LogDialog,
|
||||
currentBranch: Ref?,
|
||||
) {
|
||||
when (showLogDialog) {
|
||||
is LogDialog.NewBranch -> {
|
||||
@ -543,15 +545,6 @@ fun LogDialogs(
|
||||
onResetShowLogDialog()
|
||||
})
|
||||
}
|
||||
is LogDialog.MergeBranch -> {
|
||||
if (currentBranch != null) MergeDialog(currentBranchName = currentBranch.simpleName,
|
||||
mergeBranchName = showLogDialog.ref.simpleName,
|
||||
onReject = onResetShowLogDialog,
|
||||
onAccept = { ff ->
|
||||
logViewModel.mergeBranch(showLogDialog.ref, ff)
|
||||
onResetShowLogDialog()
|
||||
})
|
||||
}
|
||||
is LogDialog.ResetBranch -> ResetBranchDialog(onReject = onResetShowLogDialog, onAccept = { resetType ->
|
||||
logViewModel.resetToCommit(showLogDialog.graphNode, resetType)
|
||||
onResetShowLogDialog()
|
||||
|
@ -9,5 +9,4 @@ sealed class LogDialog {
|
||||
data class NewBranch(val graphNode: GraphNode) : LogDialog()
|
||||
data class NewTag(val graphNode: GraphNode) : LogDialog()
|
||||
data class ResetBranch(val graphNode: GraphNode) : LogDialog()
|
||||
data class MergeBranch(val ref: Ref) : LogDialog()
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package app.viewmodels
|
||||
|
||||
import app.git.*
|
||||
import app.preferences.AppPreferences
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import org.eclipse.jgit.api.Git
|
||||
@ -13,6 +14,7 @@ class BranchesViewModel @Inject constructor(
|
||||
private val mergeManager: MergeManager,
|
||||
private val remoteOperationsManager: RemoteOperationsManager,
|
||||
private val tabState: TabState,
|
||||
private val appPreferences: AppPreferences,
|
||||
) : ExpandableViewModel() {
|
||||
private val _branches = MutableStateFlow<List<Ref>>(listOf())
|
||||
val branches: StateFlow<List<Ref>>
|
||||
@ -46,10 +48,10 @@ class BranchesViewModel @Inject constructor(
|
||||
this.loadBranches(git)
|
||||
}
|
||||
|
||||
fun mergeBranch(ref: Ref, fastForward: Boolean) = tabState.safeProcessing(
|
||||
fun mergeBranch(ref: Ref) = tabState.safeProcessing(
|
||||
refreshType = RefreshType.ALL_DATA,
|
||||
) { git ->
|
||||
mergeManager.mergeBranch(git, ref, fastForward)
|
||||
mergeManager.mergeBranch(git, ref, appPreferences.ffMerge)
|
||||
}
|
||||
|
||||
fun deleteBranch(branch: Ref) = tabState.safeProcessing(
|
||||
|
@ -172,10 +172,10 @@ class LogViewModel @Inject constructor(
|
||||
tagsManager.createTagOnCommit(git, tag, revCommit)
|
||||
}
|
||||
|
||||
fun mergeBranch(ref: Ref, fastForward: Boolean) = tabState.safeProcessing(
|
||||
fun mergeBranch(ref: Ref) = tabState.safeProcessing(
|
||||
refreshType = RefreshType.ALL_DATA,
|
||||
) { git ->
|
||||
mergeManager.mergeBranch(git, ref, fastForward)
|
||||
mergeManager.mergeBranch(git, ref, appPreferences.ffMerge)
|
||||
}
|
||||
|
||||
fun deleteBranch(branch: Ref) = tabState.safeProcessing(
|
||||
|
Loading…
Reference in New Issue
Block a user