mirror of
https://github.com/chylex/IntelliJ-Keyboard-Master.git
synced 2025-05-19 08:34:09 +02:00
Add configurable keyboard shortcuts to select next/previous item in focused menu
This commit is contained in:
parent
6072e2ea03
commit
bd194f05d5
src/main
kotlin/com/chylex/intellij/keyboardmaster/feature/actions
resources/META-INF
@ -0,0 +1,9 @@
|
|||||||
|
package com.chylex.intellij.keyboardmaster.feature.actions
|
||||||
|
|
||||||
|
import javax.swing.JList
|
||||||
|
|
||||||
|
class NextMenuItemAction : SelectMenuItemBaseAction() {
|
||||||
|
override fun updateSelection(list: JList<*>) {
|
||||||
|
setSelectedIndex(list, list.selectedIndex + 1)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.chylex.intellij.keyboardmaster.feature.actions
|
||||||
|
|
||||||
|
import javax.swing.JList
|
||||||
|
|
||||||
|
class PrevMenuItemAction : SelectMenuItemBaseAction() {
|
||||||
|
override fun updateSelection(list: JList<*>) {
|
||||||
|
val index = list.selectedIndex
|
||||||
|
if (index == -1) {
|
||||||
|
setSelectedIndex(list, list.model.size - 1)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setSelectedIndex(list, index - 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
package com.chylex.intellij.keyboardmaster.feature.actions
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.lookup.LookupManager
|
||||||
|
import com.intellij.codeInsight.lookup.impl.LookupImpl
|
||||||
|
import com.intellij.ide.actions.BigPopupUI
|
||||||
|
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||||
|
import com.intellij.openapi.actionSystem.CommonDataKeys
|
||||||
|
import com.intellij.openapi.project.DumbAwareAction
|
||||||
|
import com.intellij.ui.ComponentUtil
|
||||||
|
import java.awt.KeyboardFocusManager
|
||||||
|
import javax.swing.JList
|
||||||
|
|
||||||
|
abstract class SelectMenuItemBaseAction internal constructor(): DumbAwareAction() {
|
||||||
|
init {
|
||||||
|
isEnabledInModalContext = true
|
||||||
|
}
|
||||||
|
|
||||||
|
final override fun actionPerformed(e: AnActionEvent) {
|
||||||
|
val editor = e.getData(CommonDataKeys.EDITOR)
|
||||||
|
if (editor != null) {
|
||||||
|
val lookup = LookupManager.getActiveLookup(editor)
|
||||||
|
if (lookup is LookupImpl) {
|
||||||
|
updateSelection(lookup.list)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var focused = KeyboardFocusManager.getCurrentKeyboardFocusManager().focusOwner
|
||||||
|
while (focused != null) {
|
||||||
|
if (focused is JList<*>) {
|
||||||
|
updateSelection(focused)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
else if (focused is BigPopupUI) {
|
||||||
|
val list = ComponentUtil.findComponentsOfType(focused, JList::class.java).singleOrNull()
|
||||||
|
if (list != null) {
|
||||||
|
updateSelection(list)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
focused = focused.parent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract fun updateSelection(list: JList<*>)
|
||||||
|
|
||||||
|
protected fun setSelectedIndex(list: JList<*>, newIndex: Int) {
|
||||||
|
if (newIndex in 0 until list.model.size) {
|
||||||
|
list.selectedIndex = newIndex
|
||||||
|
list.ensureIndexIsVisible(newIndex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,6 +8,7 @@
|
|||||||
Collection of keyboard-centric additions.
|
Collection of keyboard-centric additions.
|
||||||
<ul>
|
<ul>
|
||||||
<li>Code completion items can be jumped to using customizable characters (numbers by default).</li>
|
<li>Code completion items can be jumped to using customizable characters (numbers by default).</li>
|
||||||
|
<li>Keyboard shortcuts to select next/previous item in focused menu.</li>
|
||||||
</ul>
|
</ul>
|
||||||
]]></description>
|
]]></description>
|
||||||
|
|
||||||
@ -22,4 +23,9 @@
|
|||||||
<applicationConfigurable parentId="tools" instance="com.chylex.intellij.keyboardmaster.configuration.PluginConfigurable" id="com.chylex.keyboardmaster" />
|
<applicationConfigurable parentId="tools" instance="com.chylex.intellij.keyboardmaster.configuration.PluginConfigurable" id="com.chylex.keyboardmaster" />
|
||||||
<postStartupActivity implementation="com.chylex.intellij.keyboardmaster.PluginStartup" order="last" />
|
<postStartupActivity implementation="com.chylex.intellij.keyboardmaster.PluginStartup" order="last" />
|
||||||
</extensions>
|
</extensions>
|
||||||
|
|
||||||
|
<actions>
|
||||||
|
<action id="com.chylex.intellij.keyboardmaster.feature.actions.NextMenuItemAction" class="com.chylex.intellij.keyboardmaster.feature.actions.NextMenuItemAction" text="Next Menu Item" />
|
||||||
|
<action id="com.chylex.intellij.keyboardmaster.feature.actions.PrevMenuItemAction" class="com.chylex.intellij.keyboardmaster.feature.actions.PrevMenuItemAction" text="Previous Menu Item" />
|
||||||
|
</actions>
|
||||||
</idea-plugin>
|
</idea-plugin>
|
||||||
|
Loading…
Reference in New Issue
Block a user