Skip to content

Commit

Permalink
feat(ui): update for bottom
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Aug 3, 2023
1 parent 07301b2 commit 00cc025
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/main/kotlin/cc/unitmesh/devti/gui/block/SimpleMessage.kt
@@ -1,11 +1,13 @@
package cc.unitmesh.devti.gui.block

import cc.unitmesh.devti.gui.chat.ChatRole
import cc.unitmesh.devti.gui.chat.message.ChatMessageRating

class SimpleMessage(
override val displayText: String,
override val text: String,
val chatRole: ChatRole
val chatRole: ChatRole,
override var rating: ChatMessageRating = ChatMessageRating.None
) : CompletableMessage {
private val textListeners: MutableList<MessageBlockTextListener> = mutableListOf()
override fun getRole(): ChatRole = chatRole
Expand Down
Expand Up @@ -175,7 +175,7 @@ class ChatCodingPanel(private val chatCodingService: ChatCodingService, val disp
messageView.scrollToBottom()
}

messageView.doneContent()
messageView.reRenderAssistantOutput()

return text
}
Expand Down
42 changes: 40 additions & 2 deletions src/main/kotlin/cc/unitmesh/devti/gui/chat/MessageView.kt
Expand Up @@ -2,20 +2,25 @@ package cc.unitmesh.devti.gui.chat


import cc.unitmesh.devti.gui.block.*
import com.intellij.openapi.actionSystem.ex.ActionUtil
import com.intellij.openapi.actionSystem.impl.ActionToolbarImpl
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.project.ProjectManager
import com.intellij.ui.JBColor
import com.intellij.ui.components.JBPanel
import com.intellij.ui.components.panels.VerticalLayout
import com.intellij.util.ui.JBEmptyBorder
import com.intellij.util.ui.JBFont
import com.intellij.util.ui.JBUI
import com.intellij.util.ui.components.BorderLayoutPanel
import java.awt.*
import javax.swing.*
import kotlin.jvm.internal.Ref

class MessageView(private val message: String, role: ChatRole, private val displayText: String) :
class MessageView(private val message: String, val role: ChatRole, private val displayText: String) :
JBPanel<MessageView>() {
private val myNameLabel: Component
private val component: DisplayComponent = DisplayComponent(message)
private var answer: String? = null
private var centerPanel: JPanel = JPanel(VerticalLayout(JBUI.scale(8)))
Expand All @@ -29,13 +34,23 @@ class MessageView(private val message: String, role: ChatRole, private val displ
ChatRole.User -> JBColor(0xE0EEF7, 0x2d2f30)
}

val authorLabel = JLabel()
authorLabel.setFont(JBFont.h4())
authorLabel.setText(when (role) {
ChatRole.System -> "System"
ChatRole.Assistant -> "Assistant"
ChatRole.User -> "User"
})
myNameLabel = authorLabel

this.border = JBEmptyBorder(8)
layout = BorderLayout(JBUI.scale(8), 0)

centerPanel = JPanel(VerticalLayout(JBUI.scale(8)))
centerPanel.isOpaque = false
centerPanel.border = JBUI.Borders.emptyRight(8)

centerPanel.add(myNameLabel)
add(centerPanel, BorderLayout.CENTER)

if (role == ChatRole.User) {
Expand All @@ -49,6 +64,25 @@ class MessageView(private val message: String, role: ChatRole, private val displ
}
}

private fun createTitlePanel(): JPanel {
val borderLayoutPanel = BorderLayoutPanel()
borderLayoutPanel.setOpaque(false)
borderLayoutPanel.addToCenter(this.myNameLabel)
val group = ActionUtil.getActionGroup("AutoDev.ToolWindow.Message.Toolbar.Assistant")

if (group != null) {
val actionToolbar = ActionToolbarImpl(javaClass.getName(), group, true)
actionToolbar.setLayoutPolicy(0)
actionToolbar.component.setOpaque(false)
actionToolbar.component.setBorder(JBUI.Borders.empty())
actionToolbar.setTargetComponent(this)
borderLayoutPanel.addToRight(actionToolbar.component)
}

borderLayoutPanel.setOpaque(false)
return borderLayoutPanel
}

private fun renderInPartView(message: SimpleMessage) {
val parts = layoutAll(message)
parts.forEach {
Expand Down Expand Up @@ -81,11 +115,15 @@ class MessageView(private val message: String, role: ChatRole, private val displ
}
}

fun doneContent() {
fun reRenderAssistantOutput() {
val displayText = component.text

ApplicationManager.getApplication().invokeLater {
centerPanel.remove(component)
centerPanel.updateUI()

centerPanel.add(myNameLabel)
centerPanel.add(createTitlePanel())

val message = SimpleMessage(displayText, displayText, ChatRole.Assistant)
renderInPartView(message)
Expand Down
Expand Up @@ -19,16 +19,13 @@ abstract class AutoDevRateMessageAction : DumbAwareToggleAction() {
abstract fun getReactionIconSelected(): Icon

private fun getMessage(event: AnActionEvent): CompletableMessage? {
return event.dataContext.getData<CompletableMessage>(CompletableMessage.key)
return event.dataContext.getData(CompletableMessage.key)
}

override fun update(e: AnActionEvent) {
super.update(e)
val icon: Icon = if (!isSelected(e)) getReactionIcon() else getReactionIconSelected()
e.presentation.setIcon(icon)

// SET HOVER TOOLTIP FOR icon
e.presentation.description = "Like this message"
}

override fun isSelected(e: AnActionEvent): Boolean {
Expand Down

0 comments on commit 00cc025

Please sign in to comment.