Skip to content

Commit e786096

Browse files
committed
refactor(devti): enhance change item UI and code structure #352
- Improve file path display with truncation and tooltip- Refactor action buttons creation and layout - Optimize code structure for better maintainability
1 parent 72b81b0 commit e786096

File tree

1 file changed

+36
-26
lines changed

1 file changed

+36
-26
lines changed

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

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ 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.Icon
1718
import javax.swing.JButton
1819
import javax.swing.JPanel
1920
import javax.swing.event.HyperlinkEvent
@@ -187,45 +188,54 @@ class PlannerResultSummary(
187188
val pathLabel = JBLabel(filePath).apply {
188189
foreground = UIUtil.getLabelDisabledForeground()
189190
toolTipText = filePath
191+
isOpaque = false
192+
componentStyle = UIUtil.ComponentStyle.SMALL
193+
putClientProperty("JComponent.truncateText", true)
194+
putClientProperty("truncateAtWord", false)
195+
putClientProperty("html.disable", true)
196+
maximumSize = JBUI.size(Int.MAX_VALUE, preferredSize.height)
197+
}
198+
199+
val pathPanel = JPanel(BorderLayout()).apply {
200+
isOpaque = false
201+
add(pathLabel, BorderLayout.CENTER)
190202
}
191203

192204
val actionsPanel = JPanel(FlowLayout(FlowLayout.RIGHT, 2, 0)).apply {
193205
isOpaque = false
194206

195-
val viewButton = JButton().apply {
196-
icon = AllIcons.Actions.Preview
197-
toolTipText = "View changes"
198-
isBorderPainted = false
199-
isContentAreaFilled = false
200-
isFocusPainted = false
201-
margin = JBUI.emptyInsets()
202-
preferredSize = JBUI.size(20, 20)
203-
addActionListener {
204-
changeActionListener?.onView(change)
205-
}
206-
}
207+
val viewButton = createActionButton(
208+
AllIcons.Actions.Preview,
209+
"View changes"
210+
) { changeActionListener.onView(change) }
207211

208-
val discardButton = JButton().apply {
209-
icon = AllIcons.Actions.Cancel
210-
toolTipText = "Discard changes"
211-
isBorderPainted = false
212-
isContentAreaFilled = false
213-
isFocusPainted = false
214-
margin = JBUI.emptyInsets()
215-
preferredSize = JBUI.size(20, 20)
216-
addActionListener {
217-
changeActionListener?.onDiscard(change)
218-
}
219-
}
212+
val discardButton = createActionButton(
213+
AllIcons.Actions.Cancel,
214+
"Discard changes"
215+
) { changeActionListener.onDiscard(change) }
220216

221217
add(viewButton)
222218
add(discardButton)
223219
}
224220

225221
add(infoPanel, BorderLayout.NORTH)
226-
add(pathLabel, BorderLayout.CENTER)
222+
add(pathPanel, BorderLayout.CENTER)
227223
add(actionsPanel, BorderLayout.EAST)
228224
}
229225
}
230-
}
231226

227+
private fun createActionButton(
228+
icon: Icon,
229+
tooltip: String,
230+
action: () -> Unit
231+
): JButton = JButton().apply {
232+
this.icon = icon
233+
toolTipText = tooltip
234+
isBorderPainted = false
235+
isContentAreaFilled = false
236+
isFocusPainted = false
237+
margin = JBUI.emptyInsets()
238+
preferredSize = JBUI.size(20, 20)
239+
addActionListener { action() }
240+
}
241+
}

0 commit comments

Comments
 (0)