|
| 1 | +package cc.unitmesh.devins.idea.editor |
| 2 | + |
| 3 | +import androidx.compose.foundation.background |
| 4 | +import androidx.compose.foundation.layout.* |
| 5 | +import androidx.compose.runtime.* |
| 6 | +import androidx.compose.ui.Alignment |
| 7 | +import androidx.compose.ui.Modifier |
| 8 | +import androidx.compose.ui.text.font.FontWeight |
| 9 | +import androidx.compose.ui.unit.dp |
| 10 | +import androidx.compose.ui.unit.sp |
| 11 | +import cc.unitmesh.devins.ui.compose.theme.AutoDevColors |
| 12 | +import org.jetbrains.jewel.foundation.theme.JewelTheme |
| 13 | +import org.jetbrains.jewel.ui.component.* |
| 14 | + |
| 15 | +/** |
| 16 | + * Bottom toolbar for the input section. |
| 17 | + * Provides send/stop buttons, @ trigger for agent completion, settings, and token info. |
| 18 | + * |
| 19 | + * Uses Jewel components for native IntelliJ IDEA look and feel. |
| 20 | + */ |
| 21 | +@Composable |
| 22 | +fun IdeaBottomToolbar( |
| 23 | + onSendClick: () -> Unit, |
| 24 | + sendEnabled: Boolean, |
| 25 | + isExecuting: Boolean = false, |
| 26 | + onStopClick: () -> Unit = {}, |
| 27 | + onAtClick: () -> Unit = {}, |
| 28 | + onSettingsClick: () -> Unit = {}, |
| 29 | + workspacePath: String? = null, |
| 30 | + totalTokens: Int? = null, |
| 31 | + modifier: Modifier = Modifier |
| 32 | +) { |
| 33 | + Row( |
| 34 | + modifier = modifier |
| 35 | + .fillMaxWidth() |
| 36 | + .padding(horizontal = 8.dp, vertical = 6.dp), |
| 37 | + horizontalArrangement = Arrangement.SpaceBetween, |
| 38 | + verticalAlignment = Alignment.CenterVertically |
| 39 | + ) { |
| 40 | + // Left side: workspace and token info |
| 41 | + Row( |
| 42 | + horizontalArrangement = Arrangement.spacedBy(8.dp), |
| 43 | + verticalAlignment = Alignment.CenterVertically, |
| 44 | + modifier = Modifier.weight(1f, fill = false) |
| 45 | + ) { |
| 46 | + // Workspace indicator |
| 47 | + if (!workspacePath.isNullOrEmpty()) { |
| 48 | + // Extract project name from path, handling both Unix and Windows separators |
| 49 | + val projectName = workspacePath |
| 50 | + .replace('\\', '/') // Normalize to Unix separator |
| 51 | + .substringAfterLast('/') |
| 52 | + .ifEmpty { "Project" } |
| 53 | + |
| 54 | + Box( |
| 55 | + modifier = Modifier |
| 56 | + .background( |
| 57 | + JewelTheme.globalColors.panelBackground.copy(alpha = 0.8f) |
| 58 | + ) |
| 59 | + .padding(horizontal = 8.dp, vertical = 4.dp) |
| 60 | + ) { |
| 61 | + Row( |
| 62 | + verticalAlignment = Alignment.CenterVertically, |
| 63 | + horizontalArrangement = Arrangement.spacedBy(4.dp) |
| 64 | + ) { |
| 65 | + Text( |
| 66 | + text = "📁", |
| 67 | + style = JewelTheme.defaultTextStyle.copy(fontSize = 12.sp) |
| 68 | + ) |
| 69 | + Text( |
| 70 | + text = projectName, |
| 71 | + style = JewelTheme.defaultTextStyle.copy(fontSize = 12.sp), |
| 72 | + maxLines = 1 |
| 73 | + ) |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + // Token usage indicator |
| 79 | + if (totalTokens != null && totalTokens > 0) { |
| 80 | + Box( |
| 81 | + modifier = Modifier |
| 82 | + .background(AutoDevColors.Blue.c400.copy(alpha = 0.2f)) |
| 83 | + .padding(horizontal = 8.dp, vertical = 4.dp) |
| 84 | + ) { |
| 85 | + Row( |
| 86 | + verticalAlignment = Alignment.CenterVertically, |
| 87 | + horizontalArrangement = Arrangement.spacedBy(4.dp) |
| 88 | + ) { |
| 89 | + Text( |
| 90 | + text = "Token", |
| 91 | + style = JewelTheme.defaultTextStyle.copy(fontSize = 11.sp) |
| 92 | + ) |
| 93 | + Text( |
| 94 | + text = "$totalTokens", |
| 95 | + style = JewelTheme.defaultTextStyle.copy( |
| 96 | + fontSize = 11.sp, |
| 97 | + fontWeight = FontWeight.Bold |
| 98 | + ) |
| 99 | + ) |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | + } |
| 104 | + |
| 105 | + // Right side: action buttons |
| 106 | + Row( |
| 107 | + horizontalArrangement = Arrangement.spacedBy(4.dp), |
| 108 | + verticalAlignment = Alignment.CenterVertically |
| 109 | + ) { |
| 110 | + // @ trigger button for agent completion |
| 111 | + IconButton( |
| 112 | + onClick = onAtClick, |
| 113 | + modifier = Modifier.size(32.dp) |
| 114 | + ) { |
| 115 | + Text( |
| 116 | + text = "@", |
| 117 | + style = JewelTheme.defaultTextStyle.copy( |
| 118 | + fontSize = 16.sp, |
| 119 | + fontWeight = FontWeight.Bold |
| 120 | + ) |
| 121 | + ) |
| 122 | + } |
| 123 | + |
| 124 | + // Settings button |
| 125 | + IconButton( |
| 126 | + onClick = onSettingsClick, |
| 127 | + modifier = Modifier.size(32.dp) |
| 128 | + ) { |
| 129 | + Text( |
| 130 | + text = "⚙", |
| 131 | + style = JewelTheme.defaultTextStyle.copy(fontSize = 14.sp) |
| 132 | + ) |
| 133 | + } |
| 134 | + |
| 135 | + // Send or Stop button |
| 136 | + if (isExecuting) { |
| 137 | + DefaultButton( |
| 138 | + onClick = onStopClick, |
| 139 | + modifier = Modifier.height(32.dp) |
| 140 | + ) { |
| 141 | + Text( |
| 142 | + text = "⏹ Stop", |
| 143 | + style = JewelTheme.defaultTextStyle.copy( |
| 144 | + color = AutoDevColors.Red.c400 |
| 145 | + ) |
| 146 | + ) |
| 147 | + } |
| 148 | + } else { |
| 149 | + DefaultButton( |
| 150 | + onClick = onSendClick, |
| 151 | + enabled = sendEnabled, |
| 152 | + modifier = Modifier.height(32.dp) |
| 153 | + ) { |
| 154 | + Text( |
| 155 | + text = "Send", |
| 156 | + style = JewelTheme.defaultTextStyle |
| 157 | + ) |
| 158 | + } |
| 159 | + } |
| 160 | + } |
| 161 | + } |
| 162 | +} |
| 163 | + |
0 commit comments