Skip to content

Commit 659afd5

Browse files
committed
feat(chat): implement new chat action and UI enhancements
- Add `NewChatAction` with functionality to reset chat session. - Enable closing contents in tool window configuration. - Update `AutoDevToolWindowFactory` to set title actions. - Enhance `NormalChatCodingPanel` with a header containing the new chat button.
1 parent 42491f4 commit 659afd5

File tree

5 files changed

+40
-11
lines changed

5 files changed

+40
-11
lines changed

core/src/223/main/resources/META-INF/autodev-core.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
doNotActivateOnStart="true"
6161
anchor="right"
6262
secondary="false"
63-
canCloseContents="false"
63+
canCloseContents="true"
6464
icon="cc.unitmesh.devti.AutoDevIcons.AI_COPILOT"
6565
factoryClass="cc.unitmesh.devti.gui.AutoDevToolWindowFactory"/>
6666

core/src/233/main/resources/META-INF/autodev-core.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
doNotActivateOnStart="true"
6060
anchor="right"
6161
secondary="false"
62-
canCloseContents="false"
62+
canCloseContents="true"
6363
icon="cc.unitmesh.devti.AutoDevIcons.AI_COPILOT"
6464
factoryClass="cc.unitmesh.devti.gui.AutoDevToolWindowFactory"/>
6565

core/src/main/kotlin/cc/unitmesh/devti/gui/AutoDevToolWindowFactory.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package cc.unitmesh.devti.gui
22

33
import cc.unitmesh.devti.bridge.BridgeToolWindow
4-
import cc.unitmesh.devti.gui.chat.message.ChatActionType
5-
import cc.unitmesh.devti.gui.chat.NormalChatCodingPanel
64
import cc.unitmesh.devti.gui.chat.ChatCodingService
5+
import cc.unitmesh.devti.gui.chat.NormalChatCodingPanel
6+
import cc.unitmesh.devti.gui.chat.message.ChatActionType
77
import cc.unitmesh.devti.inline.AutoDevInlineChatProvider
8-
import cc.unitmesh.devti.sketch.SketchToolWindow
98
import cc.unitmesh.devti.settings.locale.LanguageChangedCallback.componentStateChanged
9+
import cc.unitmesh.devti.sketch.SketchToolWindow
1010
import com.intellij.openapi.application.ApplicationManager
1111
import com.intellij.openapi.project.DumbAware
1212
import com.intellij.openapi.project.Project
@@ -79,7 +79,6 @@ class AutoDevToolWindowFactory : ToolWindowFactory, DumbAware {
7979
?.firstOrNull()
8080
}
8181

82-
8382
fun createNormalChatWindow(project: Project, toolWindow: ToolWindow) {
8483
val chatCodingService = ChatCodingService(ChatActionType.CHAT, project)
8584
val contentPanel = NormalChatCodingPanel(chatCodingService, toolWindow.disposable)

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ import cc.unitmesh.devti.gui.chat.ui.AutoDevInputTrigger
1414
import cc.unitmesh.devti.gui.chat.view.FrontendCodeView
1515
import cc.unitmesh.devti.gui.chat.view.MessageView
1616
import cc.unitmesh.devti.gui.chat.welcome.WelcomePanel
17+
import cc.unitmesh.devti.gui.toolbar.NewChatAction
1718
import cc.unitmesh.devti.provider.ContextPrompter
1819
import cc.unitmesh.devti.provider.devins.LanguageProcessor
1920
import cc.unitmesh.devti.settings.AutoDevSettingsState
2021
import cc.unitmesh.devti.settings.locale.LanguageChangedCallback.componentStateChanged
22+
import cc.unitmesh.devti.sketch.createActionButton
2123
import com.intellij.lang.html.HTMLLanguage
2224
import com.intellij.openapi.Disposable
2325
import com.intellij.openapi.project.Project
@@ -49,8 +51,7 @@ import java.awt.event.MouseEvent
4951
import javax.swing.*
5052

5153
class NormalChatCodingPanel(private val chatCodingService: ChatCodingService, val disposable: Disposable?) :
52-
SimpleToolWindowPanel(true, true),
53-
NullableComponent {
54+
SimpleToolWindowPanel(true, true), NullableComponent {
5455
private var progressBar: JProgressBar
5556
private val myTitle = JBLabel("Conversation")
5657
private val myList = JPanel(VerticalLayout(JBUI.scale(10)))
@@ -127,7 +128,20 @@ class NormalChatCodingPanel(private val chatCodingService: ChatCodingService, va
127128
}
128129
})
129130

131+
132+
val header = panel {
133+
row {
134+
createActionButton(NewChatAction()).alignRight()
135+
}
136+
}
137+
138+
header.border = JBUI.Borders.compound(
139+
JBUI.Borders.customLine(UIUtil.getBoundsColor(), 0, 0, 1, 0),
140+
JBUI.Borders.empty(0, 4)
141+
)
142+
130143
panelContent = panel {
144+
row { cell(header).fullWidth() }
131145
row { cell(myScrollPane).fullWidth().fullHeight() }.resizableRow()
132146
row { cell(suggestionPanel).fullWidth() }
133147
row { cell(progressBar).fullWidth() }
@@ -136,6 +150,8 @@ class NormalChatCodingPanel(private val chatCodingService: ChatCodingService, va
136150
border = JBUI.Borders.empty(8)
137151
cell(inputSection).fullWidth()
138152
}
153+
}.also {
154+
it.border = JBUI.Borders.empty()
139155
}
140156

141157
setContent(panelContent)

core/src/main/kotlin/cc/unitmesh/devti/gui/toolbar/NewChatAction.kt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,33 @@ import com.intellij.icons.AllIcons
66
import com.intellij.openapi.actionSystem.*
77
import com.intellij.openapi.actionSystem.ex.CustomComponentAction
88
import com.intellij.openapi.diagnostic.logger
9-
import com.intellij.openapi.project.DumbAwareAction
109
import com.intellij.openapi.util.Key
1110
import com.intellij.ui.components.panels.Wrapper
1211
import com.intellij.util.ui.JBDimension
1312
import com.intellij.util.ui.JBUI
1413
import javax.swing.JButton
1514
import javax.swing.JComponent
1615

17-
class NewChatAction : DumbAwareAction(), CustomComponentAction {
16+
class NewChatAction : AnAction("New Chat", "Create new Chat", AllIcons.General.Add), CustomComponentAction {
1817
private val logger = logger<NewChatAction>()
1918
val AVOID_EXTENDING_BORDER_GRAPHICS = Key.create<Boolean>("JButton.avoidExtendingBorderGraphics")
2019

21-
override fun actionPerformed(e: AnActionEvent) = Unit
20+
override fun actionPerformed(e: AnActionEvent) {
21+
val dataContext: DataContext = e.dataContext
22+
val project = dataContext.getData(CommonDataKeys.PROJECT)
23+
if (project == null) {
24+
logger.error("project is null")
25+
return
26+
}
27+
28+
val toolWindowManager = AutoDevToolWindowFactory.getToolWindow(project)
29+
val contentManager = toolWindowManager?.contentManager
30+
31+
val codingPanel =
32+
contentManager?.component?.components?.filterIsInstance<NormalChatCodingPanel>()?.firstOrNull()
33+
34+
codingPanel?.resetChatSession()
35+
}
2236

2337
override fun createCustomComponent(presentation: Presentation, place: String): JComponent {
2438
val button: JButton = object : JButton(AllIcons.General.Add) {

0 commit comments

Comments
 (0)