Prevent deletion of already mounted image
This commit is contained in:
@@ -31,6 +31,7 @@ import sh.sar.isodroid.data.IsoFile
|
|||||||
@Composable
|
@Composable
|
||||||
fun FileContextMenu(
|
fun FileContextMenu(
|
||||||
file: IsoFile,
|
file: IsoFile,
|
||||||
|
isMounted: Boolean = false,
|
||||||
onDismiss: () -> Unit,
|
onDismiss: () -> Unit,
|
||||||
onRename: (String) -> Unit,
|
onRename: (String) -> Unit,
|
||||||
onDelete: () -> Unit
|
onDelete: () -> Unit
|
||||||
@@ -71,10 +72,28 @@ fun FileContextMenu(
|
|||||||
},
|
},
|
||||||
text = {
|
text = {
|
||||||
Column {
|
Column {
|
||||||
|
if (isMounted) {
|
||||||
|
Text(
|
||||||
|
text = "This file is currently mounted. Unmount it first to rename or delete.",
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.error,
|
||||||
|
modifier = Modifier.padding(vertical = 8.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
MenuItem(
|
MenuItem(
|
||||||
icon = { Icon(Icons.Default.Edit, contentDescription = null) },
|
icon = {
|
||||||
|
Icon(
|
||||||
|
Icons.Default.Edit,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = if (isMounted)
|
||||||
|
MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f)
|
||||||
|
else
|
||||||
|
MaterialTheme.colorScheme.onSurface
|
||||||
|
)
|
||||||
|
},
|
||||||
text = "Rename",
|
text = "Rename",
|
||||||
onClick = { showRenameDialog = true }
|
enabled = !isMounted,
|
||||||
|
onClick = { if (!isMounted) showRenameDialog = true }
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
MenuItem(
|
MenuItem(
|
||||||
@@ -82,12 +101,19 @@ fun FileContextMenu(
|
|||||||
Icon(
|
Icon(
|
||||||
Icons.Default.Delete,
|
Icons.Default.Delete,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
tint = MaterialTheme.colorScheme.error
|
tint = if (isMounted)
|
||||||
|
MaterialTheme.colorScheme.error.copy(alpha = 0.38f)
|
||||||
|
else
|
||||||
|
MaterialTheme.colorScheme.error
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
text = "Delete",
|
text = "Delete",
|
||||||
textColor = MaterialTheme.colorScheme.error,
|
textColor = if (isMounted)
|
||||||
onClick = { showDeleteConfirm = true }
|
MaterialTheme.colorScheme.error.copy(alpha = 0.38f)
|
||||||
|
else
|
||||||
|
MaterialTheme.colorScheme.error,
|
||||||
|
enabled = !isMounted,
|
||||||
|
onClick = { if (!isMounted) showDeleteConfirm = true }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -106,12 +132,13 @@ private fun MenuItem(
|
|||||||
icon: @Composable () -> Unit,
|
icon: @Composable () -> Unit,
|
||||||
text: String,
|
text: String,
|
||||||
textColor: androidx.compose.ui.graphics.Color = MaterialTheme.colorScheme.onSurface,
|
textColor: androidx.compose.ui.graphics.Color = MaterialTheme.colorScheme.onSurface,
|
||||||
|
enabled: Boolean = true,
|
||||||
onClick: () -> Unit
|
onClick: () -> Unit
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.clickable(onClick = onClick)
|
.clickable(enabled = enabled, onClick = onClick)
|
||||||
.padding(vertical = 12.dp, horizontal = 8.dp),
|
.padding(vertical = 12.dp, horizontal = 8.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
@@ -120,7 +147,7 @@ private fun MenuItem(
|
|||||||
Text(
|
Text(
|
||||||
text = text,
|
text = text,
|
||||||
style = MaterialTheme.typography.bodyLarge,
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
color = textColor
|
color = if (enabled) textColor else textColor.copy(alpha = 0.38f)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -222,8 +222,11 @@ fun MainScreen(
|
|||||||
|
|
||||||
// File context menu (long press)
|
// File context menu (long press)
|
||||||
contextMenuFile?.let { file ->
|
contextMenuFile?.let { file ->
|
||||||
|
val isMounted = uiState.mountStatus.mounted &&
|
||||||
|
uiState.mountStatus.path == file.path
|
||||||
FileContextMenu(
|
FileContextMenu(
|
||||||
file = file,
|
file = file,
|
||||||
|
isMounted = isMounted,
|
||||||
onDismiss = { contextMenuFile = null },
|
onDismiss = { contextMenuFile = null },
|
||||||
onRename = { newName ->
|
onRename = { newName ->
|
||||||
viewModel.renameFile(file, newName)
|
viewModel.renameFile(file, newName)
|
||||||
|
|||||||
Reference in New Issue
Block a user