1
1
package cc.unitmesh.devti.gui.planner
2
2
3
+ import cc.unitmesh.devti.util.relativePath
3
4
import com.intellij.icons.AllIcons
4
5
import com.intellij.openapi.fileEditor.FileEditorManager
5
6
import com.intellij.openapi.project.Project
@@ -8,16 +9,13 @@ import com.intellij.openapi.vcs.changes.ui.RollbackWorker
8
9
import com.intellij.ui.HyperlinkLabel
9
10
import com.intellij.ui.components.JBLabel
10
11
import com.intellij.ui.components.JBScrollPane
11
- import com.intellij.ui.components.panels.HorizontalLayout
12
12
import com.intellij.util.ui.JBUI
13
13
import com.intellij.util.ui.UIUtil
14
14
import java.awt.BorderLayout
15
15
import java.awt.FlowLayout
16
16
import java.awt.GridLayout
17
- import java.awt.event.MouseAdapter
18
- import java.awt.event.MouseEvent
19
- import javax.swing.JPanel
20
17
import javax.swing.JButton
18
+ import javax.swing.JPanel
21
19
import javax.swing.event.HyperlinkEvent
22
20
import javax.swing.event.HyperlinkListener
23
21
@@ -34,7 +32,7 @@ class PlannerResultSummary(
34
32
fun onDiscard (change : Change )
35
33
fun onAccept (change : Change )
36
34
}
37
-
35
+
38
36
interface GlobalActionListener {
39
37
fun onDiscardAll ()
40
38
fun onAcceptAll ()
@@ -45,6 +43,7 @@ class PlannerResultSummary(
45
43
rollbackWorker.doRollback(changes, false )
46
44
updateChanges(mutableListOf ())
47
45
}
46
+
48
47
override fun onAcceptAll () {
49
48
50
49
}
@@ -57,12 +56,14 @@ class PlannerResultSummary(
57
56
FileEditorManager .getInstance(project).openFile(it, true )
58
57
}
59
58
}
59
+
60
60
override fun onDiscard (change : Change ) {
61
61
rollbackWorker.doRollback(listOf (change), false )
62
62
val newChanges = changes.toMutableList()
63
63
newChanges.remove(change)
64
64
updateChanges(newChanges)
65
65
}
66
+
66
67
override fun onAccept (change : Change ) {}
67
68
}
68
69
@@ -73,7 +74,7 @@ class PlannerResultSummary(
73
74
val titlePanel = JPanel (BorderLayout ()).apply {
74
75
isOpaque = false
75
76
border = JBUI .Borders .emptyBottom(10 )
76
-
77
+
77
78
val titleLabelPanel = JPanel (BorderLayout ()).apply {
78
79
isOpaque = false
79
80
add(JBLabel (" Change list" ).apply {
@@ -82,10 +83,10 @@ class PlannerResultSummary(
82
83
}, BorderLayout .WEST )
83
84
add(statsLabel, BorderLayout .EAST )
84
85
}
85
-
86
+
86
87
val actionsPanel = JPanel (FlowLayout (FlowLayout .RIGHT , 5 , 0 )).apply {
87
88
isOpaque = false
88
-
89
+
89
90
val discardAllButton = HyperlinkLabel (" Discard all" ).apply {
90
91
icon = AllIcons .Actions .Cancel
91
92
addHyperlinkListener(object : HyperlinkListener {
@@ -96,7 +97,7 @@ class PlannerResultSummary(
96
97
}
97
98
})
98
99
}
99
-
100
+
100
101
val acceptAllButton = HyperlinkLabel (" Accept all" ).apply {
101
102
icon = AllIcons .Actions .Commit
102
103
addHyperlinkListener(object : HyperlinkListener {
@@ -107,11 +108,11 @@ class PlannerResultSummary(
107
108
}
108
109
})
109
110
}
110
-
111
+
111
112
add(discardAllButton)
112
113
add(acceptAllButton)
113
114
}
114
-
115
+
115
116
add(titleLabelPanel, BorderLayout .WEST )
116
117
add(actionsPanel, BorderLayout .EAST )
117
118
}
@@ -120,13 +121,13 @@ class PlannerResultSummary(
120
121
121
122
changesPanel.isOpaque = false
122
123
changesPanel.border = JBUI .Borders .empty(1 )
123
-
124
+
124
125
val scrollPane = JBScrollPane (changesPanel).apply {
125
126
border = JBUI .Borders .empty()
126
127
background = background
127
128
viewport.background = background
128
129
}
129
-
130
+
130
131
add(scrollPane, BorderLayout .CENTER )
131
132
updateChanges(changes.toMutableList())
132
133
}
@@ -144,7 +145,7 @@ class PlannerResultSummary(
144
145
} else {
145
146
statsLabel.text = " (Total ${changes.size} files changed)"
146
147
changes.forEach { change ->
147
- val filePath = change.virtualFile?.path ? : " Unknown"
148
+ val filePath = change.virtualFile?.relativePath(project) ? : " Unknown"
148
149
val fileName = filePath.substringAfterLast(' /' )
149
150
150
151
val changePanel = createChangeItemPanel(change, fileName, filePath)
@@ -154,38 +155,43 @@ class PlannerResultSummary(
154
155
155
156
changesPanel.revalidate()
156
157
changesPanel.repaint()
157
-
158
+
158
159
isVisible = true
159
160
revalidate()
160
161
repaint()
161
162
}
162
-
163
+
163
164
private fun createChangeItemPanel (change : Change , fileName : String , filePath : String ): JPanel {
164
165
return JPanel (BorderLayout ()).apply {
165
166
isOpaque = true
166
167
background = UIUtil .getListBackground()
167
168
border = JBUI .Borders .empty(5 , 8 )
168
-
169
+
169
170
val changeIcon = when (change.type) {
170
171
Change .Type .NEW -> AllIcons .Actions .New
171
172
Change .Type .DELETED -> AllIcons .Actions .GC
172
173
Change .Type .MOVED -> AllIcons .Actions .Forward
173
174
else -> AllIcons .Actions .Edit
174
175
}
175
-
176
+
176
177
val infoPanel = JPanel (BorderLayout ()).apply {
177
178
isOpaque = false
178
179
179
180
val fileLabel = JBLabel (fileName, changeIcon, JBLabel .LEFT ).apply {
180
181
toolTipText = filePath
181
182
}
182
-
183
+
183
184
add(fileLabel, BorderLayout .CENTER )
184
185
}
185
-
186
+
187
+ val pathLabel = JBLabel (filePath).apply {
188
+ foreground = UIUtil .getLabelDisabledForeground()
189
+ toolTipText = filePath
190
+ }
191
+
186
192
val actionsPanel = JPanel (FlowLayout (FlowLayout .RIGHT , 2 , 0 )).apply {
187
193
isOpaque = false
188
-
194
+
189
195
val viewButton = JButton ().apply {
190
196
icon = AllIcons .Actions .Preview
191
197
toolTipText = " View changes"
@@ -198,7 +204,7 @@ class PlannerResultSummary(
198
204
changeActionListener?.onView(change)
199
205
}
200
206
}
201
-
207
+
202
208
val discardButton = JButton ().apply {
203
209
icon = AllIcons .Actions .Cancel
204
210
toolTipText = " Discard changes"
@@ -215,8 +221,9 @@ class PlannerResultSummary(
215
221
add(viewButton)
216
222
add(discardButton)
217
223
}
218
-
219
- add(infoPanel, BorderLayout .CENTER )
224
+
225
+ add(infoPanel, BorderLayout .NORTH )
226
+ add(pathLabel, BorderLayout .CENTER )
220
227
add(actionsPanel, BorderLayout .EAST )
221
228
}
222
229
}
0 commit comments