Skip to content

Commit

Permalink
fix(intellij): add help message when failed to create chat panel. (#3461
Browse files Browse the repository at this point in the history
)
  • Loading branch information
icycodes authored Nov 24, 2024
1 parent 344c9c6 commit 3b77c9c
Showing 1 changed file with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,49 @@
package com.tabbyml.intellijtabby.widgets

import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.project.DumbAware
import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.ToolWindow
import com.intellij.openapi.wm.ToolWindowFactory
import com.intellij.ui.components.JBLabel
import com.intellij.ui.content.ContentFactory
import com.intellij.util.ui.JBUI
import com.tabbyml.intellijtabby.chat.ChatBrowserFactory
import java.awt.GridBagLayout
import javax.swing.JPanel

class ChatToolWindowFactory : ToolWindowFactory, DumbAware {
private val logger = logger<ChatToolWindowFactory>()

override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
val chatBrowserFactory = project.service<ChatBrowserFactory>()
val browser = chatBrowserFactory.createChatBrowser(toolWindow)
val content = ContentFactory.getInstance().createContent(browser.component, "", false)
toolWindow.contentManager.addContent(content)
try {
val chatBrowserFactory = project.service<ChatBrowserFactory>()
val browser = chatBrowserFactory.createChatBrowser(toolWindow)
val content = ContentFactory.getInstance().createContent(browser.component, "", false)
toolWindow.contentManager.addContent(content)
} catch (e: Exception) {
logger.warn("Failed to create chat tool window", e)

val helpMessage =
"""
<html>
Failed to create the chat panel.<br/>
Please check the <a href=\"https://tabby.tabbyml.com/docs/extensions/troubleshooting/#check-browser-compatibility-in-intellij-platform-ides\">online documentation</a> for trouble shooting.
</html>
""".trimIndent()
val label = JBLabel(helpMessage).apply {
setBorder(JBUI.Borders.emptyLeft(20))
setCopyable(true)
}
val panel = JPanel().apply {
setLayout(GridBagLayout())
add(label)
}

val content = ContentFactory.getInstance().createContent(panel, "", false)
toolWindow.contentManager.addContent(content)
}
}

companion object {
Expand Down

0 comments on commit 3b77c9c

Please sign in to comment.