summaryrefslogtreecommitdiff
path: root/platform/lang-impl/src/com/intellij/codeInsight/codeVision/ui/popup/CodeVisionContextPopup.kt
blob: bb8bc89122f538a32d1cd2f708e84600255e0530 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.intellij.codeInsight.codeVision.ui.popup

import com.intellij.codeInsight.codeVision.CodeVisionEntry
import com.intellij.codeInsight.codeVision.CodeVisionEntryExtraActionModel
import com.intellij.codeInsight.codeVision.ui.model.CodeVisionListData
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.popup.ListPopupStep
import com.intellij.openapi.ui.popup.ListSeparator
import com.intellij.ui.popup.list.ListPopupImpl


class CodeVisionContextPopup private constructor(project: Project, aStep: ListPopupStep<CodeVisionEntryExtraActionModel>) : ListPopupImpl(
  project,
  aStep) {
  companion object {

    fun createLensList(entry: CodeVisionEntry, model: CodeVisionListData, project: Project): CodeVisionContextPopup {
      val lst = entry.extraActions + model.projectModel.hideLens

      val aStep = object : SubCodeVisionMenu(lst,
                                             {
                                               model.rangeCodeVisionModel.handleLensExtraAction(entry, it)
                                             }) {


        override fun getSeparatorAbove(value: CodeVisionEntryExtraActionModel): ListSeparator? {
          return super.getSeparatorAbove(value) ?: if (value == model.projectModel.hideLens) ListSeparator() else null
        }
      }

      return CodeVisionContextPopup(project, aStep)
    }
  }

  init {
    setMaxRowCount(15)
  }

  override fun beforeShow(): Boolean {
    setHandleAutoSelectionBeforeShow(false)
    list.clearSelection()
    return super.beforeShow()
  }

  override fun afterShow() {
  }
}