Skip to content

Commit

Permalink
feat(ext-terminal): refactor suggestCommand method to support new UI …
Browse files Browse the repository at this point in the history
…context and add TerminalUtil class for message sending #135

This commit refactors the suggestCommand method in ShellCommandSuggestAction to support a new UI context. It also introduces the TerminalUtil class for sending messages, improving the extensibility and usability of the terminal extension.
  • Loading branch information
phodal committed Apr 4, 2024
1 parent 633e393 commit 60d15ee
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
@@ -1,6 +1,7 @@
package cc.unitmesh.terminal

import cc.unitmesh.terminal.ShellCommandSuggestAction.Companion.suggestCommand
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.ToolWindowManager
import com.intellij.terminal.JBTerminalWidget
Expand Down
@@ -1,6 +1,7 @@
package cc.unitmesh.terminal

import cc.unitmesh.terminal.ShellCommandSuggestAction.Companion.suggestCommand
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.ToolWindowManager
import com.intellij.terminal.JBTerminalWidget
Expand Down
Expand Up @@ -8,10 +8,10 @@ import cc.unitmesh.devti.statusbar.AutoDevStatusService
import cc.unitmesh.devti.template.GENIUS_PRACTISES
import cc.unitmesh.devti.template.TemplateRender
import cc.unitmesh.devti.util.LLMCoroutineScope
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.AnActionHolder
import com.intellij.openapi.actionSystem.PlatformCoreDataKeys
import com.intellij.openapi.project.DumbAwareAction
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.guessProjectDir
import com.intellij.openapi.ui.popup.Balloon
Expand All @@ -25,7 +25,7 @@ import com.intellij.ui.components.JBLabel
import com.intellij.util.ui.JBUI
import com.intellij.util.ui.SwingHelper
import com.intellij.util.ui.UIUtil
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.launch
import org.jetbrains.plugins.terminal.TerminalProjectOptionsProvider
import java.awt.Component
Expand All @@ -40,14 +40,13 @@ private const val OUTLINE_PROPERTY = "JComponent.outline"
private const val ERROR_VALUE = "error"


class ShellCommandSuggestAction : AnAction() {
class ShellCommandSuggestAction : DumbAwareAction() {
override fun actionPerformed(e: AnActionEvent) {
val project = e.project ?: return
val contextComponent = e.getData(PlatformCoreDataKeys.CONTEXT_COMPONENT) ?: return

showContentRenamePopup(contextComponent, getPreferredPopupPoint(e)) { string ->
showInputBoxPopup(contextComponent, getPreferredPopupPoint(e)) { string ->
TerminalUtil.sendMsg(project, string, e)
return@showContentRenamePopup
}
}

Expand All @@ -63,7 +62,7 @@ class ShellCommandSuggestAction : AnAction() {
return null
}

private fun showContentRenamePopup(
private fun showInputBoxPopup(
component: Component, popupPoint: RelativePoint?,
callback: (String) -> Unit
) {
Expand Down

0 comments on commit 60d15ee

Please sign in to comment.