<commit_before>package com.maddyhome.idea.vim

import com.intellij.ide.BrowserUtil
import com.intellij.ide.DataManager
import com.intellij.ide.plugins.InstalledPluginsState
import com.intellij.ide.plugins.PluginManager
import com.intellij.ide.plugins.RepositoryHelper
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.DefaultActionGroup
import com.intellij.openapi.application.ApplicationInfo
import com.intellij.openapi.application.ex.ApplicationManagerEx
import com.intellij.openapi.options.ShowSettingsUtil
import com.intellij.openapi.progress.PerformInBackgroundOption
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.Task
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.Messages
import com.intellij.openapi.ui.popup.JBPopupFactory
import com.intellij.openapi.ui.popup.JBPopupListener
import com.intellij.openapi.ui.popup.LightweightWindowEvent
import com.intellij.openapi.updateSettings.impl.PluginDownloader
import com.intellij.openapi.updateSettings.impl.UpdateChecker
import com.intellij.openapi.updateSettings.impl.UpdateInstaller
import com.intellij.openapi.updateSettings.impl.UpdateSettings
import com.intellij.openapi.util.Ref
import com.intellij.openapi.wm.StatusBar
import com.intellij.openapi.wm.StatusBarWidget
import com.intellij.openapi.wm.StatusBarWidgetProvider
import com.intellij.util.Consumer
import com.intellij.util.text.VersionComparatorUtil
import com.maddyhome.idea.vim.action.VimPluginToggleAction
import com.maddyhome.idea.vim.group.NotificationService
import com.maddyhome.idea.vim.ui.VimEmulationConfigurable
import icons.VimIcons
import java.awt.Component
import java.awt.Point
import java.awt.event.MouseEvent
import javax.swing.Icon
import javax.swing.SwingConstants


private class StatusBarIconProvider : StatusBarWidgetProvider {
  override fun getWidget(project: Project) = StatusBarIcon
}

private object StatusBarIcon : StatusBarWidget, StatusBarWidget.IconPresentation {

  private var statusBar: StatusBar? = null

  override fun ID(): String = "IdeaVim-Icon"

  override fun install(statusBar: StatusBar) {
    this.statusBar = statusBar
  }

  override fun dispose() {}

  override fun getTooltipText() = "IdeaVim"

  override fun getIcon(): Icon = if (VimPlugin.isEnabled()) VimIcons.IDEAVIM else VimIcons.IDEAVIM_DISABLED

  override fun getClickConsumer() = Consumer<MouseEvent> { event ->
    val component = event.component
    val actions = getActions(component)
    val popup = JBPopupFactory.getInstance()
      .createActionGroupPopup("IdeaVim", actions,
        DataManager.getInstance().getDataContext(component), false, null,
        actions.childrenCount)
    popup.addListener(object : JBPopupListener {
      override fun beforeShown(event: LightweightWindowEvent) {
        val location = component.locationOnScreen
        val size = popup.size
        popup.setLocation(Point(location.x + component.width - size.width, location.y - size.height))
      }
    })

    popup.setAdText("Version ${VimPlugin.getVersion()}", SwingConstants.CENTER)

    popup.show(component)
  }

  // TODO [VERSION UPDATE] After 193 use `getPresentation()`
  override fun getPresentation(type: StatusBarWidget.PlatformType): StatusBarWidget.WidgetPresentation? = this

  private fun getActions(component: Component): DefaultActionGroup {
    val actionGroup = DefaultActionGroup()

    actionGroup.add(VimStatusBarToggle)
    actionGroup.addSeparator()
    actionGroup.add(NotificationService.OpenIdeaVimRcAction(null))
    actionGroup.add(ShortcutConflictsSettings)
    actionGroup.addSeparator("EAP" + if (JoinEap.eapActive()) " (Active)" else "")
    actionGroup.add(JoinEap)
    actionGroup.add(HelpLink("About EAP...", "https://github.com/JetBrains/ideavim#get-early-access", null))
    actionGroup.addSeparator()
    actionGroup.add(Help(component))

    return actionGroup
  }

