<commit_before>package cn.yiiguxing.plugin.translate.action

import cn.yiiguxing.plugin.translate.message
import cn.yiiguxing.plugin.translate.util.*
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.actionSystem.EditorActionHandler
import com.intellij.openapi.editor.actions.TextComponentEditorAction

/**
 * 文本组件（如文本框、提示气泡、输入框……）翻译
 *
 * Created by Yii.Guxing on 2017/9/11
 */
class TranslateTextComponentAction : TextComponentEditorAction(Handler()) {

    init {
        isEnabledInModalContext = true
        @Suppress("InvalidBundleOrProperty")
        templatePresentation.description = message("action.description.textComponent")
    }

    private class Handler : EditorActionHandler() {

        private val settings = Settings

        public override fun doExecute(editor: Editor, caret: Caret?, dataContext: DataContext) {
            val text = when {
                editor.selectionModel.hasSelection() -> editor.selectionModel.selectedText
                !editor.isViewer -> editor.getSelectionFromCurrentCaret(settings.autoSelectionMode)?.let {
                    editor.document.getText(it)
                }
                else -> null
            }

            text?.processBeforeTranslate()?.let { TranslationUIManager.showDialog(editor.project).translate(it) }
        }

        public override fun isEnabledForCaret(editor: Editor, caret: Caret, dataContext: DataContext?) =
                when {
                    editor.selectionModel.hasSelection() -> !editor.selectionModel.selectedText.isNullOrBlank()
                    !editor.isViewer -> {
                        val textRange = editor.getSelectionFromCurrentCaret(settings.autoSelectionMode)
                        textRange?.let { editor.document.getText(it).isNotBlank() } ?: false
                    }
                    else -> false
                }
    }

}<commit_msg>Fix unable to perform translate text component action on balloon popup see #253<commit_after>package cn.yiiguxing.plugin.translate.action

import cn.yiiguxing.plugin.translate.message
import cn.yiiguxing.plugin.translate.util.*
import com.intellij.codeInsight.hint.HintManagerImpl
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.actionSystem.EditorActionHandler
import com.intellij.openapi.editor.actions.TextComponentEditorAction

/**
 * 文本组件（如文本框、提示气泡、输入框……）翻译
 *
 * Created by Yii.Guxing on 2017/9/11
 */
class TranslateTextComponentAction : TextComponentEditorAction(Handler()), HintManagerImpl.ActionToIgnore {

    init {
        isEnabledInModalContext = true
        @Suppress("InvalidBundleOrProperty")
        templatePresentation.description = message("action.description.textComponent")
    }

    private class Handler : EditorActionHandler() {

        private val settings = Settings

        public override fun doExecute(editor: Editor, caret: Caret?, dataContext: DataContext) {
            val text = when {
                editor.selectionModel.hasSelection() -> editor.selectionModel.selectedText
                !editor.isViewer -> editor.getSelectionFromCurrentCaret(settings.autoSelectionMode)?.let {
                    editor.document.getText(it)
                }
                else -> null
            }

            text?.processBeforeTranslate()?.let { TranslationUIManager.showDialog(editor.project).translate(it) }
        }

        public override fun isEnabledForCaret(editor: Editor, caret: Caret, dataContext: DataContext?) =
            when {
                editor.selectionModel.hasSelection() -> !editor.selectionModel.selectedText.isNullOrBlank()
                !editor.isViewer -> {
                    val textRange = editor.getSelectionFromCurrentCaret(settings.autoSelectionMode)
                    textRange?.let { editor.document.getText(it).isNotBlank() } ?: false
                }
                else -> false
            }
    }

}
{'fraction_non_alphanumeric': 0.09330085261875762, 'fraction_numerical': 0.0041412911084043845, 'mean_word_length': 2.6957695769576957, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3960619', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1097, 'n_words': 177}