refactor: ToolWindowFactory class

This commit is contained in:
Carl-Robert Linnupuu 2025-06-08 09:13:17 +01:00
parent cd9bf3d3ab
commit 155358084e
3 changed files with 39 additions and 37 deletions

View file

@ -1,36 +0,0 @@
package ee.carlrobert.codegpt.toolwindow;
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.content.ContentManagerEvent;
import com.intellij.ui.content.ContentManagerListener;
import ee.carlrobert.codegpt.toolwindow.chat.ChatToolWindowPanel;
import ee.carlrobert.codegpt.toolwindow.conversations.ConversationsToolWindow;
import javax.swing.JComponent;
import org.jetbrains.annotations.NotNull;
public class ProjectToolWindowFactory implements ToolWindowFactory, DumbAware {
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
var chatToolWindowPanel = new ChatToolWindowPanel(project, toolWindow.getDisposable());
var conversationsToolWindow = new ConversationsToolWindow(project);
addContent(toolWindow, chatToolWindowPanel, "Chat");
addContent(toolWindow, conversationsToolWindow.getContent(), "Chat History");
toolWindow.addContentManagerListener(new ContentManagerListener() {
public void selectionChanged(@NotNull ContentManagerEvent event) {
var content = event.getContent();
if ("Chat History".equals(content.getTabName()) && content.isSelected()) {
conversationsToolWindow.refresh();
}
}
});
}
public void addContent(ToolWindow toolWindow, JComponent panel, String displayName) {
var contentManager = toolWindow.getContentManager();
contentManager.addContent(contentManager.getFactory().createContent(panel, displayName, false));
}
}

View file

@ -0,0 +1,38 @@
package ee.carlrobert.codegpt.toolwindow
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.content.ContentManagerEvent
import com.intellij.ui.content.ContentManagerListener;
import ee.carlrobert.codegpt.toolwindow.chat.ChatToolWindowPanel
import ee.carlrobert.codegpt.toolwindow.conversations.ConversationsToolWindow
import javax.swing.JComponent
class ProxyAIToolWindowFactory : ToolWindowFactory, DumbAware {
override fun createToolWindowContent(
project: Project,
toolWindow: ToolWindow
) {
var chatToolWindowPanel = ChatToolWindowPanel(project, toolWindow.disposable)
var conversationsToolWindow = ConversationsToolWindow(project)
addContent(toolWindow, chatToolWindowPanel, "Chat")
addContent(toolWindow, conversationsToolWindow.getContent(), "Chat History")
toolWindow.addContentManagerListener(object : ContentManagerListener {
override fun selectionChanged(event: ContentManagerEvent) {
if ("Chat History" == event.content.tabName && event.content.isSelected) {
conversationsToolWindow.refresh()
}
}
})
}
private fun addContent(toolWindow: ToolWindow, panel: JComponent, displayName: String) {
toolWindow.contentManager.let {
it.addContent(it.factory.createContent(panel, displayName, false))
}
}
}

View file

@ -76,7 +76,7 @@
id="CodeGPTInlineCompletionProvider"
implementation="ee.carlrobert.codegpt.codecompletions.DebouncedCodeCompletionProvider"/>
<toolWindow id="ProxyAI" icon="ee.carlrobert.codegpt.Icons.DefaultSmall" anchor="right"
factoryClass="ee.carlrobert.codegpt.toolwindow.ProjectToolWindowFactory"/>
factoryClass="ee.carlrobert.codegpt.toolwindow.ProxyAIToolWindowFactory"/>
<notificationGroup id="proxyai.notification.group" displayType="BALLOON" key="notification.group.name"/>
<notificationGroup id="proxyai.notification.sticky.group" displayType="STICKY_BALLOON" key="notification.group.sticky.name"/>
<statusBarWidgetFactory order="first" id="ee.carlrobert.codegpt.statusbar.widget"