Skip to content

Commit bad095f

Browse files
committed
feat(gui): add clear all button and improve file display in AutoDev input section
- Add clear all button to remove all files except the last 3 used - Implement confirmation dialog for clear all action - Update file display to show more detailed path information - Add tool tips for file items - Refactor layout of input section to accommodate new clear all button
1 parent deb11c0 commit bad095f

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

core/src/main/kotlin/cc/unitmesh/devti/gui/chat/ui/AutoDevInputSection.kt

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,33 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
168168
inputPanel.add(input, BorderLayout.CENTER)
169169
inputPanel.addToBottom(layoutPanel)
170170

171-
// 将 elementsList 放入 JScrollPane 中
172171
val scrollPane = JBScrollPane(elementsList)
173172
scrollPane.verticalScrollBarPolicy = JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED
174173
scrollPane.horizontalScrollBarPolicy = JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED
175-
this.add(scrollPane, BorderLayout.NORTH)
176174

175+
val clearButton = JButton(AutoDevBundle.message("chat.panel.clear.all")).apply {
176+
toolTipText = AutoDevBundle.message("chat.panel.clear.all.tooltip")
177+
addActionListener {
178+
val result = JOptionPane.showConfirmDialog(
179+
this@AutoDevInputSection,
180+
AutoDevBundle.message("chat.panel.clear.all.confirm"),
181+
AutoDevBundle.message("chat.panel.clear.all.title"),
182+
JOptionPane.YES_NO_OPTION
183+
)
184+
185+
if (result == JOptionPane.YES_OPTION) {
186+
while (listModel.size() > 3) {
187+
listModel.removeElementAt(listModel.size() - 1)
188+
}
189+
}
190+
}
191+
}
192+
193+
val headerPanel = JPanel(BorderLayout())
194+
headerPanel.add(clearButton, BorderLayout.NORTH)
195+
headerPanel.add(scrollPane, BorderLayout.CENTER)
196+
197+
this.add(headerPanel, BorderLayout.NORTH)
177198
this.add(inputPanel, BorderLayout.CENTER)
178199

179200
ComponentValidator(disposable!!).withValidator(Supplier<ValidationInfo?> {
@@ -411,6 +432,7 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
411432
if (first) {
412433
insertElementAt(modelWrapper, 0)
413434
} else {
435+
// 保持最近使用的文件在前面
414436
addElement(modelWrapper)
415437
}
416438
}

core/src/main/kotlin/cc/unitmesh/devti/gui/chat/ui/RelatedFileListCellRenderer.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class RelatedFileListCellRenderer(val project: Project) : ListCellRenderer<Model
2828
val namePanel = JPanel(layout)
2929
val iconLabel = JLabel(value.virtualFile.fileType.icon ?: AllIcons.FileTypes.Unknown)
3030
namePanel.add(iconLabel)
31+
namePanel.toolTipText = value.virtualFile.relativePath(project)
3132

3233
val nameLabel = JLabel(buildDisplayName(value))
3334
namePanel.add(nameLabel)
@@ -40,7 +41,6 @@ class RelatedFileListCellRenderer(val project: Project) : ListCellRenderer<Model
4041

4142
value.panel = this
4243
value.namePanel = namePanel
43-
4444
this.toolTipText = value.virtualFile.relativePath(project)
4545
}
4646
val namePanel = value.namePanel
@@ -65,11 +65,15 @@ class RelatedFileListCellRenderer(val project: Project) : ListCellRenderer<Model
6565
*/
6666
private fun buildDisplayName(value: ModelWrapper): @NlsSafe String {
6767
val filename = value.virtualFile.name
68-
// if it's frontend index file, like index.js, index.ts, index.vue, index.html, index.css etc, then show the parent folder name
6968
if (filename.startsWith("index.")) {
7069
val parent = value.virtualFile.parent?.name
7170
if (parent != null) {
72-
return "$parent/$filename"
71+
val grandParent = value.virtualFile.parent?.parent?.name
72+
return if (grandParent != null) {
73+
"$grandParent/$parent/$filename"
74+
} else {
75+
"$parent/$filename"
76+
}
7377
}
7478
}
7579

core/src/main/resources/messages/AutoDevBundle_en.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,9 @@ sketch.patch.view=View
183183
autodev.save.as.file=Save File As
184184
autodev.save.as.file.description=Choose location to save the file
185185
sketch.terminal.show.hide=Show or hide the terminal
186+
187+
chat.panel.stop=Stop
188+
chat.panel.clear.all=Clear All
189+
chat.panel.clear.all.tooltip=Clear all files except the last 3 used
190+
chat.panel.clear.all.title=Confirm Clear
191+
chat.panel.clear.all.confirm=Are you sure you want to clear all files except the last 3 used?

core/src/main/resources/messages/AutoDevBundle_zh.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,9 @@ sketch.patch.view=查看
177177
autodev.save.as.file=保存文件
178178
autodev.save.as.file.description=选择待保存文件位置
179179
sketch.terminal.show.hide=显示或隐藏终端
180+
181+
chat.panel.stop=Stop
182+
chat.panel.clear.all=Clear All
183+
chat.panel.clear.all.tooltip=Clear all files except the last 3 used
184+
chat.panel.clear.all.title=Confirm Clear
185+
chat.panel.clear.all.confirm=Are you sure you want to clear all files except the last 3 used?

0 commit comments

Comments
 (0)