Removed merge dialog. Fast forward config is now in the settings

This commit is contained in:
Abdelilah El Aissaoui 2022-06-24 19:42:01 +02:00
parent 7ce311d9b5
commit befc7d1740
8 changed files with 42 additions and 141 deletions

View File

@ -24,6 +24,9 @@ private const val PREF_COMMITS_LIMIT_ENABLED = "commitsLimitEnabled"
private const val PREF_WINDOW_PLACEMENT = "windowsPlacement" private const val PREF_WINDOW_PLACEMENT = "windowsPlacement"
private const val PREF_CUSTOM_THEME = "customTheme" 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 = 1000
private const val DEFAULT_COMMITS_LIMIT_ENABLED = true private const val DEFAULT_COMMITS_LIMIT_ENABLED = true
@ -34,9 +37,12 @@ class AppPreferences @Inject constructor() {
private val _themeState = MutableStateFlow(theme) private val _themeState = MutableStateFlow(theme)
val themeState: StateFlow<Themes> = _themeState val themeState: StateFlow<Themes> = _themeState
private val _commitsLimitEnabledFlow = MutableStateFlow(true) private val _commitsLimitEnabledFlow = MutableStateFlow(commitsLimitEnabled)
val commitsLimitEnabledFlow: StateFlow<Boolean> = _commitsLimitEnabledFlow val commitsLimitEnabledFlow: StateFlow<Boolean> = _commitsLimitEnabledFlow
private val _ffMergeFlow = MutableStateFlow(ffMerge)
val ffMergeFlow: StateFlow<Boolean> = _ffMergeFlow
private val _commitsLimitFlow = MutableStateFlow(commitsLimit) private val _commitsLimitFlow = MutableStateFlow(commitsLimit)
val commitsLimitFlow: StateFlow<Int> = _commitsLimitFlow val commitsLimitFlow: StateFlow<Int> = _commitsLimitFlow
@ -79,6 +85,18 @@ class AppPreferences @Inject constructor() {
_commitsLimitEnabledFlow.value = value _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 var commitsLimit: Int
get() { get() {
return preferences.getInt(PREF_COMMITS_LIMIT, DEFAULT_COMMITS_LIMIT) return preferences.getInt(PREF_COMMITS_LIMIT, DEFAULT_COMMITS_LIMIT)

View File

@ -14,7 +14,6 @@ import app.extensions.simpleName
import app.ui.components.SideMenuPanel import app.ui.components.SideMenuPanel
import app.ui.components.SideMenuSubentry import app.ui.components.SideMenuSubentry
import app.ui.context_menu.branchContextMenuItems import app.ui.context_menu.branchContextMenuItems
import app.ui.dialogs.MergeDialog
import app.viewmodels.BranchesViewModel import app.viewmodels.BranchesViewModel
import org.eclipse.jgit.lib.Ref import org.eclipse.jgit.lib.Ref
@ -28,8 +27,6 @@ fun Branches(
val isExpanded by branchesViewModel.isExpanded.collectAsState() val isExpanded by branchesViewModel.isExpanded.collectAsState()
val currentBranch = currentBranchState.value val currentBranch = currentBranchState.value
val (mergeBranch, setMergeBranch) = remember { mutableStateOf<Ref?>(null) }
SideMenuPanel( SideMenuPanel(
title = "Local branches", title = "Local branches",
icon = painterResource("branch.svg"), icon = painterResource("branch.svg"),
@ -44,7 +41,7 @@ fun Branches(
onBranchClicked = { branchesViewModel.selectBranch(branch) }, onBranchClicked = { branchesViewModel.selectBranch(branch) },
onBranchDoubleClicked = { branchesViewModel.checkoutRef(branch) }, onBranchDoubleClicked = { branchesViewModel.checkoutRef(branch) },
onCheckoutBranch = { branchesViewModel.checkoutRef(branch) }, onCheckoutBranch = { branchesViewModel.checkoutRef(branch) },
onMergeBranch = { setMergeBranch(branch) }, onMergeBranch = { branchesViewModel.mergeBranch(branch) },
onDeleteBranch = { branchesViewModel.deleteBranch(branch) }, onDeleteBranch = { branchesViewModel.deleteBranch(branch) },
onRebaseBranch = { branchesViewModel.rebaseBranch(branch) }, onRebaseBranch = { branchesViewModel.rebaseBranch(branch) },
onPushToRemoteBranch = { branchesViewModel.pushToRemoteBranch(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) @OptIn(ExperimentalFoundationApi::class)

View File

@ -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"
)
}
}
}
}

View File

@ -25,6 +25,7 @@ fun SettingsDialog(
) { ) {
val currentTheme by appPreferences.themeState.collectAsState() val currentTheme by appPreferences.themeState.collectAsState()
val commitsLimitEnabled by appPreferences.commitsLimitEnabledFlow.collectAsState() val commitsLimitEnabled by appPreferences.commitsLimitEnabledFlow.collectAsState()
val ffMerge by appPreferences.ffMergeFlow.collectAsState()
var commitsLimit by remember { mutableStateOf(appPreferences.commitsLimit) } var commitsLimit by remember { mutableStateOf(appPreferences.commitsLimit) }
MaterialDialog( 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( TextButton(
modifier = Modifier modifier = Modifier
.padding(end = 8.dp) .padding(end = 8.dp)

View File

@ -129,7 +129,6 @@ fun Log(
LogDialogs( LogDialogs(
logViewModel, logViewModel,
currentBranch = logStatus.currentBranch,
onResetShowLogDialog = { logViewModel.showDialog(LogDialog.None) }, onResetShowLogDialog = { logViewModel.showDialog(LogDialog.None) },
showLogDialog = showLogDialog, showLogDialog = showLogDialog,
) )
@ -179,6 +178,9 @@ fun Log(
logViewModel = logViewModel, logViewModel = logViewModel,
graphWidth = graphWidth, graphWidth = graphWidth,
commitsLimit = logStatus.commitsLimit, commitsLimit = logStatus.commitsLimit,
onMerge = { ref ->
logViewModel.mergeBranch(ref)
},
onRebase = { ref -> onRebase = { ref ->
logViewModel.rebaseBranch(ref) logViewModel.rebaseBranch(ref)
}, },
@ -367,6 +369,7 @@ fun MessagesList(
commitList: GraphCommitList, commitList: GraphCommitList,
logViewModel: LogViewModel, logViewModel: LogViewModel,
commitsLimit: Int, commitsLimit: Int,
onMerge: (Ref) -> Unit,
onRebase: (Ref) -> Unit, onRebase: (Ref) -> Unit,
onShowLogDialog: (LogDialog) -> Unit, onShowLogDialog: (LogDialog) -> Unit,
graphWidth: Dp, graphWidth: Dp,
@ -404,8 +407,8 @@ fun MessagesList(
showCreateNewBranch = { onShowLogDialog(LogDialog.NewBranch(graphNode)) }, showCreateNewBranch = { onShowLogDialog(LogDialog.NewBranch(graphNode)) },
showCreateNewTag = { onShowLogDialog(LogDialog.NewTag(graphNode)) }, showCreateNewTag = { onShowLogDialog(LogDialog.NewTag(graphNode)) },
resetBranch = { onShowLogDialog(LogDialog.ResetBranch(graphNode)) }, resetBranch = { onShowLogDialog(LogDialog.ResetBranch(graphNode)) },
onMergeBranch = { ref -> onShowLogDialog(LogDialog.MergeBranch(ref)) }, onMergeBranch = onMerge,
onRebaseBranch = { ref -> onRebase(ref ) }, onRebaseBranch = onRebase,
onRebaseInteractive = { logViewModel.rebaseInteractive(graphNode) }, onRebaseInteractive = { logViewModel.rebaseInteractive(graphNode) },
onRevCommitSelected = { logViewModel.selectLogLine(graphNode) }, onRevCommitSelected = { logViewModel.selectLogLine(graphNode) },
) )
@ -528,7 +531,6 @@ fun LogDialogs(
logViewModel: LogViewModel, logViewModel: LogViewModel,
onResetShowLogDialog: () -> Unit, onResetShowLogDialog: () -> Unit,
showLogDialog: LogDialog, showLogDialog: LogDialog,
currentBranch: Ref?,
) { ) {
when (showLogDialog) { when (showLogDialog) {
is LogDialog.NewBranch -> { is LogDialog.NewBranch -> {
@ -543,15 +545,6 @@ fun LogDialogs(
onResetShowLogDialog() 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 -> is LogDialog.ResetBranch -> ResetBranchDialog(onReject = onResetShowLogDialog, onAccept = { resetType ->
logViewModel.resetToCommit(showLogDialog.graphNode, resetType) logViewModel.resetToCommit(showLogDialog.graphNode, resetType)
onResetShowLogDialog() onResetShowLogDialog()

View File

@ -9,5 +9,4 @@ sealed class LogDialog {
data class NewBranch(val graphNode: GraphNode) : LogDialog() data class NewBranch(val graphNode: GraphNode) : LogDialog()
data class NewTag(val graphNode: GraphNode) : LogDialog() data class NewTag(val graphNode: GraphNode) : LogDialog()
data class ResetBranch(val graphNode: GraphNode) : LogDialog() data class ResetBranch(val graphNode: GraphNode) : LogDialog()
data class MergeBranch(val ref: Ref) : LogDialog()
} }

View File

@ -1,6 +1,7 @@
package app.viewmodels package app.viewmodels
import app.git.* import app.git.*
import app.preferences.AppPreferences
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import org.eclipse.jgit.api.Git import org.eclipse.jgit.api.Git
@ -13,6 +14,7 @@ class BranchesViewModel @Inject constructor(
private val mergeManager: MergeManager, private val mergeManager: MergeManager,
private val remoteOperationsManager: RemoteOperationsManager, private val remoteOperationsManager: RemoteOperationsManager,
private val tabState: TabState, private val tabState: TabState,
private val appPreferences: AppPreferences,
) : ExpandableViewModel() { ) : ExpandableViewModel() {
private val _branches = MutableStateFlow<List<Ref>>(listOf()) private val _branches = MutableStateFlow<List<Ref>>(listOf())
val branches: StateFlow<List<Ref>> val branches: StateFlow<List<Ref>>
@ -46,10 +48,10 @@ class BranchesViewModel @Inject constructor(
this.loadBranches(git) this.loadBranches(git)
} }
fun mergeBranch(ref: Ref, fastForward: Boolean) = tabState.safeProcessing( fun mergeBranch(ref: Ref) = tabState.safeProcessing(
refreshType = RefreshType.ALL_DATA, refreshType = RefreshType.ALL_DATA,
) { git -> ) { git ->
mergeManager.mergeBranch(git, ref, fastForward) mergeManager.mergeBranch(git, ref, appPreferences.ffMerge)
} }
fun deleteBranch(branch: Ref) = tabState.safeProcessing( fun deleteBranch(branch: Ref) = tabState.safeProcessing(

View File

@ -172,10 +172,10 @@ class LogViewModel @Inject constructor(
tagsManager.createTagOnCommit(git, tag, revCommit) tagsManager.createTagOnCommit(git, tag, revCommit)
} }
fun mergeBranch(ref: Ref, fastForward: Boolean) = tabState.safeProcessing( fun mergeBranch(ref: Ref) = tabState.safeProcessing(
refreshType = RefreshType.ALL_DATA, refreshType = RefreshType.ALL_DATA,
) { git -> ) { git ->
mergeManager.mergeBranch(git, ref, fastForward) mergeManager.mergeBranch(git, ref, appPreferences.ffMerge)
} }
fun deleteBranch(branch: Ref) = tabState.safeProcessing( fun deleteBranch(branch: Ref) = tabState.safeProcessing(