Skip to content

Commit 105a990

Browse files
committed
feat(gui): add toolbar with clear button and file selection reminder #344
- Replace clear button with a toolbar containing both the button and a reminder label - Update clear button to remove all elements instead of keeping last 3 - Add new string resources for file selection reminder
1 parent bad095f commit 105a990

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

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

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -172,26 +172,10 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
172172
scrollPane.verticalScrollBarPolicy = JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED
173173
scrollPane.horizontalScrollBarPolicy = JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED
174174

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-
}
175+
val toolbar = setupToolbar()
192176

193177
val headerPanel = JPanel(BorderLayout())
194-
headerPanel.add(clearButton, BorderLayout.NORTH)
178+
headerPanel.add(toolbar, BorderLayout.NORTH)
195179
headerPanel.add(scrollPane, BorderLayout.CENTER)
196180

197181
this.add(headerPanel, BorderLayout.NORTH)
@@ -303,6 +287,28 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
303287
elements?.forEach { listModel.addIfAbsent(it.containingFile.virtualFile) }
304288
}
305289

290+
private fun setupToolbar(): JToolBar {
291+
val toolbar = JToolBar()
292+
toolbar.isFloatable = false
293+
294+
val reminderLabel = JBLabel(AutoDevBundle.message("chat.panel.select.files"))
295+
reminderLabel.border = JBUI.Borders.empty(5)
296+
reminderLabel.foreground = UIUtil.getContextHelpForeground()
297+
toolbar.add(reminderLabel)
298+
299+
toolbar.add(Box.createHorizontalGlue())
300+
301+
val clearButton = JButton(AutoDevBundle.message("chat.panel.clear.all")).apply {
302+
toolTipText = AutoDevBundle.message("chat.panel.clear.all.tooltip")
303+
addActionListener {
304+
listModel.removeAllElements()
305+
}
306+
}
307+
308+
toolbar.add(clearButton)
309+
return toolbar
310+
}
311+
306312
fun showStopButton() {
307313
(buttonPanel.layout as? CardLayout)?.show(buttonPanel, "Stop")
308314
stopButton.isEnabled = true

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,4 @@ chat.panel.clear.all=Clear All
189189
chat.panel.clear.all.tooltip=Clear all files except the last 3 used
190190
chat.panel.clear.all.title=Confirm Clear
191191
chat.panel.clear.all.confirm=Are you sure you want to clear all files except the last 3 used?
192+
chat.panel.select.files=Please select files to put in the input box

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,4 @@ chat.panel.clear.all=Clear All
183183
chat.panel.clear.all.tooltip=Clear all files except the last 3 used
184184
chat.panel.clear.all.title=Confirm Clear
185185
chat.panel.clear.all.confirm=Are you sure you want to clear all files except the last 3 used?
186+
chat.panel.select.files=请选择文件以放到输入框内

0 commit comments

Comments
 (0)