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

import cn.yiiguxing.plugin.translate.adaptedMessage
import cn.yiiguxing.plugin.translate.documentation.TranslateDocumentationTask
import cn.yiiguxing.plugin.translate.util.IdeVersion
import cn.yiiguxing.plugin.translate.util.Settings
import cn.yiiguxing.plugin.translate.util.invokeLater
import com.intellij.codeInsight.documentation.DocumentationComponent
import com.intellij.codeInsight.documentation.DocumentationManager
import com.intellij.codeInsight.documentation.QuickDocUtil
import com.intellij.codeInsight.hint.HintManagerImpl
import com.intellij.lang.documentation.ide.DocumentationBrowserFacade
import com.intellij.lang.documentation.ide.actions.DOCUMENTATION_BROWSER
import com.intellij.openapi.actionSystem.ActionPlaces
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.application.ReadAction
import com.intellij.openapi.editor.EditorMouseHoverPopupManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.registry.Registry
import com.intellij.openapi.wm.ToolWindowId
import com.intellij.openapi.wm.ToolWindowManager
import com.intellij.util.concurrency.AppExecutorUtil
import icons.Icons
import javax.swing.Icon

open class ToggleQuickDocTranslationAction :
    FixedIconToggleAction(Icons.Documentation, { adaptedMessage("action.ToggleQuickDocTranslationAction.text") }),
    HintManagerImpl.ActionToIgnore {

    init {
        // enable in hovering documentation popup
        isEnabledInModalContext = true
    }

    @Suppress("UnstableApiUsage")
    private fun documentationBrowser(dc: DataContext): DocumentationBrowserFacade? = dc.getData(DOCUMENTATION_BROWSER)

    final override fun update(e: AnActionEvent) {
        super.update(e)
        val project = e.project
        if (project == null) {
            e.presentation.isEnabled = false
            return
        }

        if (Registry.`is`("documentation.v2")) {
            e.presentation.isEnabled = documentationBrowser(e.dataContext) != null
            return
        }

        update(project, e)
    }

    override fun getIcon(place: String, selected: Boolean): Icon? {
        return if (ActionPlaces.JAVADOC_TOOLBAR != place && selected) null else icon
    }

    private fun update(project: Project, e: AnActionEvent) {
        val activeDocComponent = QuickDocUtil.getActiveDocComponent(project)<commit_msg>disable ToggleQuickDocTranslationAction in Rider<commit_after>package cn.yiiguxing.plugin.translate.action

import cn.yiiguxing.plugin.translate.adaptedMessage
import cn.yiiguxing.plugin.translate.documentation.TranslateDocumentationTask
import cn.yiiguxing.plugin.translate.util.IdeVersion
import cn.yiiguxing.plugin.translate.util.Settings
import cn.yiiguxing.plugin.translate.util.invokeLater
import com.intellij.codeInsight.documentation.DocumentationComponent
import com.intellij.codeInsight.documentation.DocumentationManager
import com.intellij.codeInsight.documentation.QuickDocUtil
import com.intellij.codeInsight.hint.HintManagerImpl
import com.intellij.lang.documentation.ide.DocumentationBrowserFacade
import com.intellij.lang.documentation.ide.actions.DOCUMENTATION_BROWSER
import com.intellij.openapi.actionSystem.ActionPlaces
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.application.ReadAction
import com.intellij.openapi.editor.EditorMouseHoverPopupManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.registry.Registry
import com.intellij.openapi.wm.ToolWindowId
import com.intellij.openapi.wm.ToolWindowManager
import com.intellij.util.concurrency.AppExecutorUtil
import icons.Icons
import javax.swing.Icon

open class ToggleQuickDocTranslationAction :
    FixedIconToggleAction(Icons.Documentation, { adaptedMessage("action.ToggleQuickDocTranslationAction.text") }),
    HintManagerImpl.ActionToIgnore {

    init {
        // enable in hovering documentation popup
        isEnabledInModalContext = true
    }

    @Suppress("UnstableApiUsage")
    private fun documentationBrowser(dc: DataContext): DocumentationBrowserFacade? = dc.getData(DOCUMENTATION_BROWSER)

    final override fun update(e: AnActionEvent) {
        super.update(e)
        val project = e.project
        if (project == null) {
            e.presentation.isEnabled = false
            return
        }

        if (Registry.`is`("documentation.v2")) {
            e.presentation.isEnabledAndVisible =
                IdeVersion.buildNumber.productCode != "RD" && documentationBrowser(e.dataContext) != null
            return
        }

        update(project, e)
    }

    override fun getIcon(place: String, selected: Boolean): Icon? {
        return if (ActionPlaces.JAVADOC_TOOLBAR != place && selected) null else icon
    }

    private fun update(project: Project, e: AnActionEvent) {
        val activeDocComponent = QuickDocUtil.getActiveDocComponent(project)
{'fraction_non_alphanumeric': 0.08255974718546316, 'fraction_numerical': 0.00039502271380604387, 'mean_word_length': 4.504347826086956, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4049088', 'n_tokens_mistral': 1500, 'n_tokens_neox': 1433, 'n_words': 236}