package cn.yiiguxing.plugin.translate.action

import cn.yiiguxing.plugin.translate.adaptedMessage
import cn.yiiguxing.plugin.translate.service.TranslationUIManager
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.DumbAwareAction
import com.intellij.terminal.JBTerminalWidget

class TerminalTranslationAction : DumbAwareAction(), ImportantTranslationAction {

    override fun update(e: AnActionEvent) {
        e.presentation.isEnabledAndVisible = !e.getSelectedTextFromTerminal().isNullOrBlank()
        templatePresentation.text = adaptedMessage("action.TerminalTranslationAction.text")
    }

    override fun actionPerformed(e: AnActionEvent) {
        val selectedText = e.getSelectedTextFromTerminal() ?: return
        TranslationUIManager.showDialog(e.project).translate(selectedText)
    }

    companion object {
        fun AnActionEvent.getSelectedTextFromTerminal(): String? = getData(JBTerminalWidget.SELECTED_TEXT_DATA_KEY)
    }
}
package cn.yiiguxing.plugin.translate.action

import cn.yiiguxing.plugin.translate.adaptedMessage
import cn.yiiguxing.plugin.translate.service.TranslationUIManager
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.DumbAwareAction
import com.intellij.terminal.JBTerminalWidget

class TerminalTranslationAction : DumbAwareAction({ adaptedMessage("action.TerminalTranslationAction.text") }),
    ImportantTranslationAction {

    override fun update(e: AnActionEvent) {
        e.presentation.isEnabledAndVisible = !e.getSelectedTextFromTerminal().isNullOrBlank()
    }

    override fun actionPerformed(e: AnActionEvent) {
        val selectedText = e.getSelectedTextFromTerminal() ?: return
        TranslationUIManager.showDialog(e.project).translate(selectedText)
    }

    companion object {
        fun AnActionEvent.getSelectedTextFromTerminal(): String? = getData(JBTerminalWidget.SELECTED_TEXT_DATA_KEY)
    }
}
Fix text of terminal translation action
Fix text of terminal translation action

YiiGuxing/TranslationPlugin,YiiGuxing/TranslationPlugin