Prevent deletion of already mounted image

This commit is contained in:
2026-03-10 14:19:18 +05:00
parent 3a4acd9a16
commit 0157954d16
2 changed files with 37 additions and 7 deletions

View File

@@ -31,6 +31,7 @@ import sh.sar.isodroid.data.IsoFile
@Composable
fun FileContextMenu(
file: IsoFile,
isMounted: Boolean = false,
onDismiss: () -> Unit,
onRename: (String) -> Unit,
onDelete: () -> Unit
@@ -71,10 +72,28 @@ fun FileContextMenu(
},
text = {
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(
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",
onClick = { showRenameDialog = true }
enabled = !isMounted,
onClick = { if (!isMounted) showRenameDialog = true }
)
Spacer(modifier = Modifier.height(8.dp))
MenuItem(
@@ -82,12 +101,19 @@ fun FileContextMenu(
Icon(
Icons.Default.Delete,
contentDescription = null,
tint = MaterialTheme.colorScheme.error
tint = if (isMounted)
MaterialTheme.colorScheme.error.copy(alpha = 0.38f)
else
MaterialTheme.colorScheme.error
)
},
text = "Delete",
textColor = MaterialTheme.colorScheme.error,
onClick = { showDeleteConfirm = true }
textColor = if (isMounted)
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,
text: String,
textColor: androidx.compose.ui.graphics.Color = MaterialTheme.colorScheme.onSurface,
enabled: Boolean = true,
onClick: () -> Unit
) {
Row(
modifier = Modifier
.fillMaxWidth()
.clickable(onClick = onClick)
.clickable(enabled = enabled, onClick = onClick)
.padding(vertical = 12.dp, horizontal = 8.dp),
verticalAlignment = Alignment.CenterVertically
) {
@@ -120,7 +147,7 @@ private fun MenuItem(
Text(
text = text,
style = MaterialTheme.typography.bodyLarge,
color = textColor
color = if (enabled) textColor else textColor.copy(alpha = 0.38f)
)
}
}

View File

@@ -222,8 +222,11 @@ fun MainScreen(
// File context menu (long press)
contextMenuFile?.let { file ->
val isMounted = uiState.mountStatus.mounted &&
uiState.mountStatus.path == file.path
FileContextMenu(
file = file,
isMounted = isMounted,
onDismiss = { contextMenuFile = null },
onRename = { newName ->
viewModel.renameFile(file, newName)