Fixed enter key press triggering on button after being clicked by the user to accept the dialog
A common case was the commit button being triggered again after clicking on enter after the GPG signing
This commit is contained in:
parent
fcc0ef63bb
commit
26bc7bacf1
@ -1,17 +1,16 @@
|
|||||||
package com.jetpackduba.gitnuro.git
|
package com.jetpackduba.gitnuro.git
|
||||||
|
|
||||||
import com.jetpackduba.gitnuro.managers.ErrorsManager
|
|
||||||
import com.jetpackduba.gitnuro.di.TabScope
|
import com.jetpackduba.gitnuro.di.TabScope
|
||||||
import com.jetpackduba.gitnuro.extensions.delayedStateChange
|
import com.jetpackduba.gitnuro.extensions.delayedStateChange
|
||||||
import com.jetpackduba.gitnuro.git.log.FindCommitUseCase
|
import com.jetpackduba.gitnuro.git.log.FindCommitUseCase
|
||||||
import com.jetpackduba.gitnuro.logging.printError
|
import com.jetpackduba.gitnuro.logging.printError
|
||||||
|
import com.jetpackduba.gitnuro.managers.ErrorsManager
|
||||||
import com.jetpackduba.gitnuro.managers.newErrorNow
|
import com.jetpackduba.gitnuro.managers.newErrorNow
|
||||||
import com.jetpackduba.gitnuro.ui.SelectedItem
|
import com.jetpackduba.gitnuro.ui.SelectedItem
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.*
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import org.eclipse.jgit.lib.ObjectId
|
import org.eclipse.jgit.lib.ObjectId
|
||||||
import org.eclipse.jgit.lib.RepositoryState
|
|
||||||
import org.eclipse.jgit.revwalk.RevCommit
|
import org.eclipse.jgit.revwalk.RevCommit
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@ -70,6 +69,7 @@ class TabState @Inject constructor(
|
|||||||
this.unsafeGit = git
|
this.unsafeGit = git
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
fun safeProcessing(
|
fun safeProcessing(
|
||||||
showError: Boolean = true,
|
showError: Boolean = true,
|
||||||
refreshType: RefreshType,
|
refreshType: RefreshType,
|
||||||
@ -252,7 +252,7 @@ class TabState @Inject constructor(
|
|||||||
} else {
|
} else {
|
||||||
val commit = findCommitUseCase(git, objectId)
|
val commit = findCommitUseCase(git, objectId)
|
||||||
|
|
||||||
if(commit == null) {
|
if (commit == null) {
|
||||||
newSelectedItem(SelectedItem.None)
|
newSelectedItem(SelectedItem.None)
|
||||||
} else {
|
} else {
|
||||||
val newSelectedItem = SelectedItem.Ref(commit)
|
val newSelectedItem = SelectedItem.Ref(commit)
|
||||||
|
@ -104,5 +104,5 @@ fun KeyEvent.matchesBinding(keybindingOption: KeybindingOption): Boolean {
|
|||||||
keybinding.meta == this.isMetaPressed &&
|
keybinding.meta == this.isMetaPressed &&
|
||||||
keybinding.shift == this.isShiftPressed &&
|
keybinding.shift == this.isShiftPressed &&
|
||||||
keybinding.key == this.key
|
keybinding.key == this.key
|
||||||
}
|
} && this.type == KeyEventType.KeyDown
|
||||||
}
|
}
|
@ -6,9 +6,7 @@ import androidx.compose.animation.AnimatedVisibility
|
|||||||
import androidx.compose.animation.ExperimentalAnimationApi
|
import androidx.compose.animation.ExperimentalAnimationApi
|
||||||
import androidx.compose.animation.fadeIn
|
import androidx.compose.animation.fadeIn
|
||||||
import androidx.compose.animation.fadeOut
|
import androidx.compose.animation.fadeOut
|
||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
import androidx.compose.foundation.*
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.hoverable
|
|
||||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||||
import androidx.compose.foundation.interaction.collectIsHoveredAsState
|
import androidx.compose.foundation.interaction.collectIsHoveredAsState
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
@ -20,9 +18,11 @@ import androidx.compose.runtime.*
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.focus.FocusRequester
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.Shape
|
import androidx.compose.ui.graphics.Shape
|
||||||
|
import androidx.compose.ui.graphics.compositeOver
|
||||||
import androidx.compose.ui.input.key.onPreviewKeyEvent
|
import androidx.compose.ui.input.key.onPreviewKeyEvent
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
@ -379,12 +379,15 @@ fun MergeButtons(
|
|||||||
onMerge: () -> Unit,
|
onMerge: () -> Unit,
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.height(36.dp)
|
||||||
) {
|
) {
|
||||||
AbortButton(
|
AbortButton(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.weight(1f)
|
.weight(1f)
|
||||||
.padding(end = 4.dp),
|
.padding(end = 4.dp)
|
||||||
|
.fillMaxHeight(),
|
||||||
onClick = onAbort
|
onClick = onAbort
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -392,7 +395,8 @@ fun MergeButtons(
|
|||||||
text = "Merge",
|
text = "Merge",
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.weight(1f)
|
.weight(1f)
|
||||||
.padding(start = 4.dp),
|
.padding(start = 4.dp)
|
||||||
|
.fillMaxHeight(),
|
||||||
enabled = haveConflictsBeenSolved,
|
enabled = haveConflictsBeenSolved,
|
||||||
onClick = onMerge,
|
onClick = onMerge,
|
||||||
)
|
)
|
||||||
@ -406,12 +410,15 @@ fun CherryPickingButtons(
|
|||||||
onCommit: () -> Unit,
|
onCommit: () -> Unit,
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.height(36.dp)
|
||||||
) {
|
) {
|
||||||
AbortButton(
|
AbortButton(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.weight(1f)
|
.weight(1f)
|
||||||
.padding(end = 4.dp),
|
.padding(end = 4.dp)
|
||||||
|
.fillMaxHeight(),
|
||||||
onClick = onAbort
|
onClick = onAbort
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -419,7 +426,8 @@ fun CherryPickingButtons(
|
|||||||
text = "Commit",
|
text = "Commit",
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.weight(1f)
|
.weight(1f)
|
||||||
.padding(start = 4.dp),
|
.padding(start = 4.dp)
|
||||||
|
.fillMaxHeight(),
|
||||||
enabled = haveConflictsBeenSolved,
|
enabled = haveConflictsBeenSolved,
|
||||||
onClick = onCommit,
|
onClick = onCommit,
|
||||||
)
|
)
|
||||||
@ -447,12 +455,15 @@ fun RebasingButtons(
|
|||||||
}
|
}
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.height(36.dp)
|
||||||
) {
|
) {
|
||||||
AbortButton(
|
AbortButton(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.weight(1f)
|
.weight(1f)
|
||||||
.padding(end = 4.dp),
|
.padding(end = 4.dp)
|
||||||
|
.fillMaxHeight(),
|
||||||
onClick = onAbort
|
onClick = onAbort
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -461,7 +472,8 @@ fun RebasingButtons(
|
|||||||
text = "Continue",
|
text = "Continue",
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.weight(1f)
|
.weight(1f)
|
||||||
.padding(start = 4.dp),
|
.padding(start = 4.dp)
|
||||||
|
.fillMaxHeight(),
|
||||||
enabled = haveConflictsBeenSolved,
|
enabled = haveConflictsBeenSolved,
|
||||||
onClick = onContinue,
|
onClick = onContinue,
|
||||||
)
|
)
|
||||||
@ -470,7 +482,8 @@ fun RebasingButtons(
|
|||||||
text = "Skip",
|
text = "Skip",
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.weight(1f)
|
.weight(1f)
|
||||||
.padding(start = 4.dp),
|
.padding(start = 4.dp)
|
||||||
|
.fillMaxHeight(),
|
||||||
onClick = onSkip,
|
onClick = onSkip,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -486,7 +499,9 @@ fun RevertingButtons(
|
|||||||
onCommit: () -> Unit,
|
onCommit: () -> Unit,
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.height(36.dp)
|
||||||
) {
|
) {
|
||||||
AbortButton(
|
AbortButton(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@ -499,7 +514,8 @@ fun RevertingButtons(
|
|||||||
text = "Continue",
|
text = "Continue",
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.weight(1f)
|
.weight(1f)
|
||||||
.padding(start = 4.dp),
|
.padding(start = 4.dp)
|
||||||
|
.fillMaxHeight(),
|
||||||
enabled = canCommit && haveConflictsBeenSolved,
|
enabled = canCommit && haveConflictsBeenSolved,
|
||||||
onClick = onCommit,
|
onClick = onCommit,
|
||||||
)
|
)
|
||||||
@ -508,12 +524,13 @@ fun RevertingButtons(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun AbortButton(modifier: Modifier, onClick: () -> Unit) {
|
fun AbortButton(modifier: Modifier, onClick: () -> Unit) {
|
||||||
Button(
|
Box(
|
||||||
onClick = onClick,
|
modifier = modifier
|
||||||
modifier = modifier,
|
.clickable { onClick() }
|
||||||
colors = ButtonDefaults.buttonColors(
|
.focusable(false)
|
||||||
backgroundColor = MaterialTheme.colors.abortButton,
|
.clip(MaterialTheme.shapes.small)
|
||||||
)
|
.background(MaterialTheme.colors.abortButton),
|
||||||
|
contentAlignment = Alignment.Center,
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = "Abort",
|
text = "Abort",
|
||||||
@ -530,18 +547,24 @@ fun ConfirmationButton(
|
|||||||
shape: Shape = MaterialTheme.shapes.small,
|
shape: Shape = MaterialTheme.shapes.small,
|
||||||
onClick: () -> Unit,
|
onClick: () -> Unit,
|
||||||
) {
|
) {
|
||||||
Button(
|
val (backgroundColor, contentColor) = if (enabled) {
|
||||||
onClick = onClick,
|
(MaterialTheme.colors.primary to MaterialTheme.colors.onPrimary)
|
||||||
modifier = modifier,
|
} else {
|
||||||
enabled = enabled,
|
(MaterialTheme.colors.onSurface.copy(alpha = 0.12f)
|
||||||
shape = shape,
|
.compositeOver(MaterialTheme.colors.surface) to MaterialTheme.colors.onSurface.copy(alpha = ContentAlpha.disabled))
|
||||||
colors = ButtonDefaults.buttonColors(
|
}
|
||||||
backgroundColor = MaterialTheme.colors.primary,
|
|
||||||
)
|
Box(
|
||||||
|
modifier = modifier
|
||||||
|
.clickable { if (enabled) onClick() }
|
||||||
|
.focusable(false) // TODO this and the abort button should be focusable (show some kind of border when focused?)
|
||||||
|
.clip(shape)
|
||||||
|
.background(backgroundColor),
|
||||||
|
contentAlignment = Alignment.Center,
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = text,
|
text = text,
|
||||||
style = MaterialTheme.typography.body1.copy(color = MaterialTheme.colors.onPrimary),
|
style = MaterialTheme.typography.body1.copy(color = contentColor),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.jetpackduba.gitnuro.ui.components
|
package com.jetpackduba.gitnuro.ui.components
|
||||||
|
|
||||||
|
import androidx.compose.foundation.focusable
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
@ -20,6 +21,7 @@ fun PrimaryButton(
|
|||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
text: String,
|
text: String,
|
||||||
enabled: Boolean = true,
|
enabled: Boolean = true,
|
||||||
|
focusable: Boolean = true,
|
||||||
backgroundColor: Color = MaterialTheme.colors.primary,
|
backgroundColor: Color = MaterialTheme.colors.primary,
|
||||||
backgroundDisabled: Color = MaterialTheme.colors.primary.copy(0.5f),
|
backgroundDisabled: Color = MaterialTheme.colors.primary.copy(0.5f),
|
||||||
textColor: Color = MaterialTheme.colors.onPrimary,
|
textColor: Color = MaterialTheme.colors.onPrimary,
|
||||||
@ -30,6 +32,7 @@ fun PrimaryButton(
|
|||||||
modifier = modifier
|
modifier = modifier
|
||||||
.clip(RoundedCornerShape(4.dp))
|
.clip(RoundedCornerShape(4.dp))
|
||||||
.backgroundIf(enabled, backgroundColor, backgroundDisabled)
|
.backgroundIf(enabled, backgroundColor, backgroundDisabled)
|
||||||
|
.focusable(focusable)
|
||||||
.run {
|
.run {
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
handMouseClickable {
|
handMouseClickable {
|
||||||
|
Loading…
Reference in New Issue
Block a user