Skip to content

Commit 15a4970

Browse files
committed
refactor(devti): optimize task section and step panel layout
- Adjusted spacing and padding for a more compact view - Improved title and text truncation for better readability - Enhanced scroll pane settings for smoother scrolling - Refined button sizes and positions - Updated font sizes and styles for consistency
1 parent deb7370 commit 15a4970

File tree

2 files changed

+70
-49
lines changed

2 files changed

+70
-49
lines changed

core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/plan/TaskSectionPanel.kt

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ class TaskSectionPanel(
3838
private var expandButton: JButton? = null
3939
private var statusLabel: JLabel? = null
4040
private var progressLabel: JLabel? = null
41+
private val scrollPane: JBScrollPane
42+
private val MAX_TITLE_LENGTH = 50
4143

4244
init {
4345
layout = BorderLayout()
4446
background = JBUI.CurrentTheme.ToolWindow.background()
4547
border = CompoundBorder(
4648
BorderFactory.createMatteBorder(0, 0, 1, 0, JBColor.border()),
47-
JBUI.Borders.empty(8, 16, 8, 16)
49+
JBUI.Borders.empty(4, 16)
4850
)
4951

5052
val headerPanel = createHeaderPanel()
@@ -54,14 +56,15 @@ class TaskSectionPanel(
5456
stepsPanel.background = JBUI.CurrentTheme.ToolWindow.background()
5557
stepsPanel.border = JBUI.Borders.emptyLeft(24)
5658

57-
// Add steps to the steps panel
5859
refreshStepsPanel()
5960

60-
// Create a scroll pane for the steps
61-
val scrollPane = JBScrollPane(stepsPanel)
62-
scrollPane.border = BorderFactory.createEmptyBorder()
63-
scrollPane.isOpaque = false
64-
scrollPane.viewport.isOpaque = false
61+
scrollPane = JBScrollPane(stepsPanel).apply {
62+
border = BorderFactory.createEmptyBorder()
63+
isOpaque = false
64+
viewport.isOpaque = false
65+
horizontalScrollBarPolicy = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER
66+
verticalScrollBarPolicy = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED
67+
}
6568

6669
add(scrollPane, BorderLayout.CENTER)
6770

@@ -82,23 +85,23 @@ class TaskSectionPanel(
8285

8386
// Expand/collapse button
8487
expandButton = JButton(if (isExpanded) "" else "").apply {
85-
preferredSize = Dimension(24, 24)
88+
preferredSize = Dimension(20, 20) // Slightly smaller button
8689
margin = JBUI.insets(0)
8790
isBorderPainted = false
8891
isContentAreaFilled = false
8992
toolTipText = if (isExpanded) "Collapse section" else "Expand section"
9093

91-
addActionListener {
94+
addActionListener { e ->
9295
isExpanded = !isExpanded
9396
text = if (isExpanded) "" else ""
9497
toolTipText = if (isExpanded) "Collapse section" else "Expand section"
9598
toggleStepsVisibility(isExpanded)
99+
e.source = this // Ensure event propagation
96100
}
97101
}
98102

99103
leftPanel.add(expandButton)
100104

101-
// Status icon
102105
val statusIcon = when (planItem.status) {
103106
TaskStatus.COMPLETED -> JLabel(AutoDevIcons.Checked)
104107
TaskStatus.FAILED -> JLabel(AutoDevIcons.Error)
@@ -107,18 +110,23 @@ class TaskSectionPanel(
107110
}
108111
leftPanel.add(statusIcon)
109112

110-
// Title with section number
111-
val titleLabel = JLabel("${index + 1}. ${planItem.title}").apply {
113+
val fullTitle = "${index + 1}. ${planItem.title}"
114+
val displayTitle = if (planItem.title.length > MAX_TITLE_LENGTH) {
115+
"${index + 1}. ${planItem.title.take(MAX_TITLE_LENGTH)}..."
116+
} else {
117+
fullTitle
118+
}
119+
120+
val titleLabel = JLabel(displayTitle).apply {
112121
font = font.deriveFont(Font.BOLD)
122+
toolTipText = fullTitle // Show full title on hover
113123
}
114124
leftPanel.add(titleLabel)
115125

116-
// Right side with status, progress and action buttons
117126
val rightPanel = JPanel(FlowLayout(FlowLayout.RIGHT, 5, 0)).apply {
118127
isOpaque = false
119128
}
120129

121-
// Progress indicator
122130
val completedSteps = planItem.steps.count { it.completed }
123131
val totalSteps = planItem.steps.size
124132
val progressPercentage = if (totalSteps > 0) (completedSteps * 100) / totalSteps else 0
@@ -129,7 +137,6 @@ class TaskSectionPanel(
129137
}
130138
rightPanel.add(progressLabel)
131139

132-
// Status label
133140
statusLabel = JLabel(getStatusText(planItem.status)).apply {
134141
foreground = getStatusColor(planItem.status)
135142
font = font.deriveFont(Font.BOLD, 11f)
@@ -158,23 +165,11 @@ class TaskSectionPanel(
158165
}
159166

160167
private fun toggleStepsVisibility(visible: Boolean) {
161-
stepsPanel.isVisible = visible
162-
revalidate()
163-
repaint()
164-
165-
stepsPanel.addComponentListener(object : ComponentAdapter() {
166-
override fun componentShown(e: ComponentEvent) {
167-
UIUtil.invokeLaterIfNeeded {
168-
parent.revalidate()
169-
}
170-
}
171-
172-
override fun componentHidden(e: ComponentEvent) {
173-
UIUtil.invokeLaterIfNeeded {
174-
parent.revalidate()
175-
}
176-
}
177-
})
168+
scrollPane.isVisible = visible
169+
SwingUtilities.invokeLater {
170+
parent?.revalidate()
171+
parent?.repaint()
172+
}
178173
}
179174

180175
private fun refreshStepsPanel() {
@@ -188,7 +183,7 @@ class TaskSectionPanel(
188183
}
189184

190185
stepsPanel.add(taskStepPanel)
191-
stepsPanel.add(Box.createVerticalStrut(4))
186+
stepsPanel.add(Box.createVerticalStrut(2)) // Reduced spacing between steps
192187
}
193188
}
194189

@@ -247,3 +242,4 @@ class TaskSectionPanel(
247242
}
248243
}
249244
}
245+

core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/plan/TaskStepPanel.kt

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,18 @@ class TaskStepPanel(
4040
private val doc: StyledDocument
4141
private val linkMap = mutableMapOf<IntRange, String>()
4242
private var statusLabel: JLabel? = null
43+
private val MAX_TEXT_LENGTH = 100 // Maximum characters to display before truncating
4344

4445
init {
4546
layout = BorderLayout()
4647
background = JBUI.CurrentTheme.ToolWindow.background()
4748
border = CompoundBorder(
4849
BorderFactory.createMatteBorder(0, 0, 1, 0, JBColor(0xE5E5E5, 0x323232)),
49-
JBUI.Borders.empty(6, 4)
50+
JBUI.Borders.empty(3, 2) // Reduced padding for more compact view
5051
)
5152

52-
// Left panel for status icon
53-
val leftPanel = JPanel(FlowLayout(FlowLayout.LEFT, 5, 0)).apply {
53+
// Left panel for status icon with reduced spacing
54+
val leftPanel = JPanel(FlowLayout(FlowLayout.LEFT, 2, 0)).apply {
5455
isOpaque = false
5556
}
5657

@@ -67,22 +68,21 @@ class TaskStepPanel(
6768
add(taskLabel, BorderLayout.CENTER)
6869
}
6970

70-
// Right panel for status and action buttons
71-
val rightPanel = JPanel(FlowLayout(FlowLayout.RIGHT, 5, 0)).apply {
71+
val rightPanel = JPanel(FlowLayout(FlowLayout.RIGHT, 2, 0)).apply {
7272
isOpaque = false
7373
}
7474

7575
statusLabel = JLabel(getStatusText(task.status)).apply {
7676
foreground = getStatusColor(task.status)
77-
font = font.deriveFont(Font.PLAIN, 10f)
78-
border = JBUI.Borders.empty(2, 5)
77+
font = font.deriveFont(Font.PLAIN, 9f)
78+
border = JBUI.Borders.empty(1, 3)
7979
}
8080
rightPanel.add(statusLabel)
8181

8282
if (task.status == TaskStatus.TODO || task.status == TaskStatus.FAILED) {
8383
val executeButton = JButton(AutoDevIcons.Run).apply {
84-
preferredSize = Dimension(24, 24)
85-
margin = JBUI.insets(0)
84+
preferredSize = Dimension(20, 20)
85+
margin = JBUI.emptyInsets()
8686
isBorderPainted = false
8787
isContentAreaFilled = false
8888
toolTipText = "Execute this step"
@@ -93,8 +93,8 @@ class TaskStepPanel(
9393

9494
if (task.status == TaskStatus.FAILED) {
9595
val retryButton = JButton("Retry").apply {
96-
margin = JBUI.insets(0, 3)
97-
font = font.deriveFont(Font.PLAIN, 10f)
96+
margin = JBUI.insets(0, 2) // Less margin
97+
font = font.deriveFont(Font.PLAIN, 9f) // Smaller font size
9898
addActionListener { executeTask() }
9999
}
100100
rightPanel.add(retryButton)
@@ -105,13 +105,25 @@ class TaskStepPanel(
105105
add(rightPanel, BorderLayout.EAST)
106106

107107
setupContextMenu()
108+
109+
// Set preferred size for compact view
110+
preferredSize = Dimension(preferredSize.width, Math.min(preferredSize.height, 28))
108111
}
109112

110113
private fun createStatusIcon(): JComponent {
111114
return when (task.status) {
112-
TaskStatus.COMPLETED -> JLabel(AutoDevIcons.Checked)
113-
TaskStatus.FAILED -> JLabel(AutoDevIcons.Error)
114-
TaskStatus.IN_PROGRESS -> JLabel(AutoDevIcons.Build)
115+
TaskStatus.COMPLETED -> JLabel(AutoDevIcons.Checked).apply {
116+
preferredSize = Dimension(16, 16)
117+
}
118+
119+
TaskStatus.FAILED -> JLabel(AutoDevIcons.Error).apply {
120+
preferredSize = Dimension(16, 16)
121+
}
122+
123+
TaskStatus.IN_PROGRESS -> JLabel(AutoDevIcons.Build).apply {
124+
preferredSize = Dimension(16, 16)
125+
}
126+
115127
TaskStatus.TODO -> JCheckBox().apply {
116128
isSelected = task.completed
117129
addActionListener {
@@ -124,6 +136,7 @@ class TaskStepPanel(
124136
isBorderPainted = false
125137
isContentAreaFilled = false
126138
background = JBUI.CurrentTheme.ToolWindow.background()
139+
preferredSize = Dimension(16, 16)
127140
}
128141
}
129142
}
@@ -132,13 +145,13 @@ class TaskStepPanel(
132145
val editorColorsManager = EditorColorsManager.getInstance()
133146
val currentScheme = editorColorsManager.schemeForCurrentUITheme
134147
val editorFontName = currentScheme.editorFontName
135-
val editorFontSize = currentScheme.editorFontSize
148+
val editorFontSize = currentScheme.editorFontSize - 1 // Slightly smaller font
136149

137150
return JTextPane().apply {
138151
isEditable = false
139152
isOpaque = false
140153
background = JBUI.CurrentTheme.ToolWindow.background()
141-
border = JBUI.Borders.emptyLeft(5)
154+
border = JBUI.Borders.emptyLeft(3) // Less left padding
142155
font = Font(editorFontName, Font.PLAIN, editorFontSize)
143156
foreground = UIUtil.getLabelForeground()
144157

@@ -175,6 +188,15 @@ class TaskStepPanel(
175188
var text = task.step
176189
var currentPos = 0
177190

191+
taskLabel.toolTipText = text
192+
val needsTruncation = text.length > MAX_TEXT_LENGTH && task.codeFileLinks.isEmpty()
193+
if (needsTruncation && task.codeFileLinks.isEmpty()) {
194+
val truncatedText = text.take(MAX_TEXT_LENGTH) + "..."
195+
doc.insertString(0, truncatedText, getStyleForStatus(task.status))
196+
return
197+
}
198+
199+
// If we have links or the text is short enough, use the normal rendering logic
178200
task.codeFileLinks.forEach { link ->
179201
val linkPattern = "[${link.displayText}](${link.filePath})"
180202
val linkIndex = text.indexOf(linkPattern)
@@ -198,6 +220,9 @@ class TaskStepPanel(
198220
}
199221

200222
if (text.isNotEmpty()) {
223+
if (text.length > MAX_TEXT_LENGTH) {
224+
text = text.take(MAX_TEXT_LENGTH) + "..."
225+
}
201226
doc.insertString(currentPos, text, getStyleForStatus(task.status))
202227
}
203228
}

0 commit comments

Comments
 (0)