diff --git a/clients/intellij/src/main/kotlin/com/tabbyml/intellijtabby/widgets/ChatToolWindowFactory.kt b/clients/intellij/src/main/kotlin/com/tabbyml/intellijtabby/widgets/ChatToolWindowFactory.kt index 7fa0b0fbcbc7..b55a1143e7bc 100644 --- a/clients/intellij/src/main/kotlin/com/tabbyml/intellijtabby/widgets/ChatToolWindowFactory.kt +++ b/clients/intellij/src/main/kotlin/com/tabbyml/intellijtabby/widgets/ChatToolWindowFactory.kt @@ -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() + override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) { - val chatBrowserFactory = project.service() - val browser = chatBrowserFactory.createChatBrowser(toolWindow) - val content = ContentFactory.getInstance().createContent(browser.component, "", false) - toolWindow.contentManager.addContent(content) + try { + val chatBrowserFactory = project.service() + 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 = + """ + + Failed to create the chat panel.
+ Please check the online documentation for trouble shooting. + + """.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 {