@@ -8,18 +8,25 @@ import cc.unitmesh.devti.sketch.ui.LanguageSketchProvider
8
8
import cc.unitmesh.devti.sketch.ui.MarkdownPreviewHighlightSketch
9
9
import cc.unitmesh.devti.sketch.ui.code.CodeHighlightSketch
10
10
import cc.unitmesh.devti.util.parser.CodeFence
11
+ import com.intellij.icons.AllIcons
12
+ import com.intellij.openapi.actionSystem.ActionManager
13
+ import com.intellij.openapi.actionSystem.ActionToolbar
14
+ import com.intellij.openapi.actionSystem.AnAction
15
+ import com.intellij.openapi.actionSystem.AnActionEvent
16
+ import com.intellij.openapi.actionSystem.DefaultActionGroup
11
17
import com.intellij.openapi.application.ApplicationManager
12
18
import com.intellij.openapi.application.runInEdt
13
19
import com.intellij.openapi.fileTypes.PlainTextLanguage
14
20
import com.intellij.openapi.project.Project
15
21
import com.intellij.openapi.ui.DialogPanel
16
- import com.intellij.ui.JBColor
17
22
import com.intellij.ui.components.JBPanel
18
23
import com.intellij.ui.components.panels.VerticalLayout
19
24
import com.intellij.ui.dsl.builder.panel
20
25
import com.intellij.util.ui.JBFont
21
26
import com.intellij.util.ui.JBUI
22
27
import java.awt.BorderLayout
28
+ import java.awt.Toolkit
29
+ import java.awt.datatransfer.StringSelection
23
30
import javax.swing.JLabel
24
31
import javax.swing.JPanel
25
32
@@ -58,8 +65,10 @@ class MessageView(val project: Project, val message: String, val role: ChatRole,
58
65
val centerPanel = JPanel (VerticalLayout (JBUI .scale(8 )))
59
66
centerPanel.add(authorLabel)
60
67
61
- if (role == ChatRole .User ) {
62
- runInEdt {
68
+ val toolbar = createViewActionGroup().component
69
+ runInEdt {
70
+ centerPanel.add(toolbar)
71
+ if (role == ChatRole .User ) {
63
72
myList.add(createSingleTextView(project, message))
64
73
}
65
74
}
@@ -139,6 +148,25 @@ class MessageView(val project: Project, val message: String, val role: ChatRole,
139
148
}
140
149
}
141
150
151
+
152
+ fun createViewActionGroup (): ActionToolbar {
153
+ val copyAction = object : AnAction (" Copy" , " Copy text" , AllIcons .Actions .Copy ) {
154
+ override fun actionPerformed (e : AnActionEvent ) {
155
+ val clipboard = Toolkit .getDefaultToolkit().systemClipboard
156
+ val selection = StringSelection (displayText)
157
+ clipboard.setContents(selection, null )
158
+ }
159
+ }
160
+
161
+ val actionGroup = DefaultActionGroup (listOf (copyAction))
162
+ val rightToolbar = ActionManager .getInstance()
163
+ .createActionToolbar(" AutoDevCopyView" , actionGroup, true )
164
+
165
+ rightToolbar.setTargetComponent(this )
166
+
167
+ return rightToolbar
168
+ }
169
+
142
170
companion object {
143
171
fun createSingleTextView (project : Project , text : String , language : String = "markdown"): DialogPanel {
144
172
val codeBlockViewer = CodeHighlightSketch (project, text, CodeFence .findLanguage(language)).apply {
0 commit comments