  fun update() {
    statusBar?.updateWidget(this.ID())
  }
}

private class Help(val component: Component) : AnAction("Contacts && Help") {
  override fun actionPerformed(e: AnActionEvent) {

    val helpGroup = DefaultActionGroup()

    helpGroup.add(HelpLink("Contact on Twitter", "https://twitter.com/ideavim", VimIcons.TWITTER))
    helpGroup.add(HelpLink("Create an Issue", "https://youtrack.jetbrains.com/issues/VIM", VimIcons.YOUTRACK))
    helpGroup.add(HelpLink("Contribute on GitHub", "https://github.com/JetBrains/ideavim", VimIcons.GITHUB))

    val popup = JBPopupFactory.getInstance()
      .createActionGroupPopup("Contacts & Help", helpGroup,
        DataManager.getInstance().getDataContext(component), false, null,
        helpGroup.childrenCount)
    popup.addListener(object : JBPopupListener {
      override fun beforeShown(event: LightweightWindowEvent) {
        val location = component.locationOnScreen
        val size = popup.size
        popup.setLocation(Point(location.x + component.width - size.width, location.y - size.height))
      }
    })

    popup.show(component)
  }

}

class HelpLink(
  name: String,
  val link: String,
  icon: Icon?
) : AnAction(name, null, icon) {
  override fun actionPerformed(e: AnActionEvent) {
    BrowserUtil.browse(link)
  }
}

private object VimStatusBarToggle : VimPluginToggleAction() {
  override fun update(e: AnActionEvent) {
    super.update(e)
    e.presentation.text = if (VimPlugin.isEnabled()) "Enabled" else "Enable"
  }
}

private object ShortcutConflictsSettings : AnAction("Settings...") {
  override fun actionPerformed(e: AnActionEvent) {
    ShowSettingsUtil.getInstance().editConfigurable(e.project, VimEmulationConfigurable())
  }
}<commit_msg>Hide some icon actions to sublist<commit_after>package com.maddyhome.idea.vim

import com.intellij.ide.BrowserUtil
import com.intellij.ide.DataManager
import com.intellij.ide.plugins.InstalledPluginsState
import com.intellij.ide.plugins.PluginManager
import com.intellij.ide.plugins.RepositoryHelper
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.DefaultActionGroup
import com.intellij.openapi.application.ApplicationInfo
import com.intellij.openapi.application.ex.ApplicationManagerEx
import com.intellij.openapi.options.ShowSettingsUtil
import com.intellij.openapi.progress.PerformInBackgroundOption
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.Task
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.Messages
import com.intellij.openapi.ui.popup.JBPopupFactory
import com.intellij.openapi.ui.popup.JBPopupListener
import com.intellij.openapi.ui.popup.LightweightWindowEvent
import com.intellij.openapi.updateSettings.impl.PluginDownloader
import com.intellij.openapi.updateSettings.impl.UpdateChecker
import com.intellij.openapi.updateSettings.impl.UpdateInstaller
import com.intellij.openapi.updateSettings.impl.UpdateSettings
import com.intellij.openapi.util.Ref
import com.intellij.openapi.wm.StatusBar
import com.intellij.openapi.wm.StatusBarWidget
import com.intellij.openapi.wm.StatusBarWidgetProvider
import com.intellij.util.Consumer
import com.intellij.util.text.VersionComparatorUtil
import com.maddyhome.idea.vim.action.VimPluginToggleAction
import com.maddyhome.idea.vim.group.NotificationService
import com.maddyhome.idea.vim.ui.VimEmulationConfigurable
import icons.VimIcons
import java.awt.Component
import java.awt.Point
import java.awt.event.MouseEvent
import javax.swing.Icon
import javax.swing.SwingConstants


