1
0
mirror of https://github.com/chylex/IntelliJ-Keyboard-Master.git synced 2025-04-21 23:15:43 +02:00

Remove actions to select previous/next item because those already exist in IDEA

This commit is contained in:
chylex 2023-10-05 13:38:53 +02:00
parent b733bb167e
commit e47101946e
Signed by: chylex
GPG Key ID: 4DE42C8F19A80548
4 changed files with 0 additions and 119 deletions
src/main
kotlin/com/chylex/intellij/keyboardmaster/feature/actions
resources/META-INF

View File

@ -1,17 +0,0 @@
package com.chylex.intellij.keyboardmaster.feature.actions
import javax.swing.JList
import javax.swing.JTree
class NextMenuItemAction : SelectMenuItemBaseAction() {
override fun updateSelection(list: JList<*>) {
setSelectedIndex(list, list.selectedIndex + 1)
}
override fun updateSelection(tree: JTree) {
val row = tree.selectionRows?.maxOrNull()
if (row != null) {
setSelectedIndex(tree, row + 1)
}
}
}

View File

@ -1,23 +0,0 @@
package com.chylex.intellij.keyboardmaster.feature.actions
import javax.swing.JList
import javax.swing.JTree
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)
}
}
override fun updateSelection(tree: JTree) {
val row = tree.selectionRows?.minOrNull()
if (row != null) {
setSelectedIndex(tree, row - 1)
}
}
}

View File

@ -1,74 +0,0 @@
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
import javax.swing.JTree
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 JTree) {
updateSelection(focused)
break
}
else if (focused is BigPopupUI) {
val list = ComponentUtil.findComponentsOfType(focused, JList::class.java).singleOrNull()
if (list != null) {
updateSelection(list)
break
}
val tree = ComponentUtil.findComponentsOfType(focused, JTree::class.java).singleOrNull()
if (tree != null) {
updateSelection(tree)
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)
}
}
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)
}
}
}

View File

@ -22,9 +22,4 @@
<applicationConfigurable parentId="tools" instance="com.chylex.intellij.keyboardmaster.configuration.PluginConfigurable" id="com.chylex.keyboardmaster" />
<postStartupActivity implementation="com.chylex.intellij.keyboardmaster.PluginStartup" order="last" />
</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>