mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-16 11:15:34 +00:00
Add tabs for multiple concurrent conversations (#54)
This commit is contained in:
parent
638fb557a7
commit
3d104c8b5a
11 changed files with 158 additions and 94 deletions
|
|
@ -1,16 +1,23 @@
|
|||
package ee.carlrobert.codegpt.toolwindow;
|
||||
|
||||
import com.intellij.openapi.actionSystem.ActionManager;
|
||||
import com.intellij.openapi.actionSystem.ActionToolbar;
|
||||
import com.intellij.openapi.actionSystem.DefaultActionGroup;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.SimpleToolWindowPanel;
|
||||
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 com.intellij.ui.jcef.JBCefBrowser;
|
||||
import ee.carlrobert.codegpt.client.ClientFactory;
|
||||
import ee.carlrobert.codegpt.account.AccountDetailsState;
|
||||
import ee.carlrobert.codegpt.client.ClientFactory;
|
||||
import ee.carlrobert.codegpt.conversations.ConversationsState;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.ChatGptToolWindow;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.ChatTabbedPane;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.ChatToolWindowPanel;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.actions.CreateNewConversationAction;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.actions.OpenInEditorAction;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.actions.UsageToolbarLabelAction;
|
||||
import ee.carlrobert.codegpt.toolwindow.conversations.ConversationsToolWindow;
|
||||
import javax.swing.JComponent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
|
@ -18,15 +25,18 @@ import org.jetbrains.annotations.NotNull;
|
|||
public class ProjectToolWindowFactory implements ToolWindowFactory, DumbAware {
|
||||
|
||||
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
|
||||
var chatToolWindow = new ChatGptToolWindow(project);
|
||||
var chatToolWindow = new ChatToolWindowPanel(project);
|
||||
var conversationsToolWindow = new ConversationsToolWindow(project);
|
||||
var toolWindowService = project.getService(ToolWindowService.class);
|
||||
toolWindowService.setChatToolWindow(chatToolWindow);
|
||||
var toolWindowPanel = new SimpleToolWindowPanel(true);
|
||||
|
||||
var contentManagerService = project.getService(ContentManagerService.class);
|
||||
addContent(toolWindow, chatToolWindow.getContent(), "Chat");
|
||||
var chatTabbedPane = new ChatTabbedPane();
|
||||
chatTabbedPane.addTab("Chat 1", chatToolWindow);
|
||||
|
||||
toolWindowPanel.setToolbar(createActionToolbar(project, chatTabbedPane, toolWindowPanel).getComponent());
|
||||
toolWindowPanel.setContent(chatTabbedPane);
|
||||
|
||||
addContent(toolWindow, toolWindowPanel, "Chat");
|
||||
addContent(toolWindow, conversationsToolWindow.getContent(), "Conversation History");
|
||||
addContent(toolWindow, new JBCefBrowser("https://chat.openai.com/chat").getComponent(), "Browser");
|
||||
toolWindow.addContentManagerListener(new ContentManagerListener() {
|
||||
public void selectionChanged(@NotNull ContentManagerEvent event) {
|
||||
var content = event.getContent();
|
||||
|
|
@ -43,6 +53,7 @@ public class ProjectToolWindowFactory implements ToolWindowFactory, DumbAware {
|
|||
}
|
||||
});
|
||||
|
||||
var contentManagerService = project.getService(ContentManagerService.class);
|
||||
if (contentManagerService.isChatTabSelected(toolWindow.getContentManager())) {
|
||||
var conversation = ConversationsState.getCurrentConversation();
|
||||
if (conversation == null) {
|
||||
|
|
@ -58,4 +69,22 @@ public class ProjectToolWindowFactory implements ToolWindowFactory, DumbAware {
|
|||
var content = contentManager.getFactory().createContent(panel, displayName, false);
|
||||
contentManager.addContent(content);
|
||||
}
|
||||
|
||||
private ActionToolbar createActionToolbar(Project project, ChatTabbedPane tabbedPane, SimpleToolWindowPanel toolWindowPanel) {
|
||||
var actionGroup = new DefaultActionGroup("TOOLBAR_ACTION_GROUP", false);
|
||||
actionGroup.add(new CreateNewConversationAction(() -> {
|
||||
tabbedPane.addTab("Chat " + (tabbedPane.getTabCount() + 1), new ChatToolWindowPanel(project));
|
||||
tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
|
||||
toolWindowPanel.repaint();
|
||||
toolWindowPanel.revalidate();
|
||||
}));
|
||||
actionGroup.add(new OpenInEditorAction());
|
||||
actionGroup.addSeparator();
|
||||
actionGroup.add(new UsageToolbarLabelAction());
|
||||
|
||||
// TODO: Data usage not enabled in stream mode https://community.openai.com/t/usage-info-in-api-responses/18862/11
|
||||
// actionGroup.add(new TokenToolbarLabelAction());
|
||||
|
||||
return ActionManager.getInstance().createActionToolbar("NAVIGATION_BAR_TOOLBAR", actionGroup, false);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue