[pycharm] PY-79113 Debugger: add action group draft

(cherry picked from commit 80a15019201c2d502b9e1ff11c24c35f55b79516)

GitOrigin-RevId: b91de0bb53ddf7f828244c644c37e91d93060908
This commit is contained in:
ekaterina.itsenko
2025-02-24 23:36:40 +01:00
committed by intellij-monorepo-bot
parent 28eef02586
commit 3c9ddf8cdd
3 changed files with 86 additions and 1 deletions

View File

@@ -157,6 +157,8 @@
id="Images.CopyImageAction"
icon="AllIcons.Actions.Copy">
</action>
<group id="Images.ImageOperationsGroup"
class="org.intellij.images.scientific.action.ImageOperationsActionGroup"/>
</group>
<group id="Images.EditorToolbar">
<reference ref="Images.ToggleTransparencyChessboard"/>

View File

@@ -88,4 +88,8 @@ image.description={0}\u00D7{1}, {2}bpp
# scientific mode
dialog.title.save.image=Select File to Save Image
action.Images.SaveImageAction.text=Save Image
action.Images.CopyImageAction.text=Copy Image
action.Images.CopyImageAction.text=Copy Image
group.Images.ImageOperationsGroup.text=Hi there
image.color.mode.rgb=RGB
image.color.mode.bgr=BGR
image.color.mode.grayscale=Grayscale

View File

@@ -0,0 +1,79 @@
package org.intellij.images.scientific.action
import com.intellij.openapi.actionSystem.*
import com.intellij.openapi.actionSystem.ex.CustomComponentAction
import com.intellij.openapi.project.DumbAware
import com.intellij.openapi.project.DumbAwareAction
import com.intellij.openapi.ui.ComboBox
import com.intellij.openapi.ui.popup.JBPopupFactory
import org.intellij.images.ImagesBundle
import org.intellij.images.scientific.ScientificUtils
import java.awt.BorderLayout
import javax.swing.DefaultComboBoxModel
import javax.swing.JComponent
import javax.swing.JPanel
class ImageOperationsActionGroup : DefaultActionGroup(), CustomComponentAction, DumbAware {
private var selectedMode: String = RGB
private val availableModes = listOf(RGB, BGR, GRAYSCALE)
init {
templatePresentation.apply {
isPerformGroup = true
isPopup = true
}
}
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
override fun actionPerformed(e: AnActionEvent) {
val component = e.inputEvent?.source as? JComponent ?: return
JBPopupFactory.getInstance().createActionGroupPopup(
null,
createPopupActionGroup(),
e.dataContext,
null,
true,
null
).showUnderneathOf(component)
}
override fun update(e: AnActionEvent) {
val imageFile = e.getData(CommonDataKeys.VIRTUAL_FILE)
e.presentation.isEnabledAndVisible = imageFile?.getUserData(ScientificUtils.SCIENTIFIC_MODE_KEY) != null
}
override fun createCustomComponent(presentation: Presentation, place: String): JComponent {
val comboBox = ComboBox(DefaultComboBoxModel(availableModes.toTypedArray())).apply {
selectedItem = selectedMode
isOpaque = false
addActionListener {
selectedMode = selectedItem as String
}
}
return JPanel(BorderLayout()).apply {
isOpaque = false
border = null
add(comboBox, BorderLayout.CENTER)
}
}
private fun createPopupActionGroup(): DefaultActionGroup {
val actionGroup = DefaultActionGroup()
availableModes.forEach { mode ->
actionGroup.add(
DumbAwareAction.create(mode) {
selectedMode = mode
}
)
}
return actionGroup
}
companion object {
private val RGB: String = ImagesBundle.message("image.color.mode.rgb")
private val BGR: String = ImagesBundle.message("image.color.mode.bgr")
private val GRAYSCALE: String = ImagesBundle.message("image.color.mode.grayscale")
}
}