Added new branch dialog

This commit is contained in:
Abdelilah El Aissaoui 2021-10-25 02:01:53 +02:00
parent a4f0820857
commit e718f10b60
4 changed files with 102 additions and 2 deletions

View File

@ -38,7 +38,8 @@ class BranchesManager @Inject constructor() {
suspend fun createBranch(git: Git, branchName: String) = withContext(Dispatchers.IO) { suspend fun createBranch(git: Git, branchName: String) = withContext(Dispatchers.IO) {
git git
.branchCreate() .checkout()
.setCreateBranch(true)
.setName(branchName) .setName(branchName)
.call() .call()

View File

@ -0,0 +1,66 @@
package app.git.dialogs
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Button
import androidx.compose.material.OutlinedTextField
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusOrder
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.rememberDialogState
@Composable
fun NewBranchDialog(
onReject: () -> Unit,
onAccept: (branchName: String) -> Unit
) {
var branchField by remember { mutableStateOf("") }
val userFieldFocusRequester = remember { FocusRequester() }
val buttonFieldFocusRequester = remember { FocusRequester() }
Dialog(
state = rememberDialogState(width = 0.dp, height = 0.dp),
onCloseRequest = onReject,
title = "",
) {
Column(
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
) {
Text("Enter a branch name")
OutlinedTextField(
modifier = Modifier.focusOrder(userFieldFocusRequester) {
this.next = buttonFieldFocusRequester
},
value = branchField,
label = { Text("User", fontSize = 14.sp) },
textStyle = TextStyle(fontSize = 14.sp),
onValueChange = {
branchField = it
},
)
Button(
modifier = Modifier.focusOrder(buttonFieldFocusRequester) {
this.previous = userFieldFocusRequester
this.next = userFieldFocusRequester
},
onClick = {
onAccept(branchField)
}
) {
Text("Create branch")
}
}
}
}

View File

@ -28,9 +28,12 @@ fun GMenu(
onPush: () -> Unit, onPush: () -> Unit,
onStash: () -> Unit, onStash: () -> Unit,
onPopStash: () -> Unit, onPopStash: () -> Unit,
onCreateBranch: () -> Unit,
) { ) {
val openHovering = remember { mutableStateOf(false) } val openHovering = remember { mutableStateOf(false) }
val pullHovering = remember { mutableStateOf(false) } val pullHovering = remember { mutableStateOf(false) }
val pushHovering = remember { mutableStateOf(false) }
val branchHovering = remember { mutableStateOf(false) }
Row( Row(
modifier = Modifier modifier = Modifier
@ -58,8 +61,21 @@ fun GMenu(
) )
MenuButton( MenuButton(
title = "Push", title = "Push",
hovering = pushHovering,
icon = painterResource("upload.svg"), icon = painterResource("upload.svg"),
onClick = onPush, onClick = {
pushHovering.value = false
onPush()
},
)
MenuButton(
title = "Branch",
hovering = branchHovering,
icon = painterResource("branch.svg"),
onClick = {
branchHovering.value = false
onCreateBranch()
},
) )
MenuButton( MenuButton(
title = "Stash", title = "Stash",

View File

@ -14,6 +14,7 @@ import androidx.compose.ui.window.Dialog
import app.credentials.CredentialsState import app.credentials.CredentialsState
import app.git.DiffEntryType import app.git.DiffEntryType
import app.git.GitManager import app.git.GitManager
import app.git.dialogs.NewBranchDialog
import app.git.dialogs.UserPasswordDialog import app.git.dialogs.UserPasswordDialog
import openRepositoryDialog import openRepositoryDialog
import org.eclipse.jgit.revwalk.RevCommit import org.eclipse.jgit.revwalk.RevCommit
@ -32,6 +33,10 @@ fun RepositoryOpenPage(gitManager: GitManager) {
mutableStateOf(false) mutableStateOf(false)
} }
var showBranchDialog by remember {
mutableStateOf(false)
}
val selectedIndexCommitLog = remember { mutableStateOf(-1) } val selectedIndexCommitLog = remember { mutableStateOf(-1) }
val credentialsState by gitManager.credentialsState.collectAsState() val credentialsState by gitManager.credentialsState.collectAsState()
@ -47,6 +52,17 @@ fun RepositoryOpenPage(gitManager: GitManager) {
) )
} }
if (showBranchDialog) {
NewBranchDialog(
onReject = {
showBranchDialog = false
},
onAccept = { branchName ->
gitManager.createBranch(branchName)
}
)
}
Column { Column {
GMenu( GMenu(
onRepositoryOpen = { onRepositoryOpen = {
@ -56,6 +72,7 @@ fun RepositoryOpenPage(gitManager: GitManager) {
onPush = { gitManager.push() }, onPush = { gitManager.push() },
onStash = { gitManager.stash() }, onStash = { gitManager.stash() },
onPopStash = { gitManager.popStash() }, onPopStash = { gitManager.popStash() },
onCreateBranch = { showBranchDialog = true }
) )
Row { Row {