Skip to content

Commit 72b81b0

Browse files
committed
feat(gui): show relative file path in planner result #352
- Update file path display to show relative path instead of absolute path - Add tooltip to file path for full path information - Improve UI layout for better readability
1 parent 7047c8e commit 72b81b0

File tree

1 file changed

+31
-24
lines changed

1 file changed

+31
-24
lines changed

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

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package cc.unitmesh.devti.gui.planner
22

3+
import cc.unitmesh.devti.util.relativePath
34
import com.intellij.icons.AllIcons
45
import com.intellij.openapi.fileEditor.FileEditorManager
56
import com.intellij.openapi.project.Project
@@ -8,16 +9,13 @@ import com.intellij.openapi.vcs.changes.ui.RollbackWorker
89
import com.intellij.ui.HyperlinkLabel
910
import com.intellij.ui.components.JBLabel
1011
import com.intellij.ui.components.JBScrollPane
11-
import com.intellij.ui.components.panels.HorizontalLayout
1212
import com.intellij.util.ui.JBUI
1313
import com.intellij.util.ui.UIUtil
1414
import java.awt.BorderLayout
1515
import java.awt.FlowLayout
1616
import java.awt.GridLayout
17-
import java.awt.event.MouseAdapter
18-
import java.awt.event.MouseEvent
19-
import javax.swing.JPanel
2017
import javax.swing.JButton
18+
import javax.swing.JPanel
2119
import javax.swing.event.HyperlinkEvent
2220
import javax.swing.event.HyperlinkListener
2321

@@ -34,7 +32,7 @@ class PlannerResultSummary(
3432
fun onDiscard(change: Change)
3533
fun onAccept(change: Change)
3634
}
37-
35+
3836
interface GlobalActionListener {
3937
fun onDiscardAll()
4038
fun onAcceptAll()
@@ -45,6 +43,7 @@ class PlannerResultSummary(
4543
rollbackWorker.doRollback(changes, false)
4644
updateChanges(mutableListOf())
4745
}
46+
4847
override fun onAcceptAll() {
4948

5049
}
@@ -57,12 +56,14 @@ class PlannerResultSummary(
5756
FileEditorManager.getInstance(project).openFile(it, true)
5857
}
5958
}
59+
6060
override fun onDiscard(change: Change) {
6161
rollbackWorker.doRollback(listOf(change), false)
6262
val newChanges = changes.toMutableList()
6363
newChanges.remove(change)
6464
updateChanges(newChanges)
6565
}
66+
6667
override fun onAccept(change: Change) {}
6768
}
6869

@@ -73,7 +74,7 @@ class PlannerResultSummary(
7374
val titlePanel = JPanel(BorderLayout()).apply {
7475
isOpaque = false
7576
border = JBUI.Borders.emptyBottom(10)
76-
77+
7778
val titleLabelPanel = JPanel(BorderLayout()).apply {
7879
isOpaque = false
7980
add(JBLabel("Change list").apply {
@@ -82,10 +83,10 @@ class PlannerResultSummary(
8283
}, BorderLayout.WEST)
8384
add(statsLabel, BorderLayout.EAST)
8485
}
85-
86+
8687
val actionsPanel = JPanel(FlowLayout(FlowLayout.RIGHT, 5, 0)).apply {
8788
isOpaque = false
88-
89+
8990
val discardAllButton = HyperlinkLabel("Discard all").apply {
9091
icon = AllIcons.Actions.Cancel
9192
addHyperlinkListener(object : HyperlinkListener {
@@ -96,7 +97,7 @@ class PlannerResultSummary(
9697
}
9798
})
9899
}
99-
100+
100101
val acceptAllButton = HyperlinkLabel("Accept all").apply {
101102
icon = AllIcons.Actions.Commit
102103
addHyperlinkListener(object : HyperlinkListener {
@@ -107,11 +108,11 @@ class PlannerResultSummary(
107108
}
108109
})
109110
}
110-
111+
111112
add(discardAllButton)
112113
add(acceptAllButton)
113114
}
114-
115+
115116
add(titleLabelPanel, BorderLayout.WEST)
116117
add(actionsPanel, BorderLayout.EAST)
117118
}
@@ -120,13 +121,13 @@ class PlannerResultSummary(
120121

121122
changesPanel.isOpaque = false
122123
changesPanel.border = JBUI.Borders.empty(1)
123-
124+
124125
val scrollPane = JBScrollPane(changesPanel).apply {
125126
border = JBUI.Borders.empty()
126127
background = background
127128
viewport.background = background
128129
}
129-
130+
130131
add(scrollPane, BorderLayout.CENTER)
131132
updateChanges(changes.toMutableList())
132133
}
@@ -144,7 +145,7 @@ class PlannerResultSummary(
144145
} else {
145146
statsLabel.text = " (Total ${changes.size} files changed)"
146147
changes.forEach { change ->
147-
val filePath = change.virtualFile?.path ?: "Unknown"
148+
val filePath = change.virtualFile?.relativePath(project) ?: "Unknown"
148149
val fileName = filePath.substringAfterLast('/')
149150

150151
val changePanel = createChangeItemPanel(change, fileName, filePath)
@@ -154,38 +155,43 @@ class PlannerResultSummary(
154155

155156
changesPanel.revalidate()
156157
changesPanel.repaint()
157-
158+
158159
isVisible = true
159160
revalidate()
160161
repaint()
161162
}
162-
163+
163164
private fun createChangeItemPanel(change: Change, fileName: String, filePath: String): JPanel {
164165
return JPanel(BorderLayout()).apply {
165166
isOpaque = true
166167
background = UIUtil.getListBackground()
167168
border = JBUI.Borders.empty(5, 8)
168-
169+
169170
val changeIcon = when (change.type) {
170171
Change.Type.NEW -> AllIcons.Actions.New
171172
Change.Type.DELETED -> AllIcons.Actions.GC
172173
Change.Type.MOVED -> AllIcons.Actions.Forward
173174
else -> AllIcons.Actions.Edit
174175
}
175-
176+
176177
val infoPanel = JPanel(BorderLayout()).apply {
177178
isOpaque = false
178179

179180
val fileLabel = JBLabel(fileName, changeIcon, JBLabel.LEFT).apply {
180181
toolTipText = filePath
181182
}
182-
183+
183184
add(fileLabel, BorderLayout.CENTER)
184185
}
185-
186+
187+
val pathLabel = JBLabel(filePath).apply {
188+
foreground = UIUtil.getLabelDisabledForeground()
189+
toolTipText = filePath
190+
}
191+
186192
val actionsPanel = JPanel(FlowLayout(FlowLayout.RIGHT, 2, 0)).apply {
187193
isOpaque = false
188-
194+
189195
val viewButton = JButton().apply {
190196
icon = AllIcons.Actions.Preview
191197
toolTipText = "View changes"
@@ -198,7 +204,7 @@ class PlannerResultSummary(
198204
changeActionListener?.onView(change)
199205
}
200206
}
201-
207+
202208
val discardButton = JButton().apply {
203209
icon = AllIcons.Actions.Cancel
204210
toolTipText = "Discard changes"
@@ -215,8 +221,9 @@ class PlannerResultSummary(
215221
add(viewButton)
216222
add(discardButton)
217223
}
218-
219-
add(infoPanel, BorderLayout.CENTER)
224+
225+
add(infoPanel, BorderLayout.NORTH)
226+
add(pathLabel, BorderLayout.CENTER)
220227
add(actionsPanel, BorderLayout.EAST)
221228
}
222229
}

0 commit comments

Comments
 (0)