Skip to content

Commit 6b40d4c

Browse files
committed
feat(gui): add hyperlink to file name in planner result #352
- Replace JBLabel with HyperlinkLabel for file name- Add hyperlink listener to navigate to file when clicked - Improve user interaction and accessibility in the planner result view
1 parent e786096 commit 6b40d4c

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

core/src/main/kotlin/cc/unitmesh/devti/gui/planner/PlannerResultSummary.kt

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import com.intellij.util.ui.UIUtil
1414
import java.awt.BorderLayout
1515
import java.awt.FlowLayout
1616
import java.awt.GridLayout
17+
import javax.swing.Box
18+
import javax.swing.BoxLayout
1719
import javax.swing.Icon
1820
import javax.swing.JButton
1921
import javax.swing.JPanel
@@ -163,10 +165,11 @@ class PlannerResultSummary(
163165
}
164166

165167
private fun createChangeItemPanel(change: Change, fileName: String, filePath: String): JPanel {
166-
return JPanel(BorderLayout()).apply {
168+
return JPanel().apply {
167169
isOpaque = true
168170
background = UIUtil.getListBackground()
169171
border = JBUI.Borders.empty(5, 8)
172+
layout = BoxLayout(this, BoxLayout.X_AXIS)
170173

171174
val changeIcon = when (change.type) {
172175
Change.Type.NEW -> AllIcons.Actions.New
@@ -175,16 +178,21 @@ class PlannerResultSummary(
175178
else -> AllIcons.Actions.Edit
176179
}
177180

178-
val infoPanel = JPanel(BorderLayout()).apply {
179-
isOpaque = false
180-
181-
val fileLabel = JBLabel(fileName, changeIcon, JBLabel.LEFT).apply {
182-
toolTipText = filePath
183-
}
184-
185-
add(fileLabel, BorderLayout.CENTER)
181+
val fileLabel = HyperlinkLabel(fileName).apply {
182+
icon = changeIcon
183+
toolTipText = filePath
184+
addHyperlinkListener(object : HyperlinkListener {
185+
override fun hyperlinkUpdate(e: HyperlinkEvent) {
186+
if (e.eventType == HyperlinkEvent.EventType.ACTIVATED) {
187+
changeActionListener.onView(change)
188+
}
189+
}
190+
})
186191
}
187-
192+
193+
add(fileLabel)
194+
add(Box.createHorizontalStrut(5))
195+
188196
val pathLabel = JBLabel(filePath).apply {
189197
foreground = UIUtil.getLabelDisabledForeground()
190198
toolTipText = filePath
@@ -193,17 +201,19 @@ class PlannerResultSummary(
193201
putClientProperty("JComponent.truncateText", true)
194202
putClientProperty("truncateAtWord", false)
195203
putClientProperty("html.disable", true)
204+
minimumSize = JBUI.size(20, preferredSize.height)
205+
preferredSize = JBUI.size(100, preferredSize.height)
196206
maximumSize = JBUI.size(Int.MAX_VALUE, preferredSize.height)
197207
}
198-
199-
val pathPanel = JPanel(BorderLayout()).apply {
200-
isOpaque = false
201-
add(pathLabel, BorderLayout.CENTER)
202-
}
203-
204-
val actionsPanel = JPanel(FlowLayout(FlowLayout.RIGHT, 2, 0)).apply {
208+
209+
add(pathLabel)
210+
add(Box.createHorizontalGlue()) // This pushes the action buttons to the right
211+
212+
// Action buttons
213+
val actionsPanel = JPanel().apply {
205214
isOpaque = false
206-
215+
layout = BoxLayout(this, BoxLayout.X_AXIS)
216+
207217
val viewButton = createActionButton(
208218
AllIcons.Actions.Preview,
209219
"View changes"
@@ -215,12 +225,11 @@ class PlannerResultSummary(
215225
) { changeActionListener.onDiscard(change) }
216226

217227
add(viewButton)
228+
add(Box.createHorizontalStrut(2))
218229
add(discardButton)
219230
}
220-
221-
add(infoPanel, BorderLayout.NORTH)
222-
add(pathPanel, BorderLayout.CENTER)
223-
add(actionsPanel, BorderLayout.EAST)
231+
232+
add(actionsPanel)
224233
}
225234
}
226235

0 commit comments

Comments
 (0)