Certain menu icons are now enabled only if there is an open repository
This commit is contained in:
parent
87b5b49291
commit
ef39c6f6d5
@ -82,8 +82,6 @@ class StatusManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun reset(git: Git, diffEntry: DiffEntry, staged: Boolean) = withContext(Dispatchers.IO) {
|
suspend fun reset(git: Git, diffEntry: DiffEntry, staged: Boolean) = withContext(Dispatchers.IO) {
|
||||||
println("Staged $staged")
|
|
||||||
|
|
||||||
if(staged) {
|
if(staged) {
|
||||||
git
|
git
|
||||||
.reset()
|
.reset()
|
||||||
|
@ -7,6 +7,7 @@ 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.graphics.Color
|
||||||
import androidx.compose.ui.graphics.ColorFilter
|
import androidx.compose.ui.graphics.ColorFilter
|
||||||
import androidx.compose.ui.graphics.painter.Painter
|
import androidx.compose.ui.graphics.painter.Painter
|
||||||
import androidx.compose.ui.input.pointer.pointerMoveFilter
|
import androidx.compose.ui.input.pointer.pointerMoveFilter
|
||||||
@ -15,10 +16,7 @@ import androidx.compose.ui.unit.dp
|
|||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.compose.ui.window.*
|
import androidx.compose.ui.window.*
|
||||||
import theme.*
|
import theme.*
|
||||||
import java.awt.FileDialog
|
|
||||||
import java.awt.Frame
|
|
||||||
import javax.swing.JFileChooser
|
import javax.swing.JFileChooser
|
||||||
import javax.swing.UIManager
|
|
||||||
|
|
||||||
|
|
||||||
@OptIn(ExperimentalComposeUiApi::class)
|
@OptIn(ExperimentalComposeUiApi::class)
|
||||||
@ -32,7 +30,7 @@ fun main() = application {
|
|||||||
isOpen = false
|
isOpen = false
|
||||||
},
|
},
|
||||||
state = rememberWindowState(placement = WindowPlacement.Maximized, size = WindowSize(1280.dp, 720.dp))
|
state = rememberWindowState(placement = WindowPlacement.Maximized, size = WindowSize(1280.dp, 720.dp))
|
||||||
) {
|
) {
|
||||||
GitnuroTheme {
|
GitnuroTheme {
|
||||||
Gitnuro(gitManager)
|
Gitnuro(gitManager)
|
||||||
}
|
}
|
||||||
@ -66,6 +64,7 @@ fun Gitnuro(gitManager: GitManager) {
|
|||||||
onPush = { gitManager.push() },
|
onPush = { gitManager.push() },
|
||||||
onStash = { gitManager.stash() },
|
onStash = { gitManager.stash() },
|
||||||
onPopStash = { gitManager.popStash() },
|
onPopStash = { gitManager.popStash() },
|
||||||
|
isRepositoryOpen = repositorySelectionStatus is RepositorySelectionStatus.Open
|
||||||
)
|
)
|
||||||
|
|
||||||
Crossfade(targetState = repositorySelectionStatus) {
|
Crossfade(targetState = repositorySelectionStatus) {
|
||||||
@ -106,11 +105,14 @@ fun NoneRepository() {
|
|||||||
@Composable
|
@Composable
|
||||||
fun GMenu(
|
fun GMenu(
|
||||||
onRepositoryOpen: () -> Unit,
|
onRepositoryOpen: () -> Unit,
|
||||||
|
isRepositoryOpen: Boolean,
|
||||||
onPull: () -> Unit,
|
onPull: () -> Unit,
|
||||||
onPush: () -> Unit,
|
onPush: () -> Unit,
|
||||||
onStash: () -> Unit,
|
onStash: () -> Unit,
|
||||||
onPopStash: () -> Unit,
|
onPopStash: () -> Unit,
|
||||||
) {
|
) {
|
||||||
|
val openHovering = remember { mutableStateOf(false) }
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(vertical = 16.dp)
|
.padding(vertical = 16.dp)
|
||||||
@ -119,58 +121,79 @@ fun GMenu(
|
|||||||
) {
|
) {
|
||||||
MenuButton(
|
MenuButton(
|
||||||
title = "Open",
|
title = "Open",
|
||||||
|
hovering = openHovering,
|
||||||
icon = painterResource("open.svg"),
|
icon = painterResource("open.svg"),
|
||||||
onClick = onRepositoryOpen
|
onClick = {
|
||||||
|
openHovering.value = false // Without this, the hover would be kept because of the newly opened dialog
|
||||||
|
onRepositoryOpen()
|
||||||
|
}
|
||||||
)
|
)
|
||||||
MenuButton(
|
MenuButton(
|
||||||
title = "Pull",
|
title = "Pull",
|
||||||
icon = painterResource("download.svg"),
|
icon = painterResource("download.svg"),
|
||||||
onClick = onPull,
|
onClick = onPull,
|
||||||
|
enabled = isRepositoryOpen,
|
||||||
)
|
)
|
||||||
MenuButton(
|
MenuButton(
|
||||||
title = "Push",
|
title = "Push",
|
||||||
icon = painterResource("upload.svg"),
|
icon = painterResource("upload.svg"),
|
||||||
onClick = onPush,
|
onClick = onPush,
|
||||||
|
enabled = isRepositoryOpen,
|
||||||
)
|
)
|
||||||
MenuButton(
|
MenuButton(
|
||||||
title = "Stash",
|
title = "Stash",
|
||||||
icon = painterResource("stash.svg"),
|
icon = painterResource("stash.svg"),
|
||||||
onClick = onStash,
|
onClick = onStash,
|
||||||
|
enabled = isRepositoryOpen,
|
||||||
)
|
)
|
||||||
MenuButton(
|
MenuButton(
|
||||||
title = "Apply",
|
title = "Apply",
|
||||||
icon = painterResource("apply_stash.svg"),
|
icon = painterResource("apply_stash.svg"),
|
||||||
onClick = onPopStash,
|
onClick = onPopStash,
|
||||||
|
enabled = isRepositoryOpen,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun MenuButton(modifier: Modifier = Modifier, title: String, icon: Painter, onClick: () -> Unit) {
|
fun MenuButton(
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
var hovering by remember { mutableStateOf(false) }
|
enabled: Boolean = true,
|
||||||
|
hovering: MutableState<Boolean> = remember { mutableStateOf(false) },
|
||||||
val backgroundColor = if(hovering)
|
title: String,
|
||||||
|
icon: Painter,
|
||||||
|
onClick: () -> Unit
|
||||||
|
) {
|
||||||
|
val backgroundColor = if (hovering.value)
|
||||||
MaterialTheme.colors.primary.copy(alpha = 0.15F)
|
MaterialTheme.colors.primary.copy(alpha = 0.15F)
|
||||||
else
|
else
|
||||||
MaterialTheme.colors.primary.copy(alpha = 0F)
|
Color.Transparent
|
||||||
|
|
||||||
|
val iconColor = if (enabled) {
|
||||||
|
MaterialTheme.colors.primary
|
||||||
|
} else {
|
||||||
|
MaterialTheme.colors.secondaryVariant
|
||||||
|
}
|
||||||
|
|
||||||
TextButton(
|
TextButton(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.padding(horizontal = 2.dp)
|
.padding(horizontal = 2.dp)
|
||||||
.pointerMoveFilter(
|
.pointerMoveFilter(
|
||||||
onEnter = {
|
onEnter = {
|
||||||
hovering = true
|
hovering.value = true
|
||||||
false
|
false
|
||||||
},
|
},
|
||||||
onExit = {
|
onExit = {
|
||||||
hovering = false
|
hovering.value = false
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
)
|
),
|
||||||
,
|
enabled = enabled,
|
||||||
onClick = onClick,
|
onClick = onClick,
|
||||||
colors = ButtonDefaults.buttonColors(backgroundColor = backgroundColor)
|
colors = ButtonDefaults.buttonColors(
|
||||||
|
backgroundColor = backgroundColor,
|
||||||
|
disabledBackgroundColor = Color.Transparent
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
||||||
Image(
|
Image(
|
||||||
@ -179,7 +202,7 @@ fun MenuButton(modifier: Modifier = Modifier, title: String, icon: Painter, onCl
|
|||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(4.dp)
|
.padding(4.dp)
|
||||||
.size(24.dp),
|
.size(24.dp),
|
||||||
colorFilter = ColorFilter.tint(MaterialTheme.colors.primary),
|
colorFilter = ColorFilter.tint(iconColor),
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = title,
|
text = title,
|
||||||
|
Loading…
Reference in New Issue
Block a user