refactor: ToolWindowFactory class

This commit is contained in:
Carl-Robert Linnupuu 2025-06-08 09:13:17 +01:00
parent f6ccf201f4
commit 06e0484f8c
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));
}
}