private class StatusBarIconProvider : StatusBarWidgetProvider {
  override fun getWidget(project: Project) = StatusBarIcon
}

private object StatusBarIcon : StatusBarWidget, StatusBarWidget.IconPresentation {

  private var statusBar: StatusBar? = null

  override fun ID(): String = "IdeaVim-Icon"

  override fun install(statusBar: StatusBar) {
    this.statusBar = statusBar
  }

  override fun dispose() {}

  override fun getTooltipText() = "IdeaVim"

  override fun getIcon(): Icon = if (VimPlugin.isEnabled()) VimIcons.IDEAVIM else VimIcons.IDEAVIM_DISABLED

  override fun getClickConsumer() = Consumer<MouseEvent> { event ->
    val component = event.component
    val actions = getActions(component)
    val popup = JBPopupFactory.getInstance()
      .createActionGroupPopup("IdeaVim", actions,
        DataManager.getInstance().getDataContext(component), false, null,
        actions.childrenCount)
    popup.addListener(object : JBPopupListener {
      override fun beforeShown(event: LightweightWindowEvent) {
        val location = component.locationOnScreen
        val size = popup.size
        popup.setLocation(Point(location.x + component.width - size.width, location.y - size.height))
      }
    })

    popup.setAdText("Version ${VimPlugin.getVersion()}", SwingConstants.CENTER)

    popup.show(component)
  }

  // TODO [VERSION UPDATE] After 193 use `getPresentation()`
  override fun getPresentation(type: StatusBarWidget.PlatformType): StatusBarWidget.WidgetPresentation? = this

  private fun getActions(component: Component): DefaultActionGroup {
    val actionGroup = DefaultActionGroup()

    actionGroup.add(VimStatusBarToggle)
    actionGroup.addSeparator()
    actionGroup.add(NotificationService.OpenIdeaVimRcAction(null))
    actionGroup.add(ShortcutConflictsSettings)
    actionGroup.addSeparator()

    val eapGroup = DefaultActionGroup("EAP" + if (JoinEap.eapActive()) " (Active)" else "", true)
    eapGroup.add(JoinEap)
    eapGroup.add(HelpLink("About EAP...", "https://github.com/JetBrains/ideavim#get-early-access", null))
    actionGroup.add(eapGroup)

    val helpGroup = DefaultActionGroup("Contacts && Help", true)
    helpGroup.add(HelpLink("Contact on Twitter", "https://twitter.com/ideavim", VimIcons.TWITTER))
    helpGroup.add(HelpLink("Create an Issue", "https://youtrack.jetbrains.com/issues/VIM", VimIcons.YOUTRACK))
    helpGroup.add(HelpLink("Contribute on GitHub", "https://github.com/JetBrains/ideavim", VimIcons.GITHUB))
    actionGroup.add(helpGroup)

    return actionGroup
  }

  fun update() {
    statusBar?.updateWidget(this.ID())
  }
}

class HelpLink(
  name: String,
  val link: String,
  icon: Icon?
) : AnAction(name, null, icon) {
  override fun actionPerformed(e: AnActionEvent) {
    BrowserUtil.browse(link)
  }
}

private object VimStatusBarToggle : VimPluginToggleAction() {
  override fun update(e: AnActionEvent) {
    super.update(e)
    e.presentation.text = if (VimPlugin.isEnabled()) "Enabled" else "Enable"
  }
}

private object ShortcutConflictsSettings : AnAction("Settings...") {
  override fun actionPerformed(e: AnActionEvent) {
    ShowSettingsUtil.getInstance().editConfigurable(e.project, VimEmulationConfigurable())
  }
}
{'fraction_non_alphanumeric': 0.10217631870158612, 'fraction_numerical': 0.0005533013648100332, 'mean_word_length': 5.065436241610739, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3002749', 'n_tokens_mistral': 3377, 'n_tokens_neox': 3285, 'n_words': 584}