Added new branch dialog
This commit is contained in:
parent
a4f0820857
commit
e718f10b60
@ -38,7 +38,8 @@ class BranchesManager @Inject constructor() {
|
||||
|
||||
suspend fun createBranch(git: Git, branchName: String) = withContext(Dispatchers.IO) {
|
||||
git
|
||||
.branchCreate()
|
||||
.checkout()
|
||||
.setCreateBranch(true)
|
||||
.setName(branchName)
|
||||
.call()
|
||||
|
||||
|
66
src/main/kotlin/app/git/dialogs/NewBranchDialog.kt
Normal file
66
src/main/kotlin/app/git/dialogs/NewBranchDialog.kt
Normal 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")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -28,9 +28,12 @@ fun GMenu(
|
||||
onPush: () -> Unit,
|
||||
onStash: () -> Unit,
|
||||
onPopStash: () -> Unit,
|
||||
onCreateBranch: () -> Unit,
|
||||
) {
|
||||
val openHovering = remember { mutableStateOf(false) }
|
||||
val pullHovering = remember { mutableStateOf(false) }
|
||||
val pushHovering = remember { mutableStateOf(false) }
|
||||
val branchHovering = remember { mutableStateOf(false) }
|
||||
|
||||
Row(
|
||||
modifier = Modifier
|
||||
@ -58,8 +61,21 @@ fun GMenu(
|
||||
)
|
||||
MenuButton(
|
||||
title = "Push",
|
||||
hovering = pushHovering,
|
||||
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(
|
||||
title = "Stash",
|
||||
|
@ -14,6 +14,7 @@ import androidx.compose.ui.window.Dialog
|
||||
import app.credentials.CredentialsState
|
||||
import app.git.DiffEntryType
|
||||
import app.git.GitManager
|
||||
import app.git.dialogs.NewBranchDialog
|
||||
import app.git.dialogs.UserPasswordDialog
|
||||
import openRepositoryDialog
|
||||
import org.eclipse.jgit.revwalk.RevCommit
|
||||
@ -32,6 +33,10 @@ fun RepositoryOpenPage(gitManager: GitManager) {
|
||||
mutableStateOf(false)
|
||||
}
|
||||
|
||||
var showBranchDialog by remember {
|
||||
mutableStateOf(false)
|
||||
}
|
||||
|
||||
val selectedIndexCommitLog = remember { mutableStateOf(-1) }
|
||||
|
||||
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 {
|
||||
GMenu(
|
||||
onRepositoryOpen = {
|
||||
@ -56,6 +72,7 @@ fun RepositoryOpenPage(gitManager: GitManager) {
|
||||
onPush = { gitManager.push() },
|
||||
onStash = { gitManager.stash() },
|
||||
onPopStash = { gitManager.popStash() },
|
||||
onCreateBranch = { showBranchDialog = true }
|
||||
)
|
||||
|
||||
Row {
|
||||
|
Loading…
Reference in New Issue
Block a user