1
1
package cc.unitmesh.devti.gui.chat
2
2
3
+ import cc.unitmesh.devti.custom.variable.CustomVariable
3
4
import com.intellij.ui.Gray
4
5
import com.intellij.ui.JBColor
5
6
import com.intellij.ui.components.JBList
6
7
import java.awt.BorderLayout
7
8
import java.awt.Component
8
9
import java.awt.event.MouseEvent
9
- import java.awt.event.MouseListener
10
10
import javax.swing.*
11
11
import javax.swing.border.Border
12
12
import javax.swing.event.MouseInputAdapter
13
13
14
14
class AutoDevVariableList (
15
- val list : List <AutoDevVariableListComponent >,
16
- val callback : ((AutoDevVariableListComponent ) -> Unit? ) ? ,
17
- ) : JBList<AutoDevVariableListComponent>( ) {
15
+ val list : List <AutoDevVariableListItemComponent >,
16
+ val callback : ((AutoDevVariableListItemComponent ) -> Unit ) ,
17
+ ) : JBList<AutoDevVariableListItemComponent>(list ) {
18
18
init {
19
19
border = BorderFactory .createEmptyBorder(0 , 4 , 0 , 4 )
20
20
setCellRenderer(VariableListCellRenderer ())
21
21
addMouseListener(object : MouseInputAdapter () {
22
22
override fun mouseClicked (event : MouseEvent ? ) {
23
23
val item = selectedValue ? : return
24
- callback? .invoke(item)
24
+ callback.invoke(item)
25
25
}
26
26
})
27
27
}
28
+
29
+ companion object {
30
+ fun from (all : List <CustomVariable >, function : (AutoDevVariableListItemComponent ) -> Unit ): AutoDevVariableList {
31
+ val list = all.map {
32
+ AutoDevVariableListItemComponent (it)
33
+ }
34
+ return AutoDevVariableList (list, function)
35
+ }
36
+ }
28
37
}
29
38
30
- class VariableListCellRenderer : ListCellRenderer <AutoDevVariableListComponent > {
39
+ class VariableListCellRenderer : ListCellRenderer <AutoDevVariableListItemComponent > {
31
40
private var emptyBorder: Border = BorderFactory .createEmptyBorder(1 , 1 , 1 , 1 )
32
41
33
42
override fun getListCellRendererComponent (
34
- jList : JList <out AutoDevVariableListComponent >,
35
- value : AutoDevVariableListComponent ? ,
43
+ jList : JList <out AutoDevVariableListItemComponent >,
44
+ value : AutoDevVariableListItemComponent ? ,
36
45
index : Int ,
37
46
isSelected : Boolean ,
38
47
cellHasFocus : Boolean ,
@@ -62,15 +71,14 @@ class VariableListCellRenderer : ListCellRenderer<AutoDevVariableListComponent>
62
71
value.border = border
63
72
return value
64
73
}
65
-
66
74
}
67
75
68
- class AutoDevVariableListComponent : JPanel () {
76
+ class AutoDevVariableListItemComponent ( val customVariable : CustomVariable ) : JPanel() {
69
77
init {
70
- add(JLabel (" $" + " selection " ), BorderLayout .WEST )
71
- val label = JLabel (" Used to get the currently selected text " )
78
+ add(JLabel (" $${customVariable.variable} " ), BorderLayout .WEST )
79
+ val label = JLabel (customVariable.description )
72
80
label.border = BorderFactory .createEmptyBorder(0 , 8 , 0 , 0 )
73
81
label.foreground = JBColor .namedColor(" Component.infoForeground" , JBColor (Gray .x99, Gray .x78))
74
82
add(label, BorderLayout .EAST )
75
83
}
76
- }
84
+ }
0 commit comments