diff --git a/src/main/kotlin/ee/carlrobert/codegpt/actions/FocusAgentInputAction.kt b/src/main/kotlin/ee/carlrobert/codegpt/actions/FocusAgentInputAction.kt new file mode 100644 index 000000000..9e47c199f --- /dev/null +++ b/src/main/kotlin/ee/carlrobert/codegpt/actions/FocusAgentInputAction.kt @@ -0,0 +1,29 @@ +package ee.carlrobert.codegpt.actions + +import com.intellij.openapi.actionSystem.ActionUpdateThread +import com.intellij.openapi.actionSystem.AnAction +import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.wm.ToolWindowManager +import ee.carlrobert.codegpt.toolwindow.agent.AgentToolWindowPanel + +class FocusAgentInputAction : AnAction() { + + override fun update(e: AnActionEvent) { + e.presentation.isEnabled = e.project != null + } + + override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT + + override fun actionPerformed(e: AnActionEvent) { + val project = e.project ?: return + val toolWindow = ToolWindowManager.getInstance(project).getToolWindow("ProxyAI") ?: return + toolWindow.show { + val contentManager = toolWindow.contentManager + val agentContent = contentManager.contents.firstOrNull { it.tabName == "Agent" } + ?: contentManager.getContent(0) + ?: return@show + contentManager.setSelectedContent(agentContent) + (agentContent.component as? AgentToolWindowPanel)?.focusActiveInput() + } + } +} diff --git a/src/main/kotlin/ee/carlrobert/codegpt/actions/FocusChatInputAction.kt b/src/main/kotlin/ee/carlrobert/codegpt/actions/FocusChatInputAction.kt new file mode 100644 index 000000000..1d70b6b7a --- /dev/null +++ b/src/main/kotlin/ee/carlrobert/codegpt/actions/FocusChatInputAction.kt @@ -0,0 +1,28 @@ +package ee.carlrobert.codegpt.actions + +import com.intellij.openapi.actionSystem.ActionUpdateThread +import com.intellij.openapi.actionSystem.AnAction +import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.wm.ToolWindowManager +import ee.carlrobert.codegpt.toolwindow.chat.ChatToolWindowPanel + +class FocusChatInputAction : AnAction() { + + override fun update(e: AnActionEvent) { + e.presentation.isEnabled = e.project != null + } + + override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT + + override fun actionPerformed(e: AnActionEvent) { + val project = e.project ?: return + val toolWindow = ToolWindowManager.getInstance(project).getToolWindow("ProxyAI") ?: return + toolWindow.show { + val contentManager = toolWindow.contentManager + val chatContent = contentManager.contents.firstOrNull { it.tabName == "Chat" } + ?: return@show + contentManager.setSelectedContent(chatContent) + (chatContent.component as? ChatToolWindowPanel)?.requestFocusForInput() + } + } +} diff --git a/src/main/kotlin/ee/carlrobert/codegpt/toolwindow/agent/AgentToolWindowPanel.kt b/src/main/kotlin/ee/carlrobert/codegpt/toolwindow/agent/AgentToolWindowPanel.kt index 84f5c483f..ee1952a2e 100644 --- a/src/main/kotlin/ee/carlrobert/codegpt/toolwindow/agent/AgentToolWindowPanel.kt +++ b/src/main/kotlin/ee/carlrobert/codegpt/toolwindow/agent/AgentToolWindowPanel.kt @@ -85,6 +85,14 @@ class AgentToolWindowPanel( fun getTabbedPane(): AgentToolWindowTabbedPane = tabbedPane + fun focusActiveInput() { + landingPanel?.let { + it.requestFocusForTextArea() + return + } + contentManager.getActiveTabPanel()?.requestFocusForTextArea() + } + private fun showTabsView() { disposeLandingPanel() centerLayout.show(centerPanel, TABS_CARD) diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 1259f874c..47d85824b 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -319,6 +319,17 @@ + + +