@@ -20,12 +20,9 @@ import com.intellij.ui.components.JBList
20
20
import com.intellij.ui.components.JBScrollPane
21
21
import com.intellij.util.ui.JBUI
22
22
import java.awt.*
23
- import java.awt.event.ComponentAdapter
24
- import java.awt.event.ComponentEvent
25
23
import java.awt.event.MouseAdapter
26
24
import java.awt.event.MouseEvent
27
25
import javax.swing.*
28
- import javax.swing.border.EmptyBorder
29
26
30
27
class ViewHistoryAction : AnAction (
31
28
AutoDevBundle .message("action.view.history.text"),
@@ -75,8 +72,8 @@ class ViewHistoryAction : AnAction(
75
72
hasFocus : Boolean
76
73
): Component {
77
74
// 创建主面板,使用 BorderLayout
78
- val panel = JPanel (BorderLayout ())
79
- panel.border = JBUI .Borders .empty(8 , 12 )
75
+ val panel = JPanel (BorderLayout (10 , 0 ))
76
+ panel.border = JBUI .Borders .empty(4 , 8 )
80
77
81
78
// 设置背景颜色
82
79
if (selected) {
@@ -88,46 +85,37 @@ class ViewHistoryAction : AnAction(
88
85
}
89
86
panel.isOpaque = true
90
87
91
- // 左侧内容面板 - 包含会话名称和时间
92
- val contentPanel = JPanel ()
93
- contentPanel.layout = BoxLayout (contentPanel, BoxLayout .Y_AXIS )
94
- contentPanel.isOpaque = false
95
-
96
- // 会话名称标签 - 处理过长文本
97
88
val sessionName = value.session.name
98
- val displayName = if (sessionName.length > 40 ) {
99
- sessionName.substring(0 , 37 ) + " ..."
89
+ val maxLength = 30 // 根据UI宽度调整最大长度
90
+ val displayName = if (sessionName.length > maxLength) {
91
+ sessionName.substring(0 , maxLength - 3 ) + " ..."
100
92
} else {
101
93
sessionName
102
94
}
103
95
96
+ val contentPanel = JPanel (FlowLayout (FlowLayout .LEFT , 0 , 0 ))
97
+ contentPanel.isOpaque = false
98
+
99
+ // 会话名称
104
100
val titleLabel = JLabel (displayName)
105
- titleLabel.font = titleLabel.font.deriveFont(Font .BOLD , 13f )
101
+ titleLabel.font = titleLabel.font.deriveFont(Font .BOLD , 12f )
106
102
titleLabel.toolTipText = sessionName // 完整名称作为工具提示
107
- if (selected) {
108
- titleLabel.foreground = list.selectionForeground
109
- } else {
110
- titleLabel.foreground = list.foreground
111
- }
112
-
103
+
113
104
// 时间标签
114
- val timeLabel = JLabel (value.relativeTime)
105
+ val timeLabel = JLabel (" - ${ value.relativeTime} " )
115
106
timeLabel.font = timeLabel.font.deriveFont(11f )
107
+
116
108
if (selected) {
109
+ titleLabel.foreground = list.selectionForeground
117
110
timeLabel.foreground = list.selectionForeground.darker()
118
111
} else {
112
+ titleLabel.foreground = list.foreground
119
113
timeLabel.foreground = list.foreground.darker()
120
114
}
121
115
122
- // 设置标签对齐
123
- titleLabel.alignmentX = Component .LEFT_ALIGNMENT
124
- timeLabel.alignmentX = Component .LEFT_ALIGNMENT
125
-
126
116
contentPanel.add(titleLabel)
127
- contentPanel.add(Box .createVerticalStrut(2 ))
128
117
contentPanel.add(timeLabel)
129
118
130
- // 右侧删除按钮
131
119
val deleteButton = JLabel (AllIcons .Actions .Close )
132
120
deleteButton.cursor = Cursor .getPredefinedCursor(Cursor .HAND_CURSOR )
133
121
deleteButton.border = JBUI .Borders .emptyLeft(8 )
@@ -146,13 +134,10 @@ class ViewHistoryAction : AnAction(
146
134
}
147
135
})
148
136
149
- // 组装面板
150
137
panel.add(contentPanel, BorderLayout .CENTER )
151
138
panel.add(deleteButton, BorderLayout .EAST )
152
139
153
- // 设置固定高度
154
- panel.preferredSize = Dimension (panel.preferredSize.width, 50 )
155
-
140
+ panel.preferredSize = Dimension (panel.preferredSize.width, 35 )
156
141
return panel
157
142
}
158
143
}
@@ -170,8 +155,8 @@ class ViewHistoryAction : AnAction(
170
155
val listItems = sessions.map { SessionListItem (it, formatRelativeTime(it.createdAt)) }
171
156
val jbList = JBList (listItems)
172
157
jbList.selectionMode = ListSelectionModel .SINGLE_SELECTION
173
- jbList.fixedCellHeight = 50 // 固定单元格高度
174
-
158
+ jbList.fixedCellHeight = 35
159
+
175
160
val onDeleteSession = { session: ChatSessionHistory ->
176
161
val result = Messages .showYesNoDialog(
177
162
project,
@@ -193,9 +178,9 @@ class ViewHistoryAction : AnAction(
193
178
scrollPane.border = null
194
179
195
180
// 设置 Popup 的固定宽度和自适应高度
196
- val popupWidth = 450
181
+ val popupWidth = 400
197
182
val maxPopupHeight = 400
198
- val itemHeight = 50
183
+ val itemHeight = 35 // 与fixedCellHeight一致
199
184
val calculatedHeight = (sessions.size * itemHeight + 20 ).coerceAtMost(maxPopupHeight)
200
185
201
186
scrollPane.preferredSize = Dimension (popupWidth, calculatedHeight)
@@ -224,8 +209,8 @@ class ViewHistoryAction : AnAction(
224
209
225
210
val popup: JBPopup = popupBuilder.createPopup()
226
211
227
- // 设置 Popup 的最小和最大尺寸
228
- popup.setMinimumSize(Dimension (popupWidth , 150 ))
212
+ // 设置 Popup 的最小尺寸
213
+ popup.setMinimumSize(Dimension (300 , 150 ))
229
214
230
215
jbList.addListSelectionListener {
231
216
if (! it.valueIsAdjusting && jbList.selectedIndex != - 1 ) {
0 commit comments