mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-12 05:51:28 +00:00
272 - Fix editor actions when createNewChatOnEachAction cfg is turned on (#283)
This commit is contained in:
parent
ecf6ac02ed
commit
2317b54d56
2 changed files with 20 additions and 33 deletions
|
|
@ -33,7 +33,7 @@ public class EditorActionsUtil {
|
|||
public static String[][] toArray(Map<String, String> actionsMap) {
|
||||
return actionsMap.entrySet()
|
||||
.stream()
|
||||
.map((entry) -> new String[] {entry.getKey(), entry.getValue()})
|
||||
.map((entry) -> new String[]{entry.getKey(), entry.getValue()})
|
||||
.collect(toList())
|
||||
.toArray(new String[0][0]);
|
||||
}
|
||||
|
|
@ -66,10 +66,6 @@ public class EditorActionsUtil {
|
|||
var toolWindow = toolWindowContentManager.getToolWindow();
|
||||
if (toolWindow != null) {
|
||||
toolWindow.show();
|
||||
|
||||
if (ConfigurationState.getInstance().isCreateNewChatOnEachAction()) {
|
||||
toolWindowContentManager.createNewTabPanel();
|
||||
}
|
||||
}
|
||||
toolWindowContentManager.sendMessage(message);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import ee.carlrobert.codegpt.conversations.ConversationService;
|
|||
import ee.carlrobert.codegpt.conversations.ConversationsState;
|
||||
import ee.carlrobert.codegpt.conversations.message.Message;
|
||||
import ee.carlrobert.codegpt.settings.configuration.ConfigurationState;
|
||||
import ee.carlrobert.codegpt.toolwindow.chat.ChatToolWindowTabPanel;
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
|
@ -27,18 +26,6 @@ public final class StandardChatToolWindowContentManager {
|
|||
}
|
||||
|
||||
public void sendMessage(Message message) {
|
||||
var chatTabbedPane = tryFindChatTabbedPane();
|
||||
if (chatTabbedPane.isPresent()) {
|
||||
var activeTabPanel = chatTabbedPane.get().tryFindActiveTabPanel();
|
||||
if (activeTabPanel.isPresent()) {
|
||||
sendMessage(activeTabPanel.get(), message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
sendMessage(createNewTabPanel(), message);
|
||||
}
|
||||
|
||||
public void sendMessage(ChatToolWindowTabPanel toolWindowTabPanel, Message message) {
|
||||
var toolWindow = getToolWindow();
|
||||
if (toolWindow != null) {
|
||||
toolWindow.show();
|
||||
|
|
@ -46,10 +33,14 @@ public final class StandardChatToolWindowContentManager {
|
|||
|
||||
if (ConfigurationState.getInstance().isCreateNewChatOnEachAction()
|
||||
|| ConversationsState.getCurrentConversation() == null) {
|
||||
ConversationService.getInstance().startConversation();
|
||||
} else {
|
||||
toolWindowTabPanel.sendMessage(message);
|
||||
createNewTabPanel().sendMessage(message);
|
||||
return;
|
||||
}
|
||||
|
||||
tryFindChatTabbedPane()
|
||||
.map(tabbedPane -> tabbedPane.tryFindActiveTabPanel().orElseGet(this::createNewTabPanel))
|
||||
.orElseGet(this::createNewTabPanel)
|
||||
.sendMessage(message);
|
||||
}
|
||||
|
||||
public void displayConversation(@NotNull Conversation conversation) {
|
||||
|
|
@ -64,15 +55,15 @@ public final class StandardChatToolWindowContentManager {
|
|||
|
||||
public StandardChatToolWindowTabPanel createNewTabPanel() {
|
||||
displayChatTab();
|
||||
var tabbedPane = tryFindChatTabbedPane();
|
||||
if (tabbedPane.isPresent()) {
|
||||
var panel = new StandardChatToolWindowTabPanel(
|
||||
project,
|
||||
ConversationService.getInstance().startConversation());
|
||||
tabbedPane.get().addNewTab(panel);
|
||||
return panel;
|
||||
}
|
||||
return null;
|
||||
return tryFindChatTabbedPane()
|
||||
.map(item -> {
|
||||
var panel = new StandardChatToolWindowTabPanel(
|
||||
project,
|
||||
ConversationService.getInstance().startConversation());
|
||||
item.addNewTab(panel);
|
||||
return panel;
|
||||
})
|
||||
.orElseThrow();
|
||||
}
|
||||
|
||||
public void displayChatTab() {
|
||||
|
|
@ -80,14 +71,14 @@ public final class StandardChatToolWindowContentManager {
|
|||
toolWindow.show();
|
||||
|
||||
var contentManager = toolWindow.getContentManager();
|
||||
tryFindChatTabContent().ifPresentOrElse(
|
||||
tryFindFirstChatTabContent().ifPresentOrElse(
|
||||
contentManager::setSelectedContent,
|
||||
() -> contentManager.setSelectedContent(requireNonNull(contentManager.getContent(0)))
|
||||
);
|
||||
}
|
||||
|
||||
public Optional<StandardChatToolWindowTabbedPane> tryFindChatTabbedPane() {
|
||||
var chatTabContent = tryFindChatTabContent();
|
||||
var chatTabContent = tryFindFirstChatTabContent();
|
||||
if (chatTabContent.isPresent()) {
|
||||
var tabbedPane = Arrays.stream(chatTabContent.get().getComponent().getComponents())
|
||||
.filter(component -> component instanceof StandardChatToolWindowTabbedPane)
|
||||
|
|
@ -112,7 +103,7 @@ public final class StandardChatToolWindowContentManager {
|
|||
return requireNonNull(ToolWindowManager.getInstance(project).getToolWindow("CodeGPT"));
|
||||
}
|
||||
|
||||
private Optional<Content> tryFindChatTabContent() {
|
||||
private Optional<Content> tryFindFirstChatTabContent() {
|
||||
return Arrays.stream(getToolWindow().getContentManager().getContents())
|
||||
.filter(content -> "Chat".equals(content.getTabName()))
|
||||
.findFirst();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue