<commit_before>package nl.hannahsten.texifyidea.startup

import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.DefaultActionGroup
import com.intellij.openapi.actionSystem.IdeActions
import com.intellij.openapi.application.ApplicationNamesInfo
import com.intellij.openapi.project.DumbAware
import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.StartupActivity

/**
 * Register a menu item programmatically instead of in plugin.xml, so we can customize when it is shown or not (xml is preferred, but we cannot switch on application name in xml).
 *
 * @author <NAME>
 */
class AnalyzeMenuRegistration : StartupActivity, DumbAware {

    override fun runActivity(project: Project) {
        // Get the group which should be added to either the Analyze menu or something else
        val latexAnalyzeMenuGroup = ActionManager.getInstance().getAction("texify.LatexMenuAnalyze") as DefaultActionGroup

        // The Analyze menu group is not present in PyCharm and probably also not in other IDEs, so we will only use it in IntelliJ.
        // In PyCharm (and others) we will use the Code group.
        val applicationName = ApplicationNamesInfo.getInstance().scriptName

        if (applicationName == "idea") {
            // Get an instance of the Analyze action group by ID
            val analyzeGroup: DefaultActionGroup = ActionManager.getInstance().getAction(IdeActions.GROUP_ANALYZE) as DefaultActionGroup

            // Add the group which contains the LaTeX actions to the Analyze menu
            analyzeGroup.add(latexAnalyzeMenuGroup)
        }
        else {
            // Get an instance of the Code action group by ID
            val analyzeGroup: DefaultActionGroup = ActionManager.getInstance().getAction("CodeMenu") as DefaultActionGroup

            analyzeGroup.add(latexAnalyzeMenuGroup)
        }
    }
}<commit_msg>Remove analyze menu group before adding, to avoid adding it twice. Fixes #1210<commit_after>package nl.hannahsten.texifyidea.startup

import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.DefaultActionGroup
import com.intellij.openapi.actionSystem.IdeActions
import com.intellij.openapi.application.ApplicationNamesInfo
import com.intellij.openapi.project.DumbAware
import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.StartupActivity

/**
 * Register a menu item programmatically instead of in plugin.xml, so we can customize when it is shown or not (xml is preferred, but we cannot switch on application name in xml).
 *
 * @author <NAME>
 */
class AnalyzeMenuRegistration : StartupActivity, DumbAware {

    override fun runActivity(project: Project) {
        // Get the group which should be added to either the Analyze menu or something else
        val latexAnalyzeMenuGroup = ActionManager.getInstance().getAction("texify.LatexMenuAnalyze") as DefaultActionGroup

        // The Analyze menu group is not present in PyCharm and probably also not in other IDEs, so we will only use it in IntelliJ.
        // In PyCharm (and others) we will use the Code group.
        val applicationName = ApplicationNamesInfo.getInstance().scriptName

        val analyzeGroup: DefaultActionGroup = if (applicationName == "idea") {
            // Get an instance of the Analyze action group by ID
            ActionManager.getInstance().getAction(IdeActions.GROUP_ANALYZE) as DefaultActionGroup
        }
        else {
            // Get an instance of the Code action group by ID
            ActionManager.getInstance().getAction("CodeMenu") as DefaultActionGroup
        }

        // Add the group which contains the LaTeX actions to the Analyze menu
        // First remove it, to avoid adding it twice
        analyzeGroup.remove(latexAnalyzeMenuGroup)
        analyzeGroup.add(latexAnalyzeMenuGroup)
    }
}
{'fraction_non_alphanumeric': 0.06644347154262169, 'fraction_numerical': 0.0010301313417460727, 'mean_word_length': 3.4953703703703702, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '3401937', 'n_tokens_mistral': 1037, 'n_tokens_neox': 1000, 'n_words': 347}