mirror of
https://github.com/chylex/IntelliJ-Keyboard-Master.git
synced 2025-05-25 08:34:06 +02:00
Make shortcuts for next/previous menu item work with tree menus
This commit is contained in:
parent
e409821bea
commit
8f3ef71e80
src/main/kotlin/com/chylex/intellij/keyboardmaster/feature/actions
@ -1,9 +1,17 @@
|
|||||||
package com.chylex.intellij.keyboardmaster.feature.actions
|
package com.chylex.intellij.keyboardmaster.feature.actions
|
||||||
|
|
||||||
import javax.swing.JList
|
import javax.swing.JList
|
||||||
|
import javax.swing.JTree
|
||||||
|
|
||||||
class NextMenuItemAction : SelectMenuItemBaseAction() {
|
class NextMenuItemAction : SelectMenuItemBaseAction() {
|
||||||
override fun updateSelection(list: JList<*>) {
|
override fun updateSelection(list: JList<*>) {
|
||||||
setSelectedIndex(list, list.selectedIndex + 1)
|
setSelectedIndex(list, list.selectedIndex + 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun updateSelection(tree: JTree) {
|
||||||
|
val row = tree.selectionRows?.maxOrNull()
|
||||||
|
if (row != null) {
|
||||||
|
setSelectedIndex(tree, row + 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.chylex.intellij.keyboardmaster.feature.actions
|
package com.chylex.intellij.keyboardmaster.feature.actions
|
||||||
|
|
||||||
import javax.swing.JList
|
import javax.swing.JList
|
||||||
|
import javax.swing.JTree
|
||||||
|
|
||||||
class PrevMenuItemAction : SelectMenuItemBaseAction() {
|
class PrevMenuItemAction : SelectMenuItemBaseAction() {
|
||||||
override fun updateSelection(list: JList<*>) {
|
override fun updateSelection(list: JList<*>) {
|
||||||
@ -12,4 +13,11 @@ class PrevMenuItemAction : SelectMenuItemBaseAction() {
|
|||||||
setSelectedIndex(list, index - 1)
|
setSelectedIndex(list, index - 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun updateSelection(tree: JTree) {
|
||||||
|
val row = tree.selectionRows?.minOrNull()
|
||||||
|
if (row != null) {
|
||||||
|
setSelectedIndex(tree, row - 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import com.intellij.openapi.project.DumbAwareAction
|
|||||||
import com.intellij.ui.ComponentUtil
|
import com.intellij.ui.ComponentUtil
|
||||||
import java.awt.KeyboardFocusManager
|
import java.awt.KeyboardFocusManager
|
||||||
import javax.swing.JList
|
import javax.swing.JList
|
||||||
|
import javax.swing.JTree
|
||||||
|
|
||||||
abstract class SelectMenuItemBaseAction internal constructor(): DumbAwareAction() {
|
abstract class SelectMenuItemBaseAction internal constructor(): DumbAwareAction() {
|
||||||
init {
|
init {
|
||||||
@ -31,12 +32,22 @@ abstract class SelectMenuItemBaseAction internal constructor(): DumbAwareAction(
|
|||||||
updateSelection(focused)
|
updateSelection(focused)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
else if (focused is JTree) {
|
||||||
|
updateSelection(focused)
|
||||||
|
break
|
||||||
|
}
|
||||||
else if (focused is BigPopupUI) {
|
else if (focused is BigPopupUI) {
|
||||||
val list = ComponentUtil.findComponentsOfType(focused, JList::class.java).singleOrNull()
|
val list = ComponentUtil.findComponentsOfType(focused, JList::class.java).singleOrNull()
|
||||||
if (list != null) {
|
if (list != null) {
|
||||||
updateSelection(list)
|
updateSelection(list)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val tree = ComponentUtil.findComponentsOfType(focused, JTree::class.java).singleOrNull()
|
||||||
|
if (tree != null) {
|
||||||
|
updateSelection(tree)
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
focused = focused.parent
|
focused = focused.parent
|
||||||
@ -51,4 +62,13 @@ abstract class SelectMenuItemBaseAction internal constructor(): DumbAwareAction(
|
|||||||
list.ensureIndexIsVisible(newIndex)
|
list.ensureIndexIsVisible(newIndex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract fun updateSelection(tree: JTree)
|
||||||
|
|
||||||
|
protected fun setSelectedIndex(list: JTree, newIndex: Int) {
|
||||||
|
if (newIndex in 0 until list.rowCount) {
|
||||||
|
list.setSelectionRow(newIndex)
|
||||||
|
list.scrollRowToVisible(newIndex)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user