mirror of
https://github.com/chylex/IntelliJ-Keyboard-Master.git
synced 2025-05-21 23:34:08 +02:00
Add configuration for which characters select which items (implementation needs cleanup)
This commit is contained in:
parent
619aa49b42
commit
28c3d80c6e
build.gradle.kts
src/main
kotlin/com/chylex/intellij/keyboardmaster
configuration
lookup
resources/META-INF
@ -5,7 +5,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "com.chylex.intellij.keyboardmaster"
|
group = "com.chylex.intellij.keyboardmaster"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
@ -0,0 +1,75 @@
|
|||||||
|
package com.chylex.intellij.keyboardmaster.configuration
|
||||||
|
|
||||||
|
import com.intellij.openapi.options.Configurable
|
||||||
|
import com.intellij.ui.components.JBTextField
|
||||||
|
import com.intellij.util.ui.FormBuilder
|
||||||
|
import javax.swing.JComponent
|
||||||
|
import javax.swing.JPanel
|
||||||
|
|
||||||
|
class PluginConfigurable : Configurable {
|
||||||
|
private lateinit var component: JComponent
|
||||||
|
|
||||||
|
private val charFields = Array(10) {
|
||||||
|
JBTextField(5)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getDisplayName(): String {
|
||||||
|
return "Keyboard Master"
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createComponent(): JComponent {
|
||||||
|
var builder = FormBuilder.createFormBuilder()
|
||||||
|
|
||||||
|
for (index in 1..9) {
|
||||||
|
builder = builder.addLabeledComponent("Code completion char $index: ", charFields[index])
|
||||||
|
}
|
||||||
|
|
||||||
|
builder = builder.addLabeledComponent("Code completion next page char: ", charFields[0])
|
||||||
|
builder = builder.addComponentFillVertically(JPanel(), 0)
|
||||||
|
component = builder.panel
|
||||||
|
|
||||||
|
return component
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isModified(): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun apply() {
|
||||||
|
fun getChar(index: Int): Int {
|
||||||
|
return charFields[index].text.firstOrNull()?.code ?: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
val instance = PluginConfiguration.instance
|
||||||
|
instance.charOption1 = getChar(1)
|
||||||
|
instance.charOption2 = getChar(2)
|
||||||
|
instance.charOption3 = getChar(3)
|
||||||
|
instance.charOption4 = getChar(4)
|
||||||
|
instance.charOption5 = getChar(5)
|
||||||
|
instance.charOption6 = getChar(6)
|
||||||
|
instance.charOption7 = getChar(7)
|
||||||
|
instance.charOption8 = getChar(8)
|
||||||
|
instance.charOption9 = getChar(9)
|
||||||
|
instance.charNextPage = getChar(0)
|
||||||
|
|
||||||
|
PluginConfiguration.update()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun reset() {
|
||||||
|
fun setChar(index: Int, char: Int) {
|
||||||
|
charFields[index].text = if (char == 0) "" else char.toChar().toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
val instance = PluginConfiguration.instance
|
||||||
|
setChar(1, instance.charOption1)
|
||||||
|
setChar(2, instance.charOption2)
|
||||||
|
setChar(3, instance.charOption3)
|
||||||
|
setChar(4, instance.charOption4)
|
||||||
|
setChar(5, instance.charOption5)
|
||||||
|
setChar(6, instance.charOption6)
|
||||||
|
setChar(7, instance.charOption7)
|
||||||
|
setChar(8, instance.charOption8)
|
||||||
|
setChar(9, instance.charOption9)
|
||||||
|
setChar(0, instance.charNextPage)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
package com.chylex.intellij.keyboardmaster.configuration
|
||||||
|
|
||||||
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
|
import com.intellij.openapi.components.PersistentStateComponent
|
||||||
|
import com.intellij.openapi.components.State
|
||||||
|
import com.intellij.openapi.components.Storage
|
||||||
|
import com.intellij.util.containers.IntIntHashMap
|
||||||
|
import com.intellij.util.xmlb.XmlSerializerUtil
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2IntMap
|
||||||
|
|
||||||
|
@State(
|
||||||
|
name = "com.chylex.intellij.keyboardmaster.configuration.PluginConfiguration",
|
||||||
|
storages = [Storage("KeyboardMaster.xml")]
|
||||||
|
)
|
||||||
|
class PluginConfiguration : PersistentStateComponent<PluginConfiguration> {
|
||||||
|
var charOption1: Int = '1'.code
|
||||||
|
var charOption2: Int = '2'.code
|
||||||
|
var charOption3: Int = '3'.code
|
||||||
|
var charOption4: Int = '4'.code
|
||||||
|
var charOption5: Int = '5'.code
|
||||||
|
var charOption6: Int = '6'.code
|
||||||
|
var charOption7: Int = '7'.code
|
||||||
|
var charOption8: Int = '8'.code
|
||||||
|
var charOption9: Int = '9'.code
|
||||||
|
var charNextPage: Int = '0'.code
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val instance: PluginConfiguration
|
||||||
|
get() = ApplicationManager.getApplication().getService(PluginConfiguration::class.java)
|
||||||
|
|
||||||
|
val charToIndexMap: Int2IntMap = IntIntHashMap(10, -1)
|
||||||
|
val hintText = Array(10) { "" }
|
||||||
|
|
||||||
|
init {
|
||||||
|
instance
|
||||||
|
update()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun update() {
|
||||||
|
val instance = instance
|
||||||
|
|
||||||
|
charToIndexMap.clear()
|
||||||
|
charToIndexMap[instance.charOption1] = 1
|
||||||
|
charToIndexMap[instance.charOption2] = 2
|
||||||
|
charToIndexMap[instance.charOption3] = 3
|
||||||
|
charToIndexMap[instance.charOption4] = 4
|
||||||
|
charToIndexMap[instance.charOption5] = 5
|
||||||
|
charToIndexMap[instance.charOption6] = 6
|
||||||
|
charToIndexMap[instance.charOption7] = 7
|
||||||
|
charToIndexMap[instance.charOption8] = 8
|
||||||
|
charToIndexMap[instance.charOption9] = 9
|
||||||
|
charToIndexMap[instance.charNextPage] = 0
|
||||||
|
|
||||||
|
for (entry in charToIndexMap.int2IntEntrySet()) {
|
||||||
|
val hintIndex = if (entry.intValue == 0) 9 else entry.intValue - 1
|
||||||
|
val charText = if (entry.intKey == 0) "" else " [${entry.intKey.toChar()}]"
|
||||||
|
hintText[hintIndex] = charText
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getState(): PluginConfiguration {
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun loadState(state: PluginConfiguration) {
|
||||||
|
XmlSerializerUtil.copyBean(state, this)
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package com.chylex.intellij.keyboardmaster.lookup
|
package com.chylex.intellij.keyboardmaster.lookup
|
||||||
|
|
||||||
|
import com.chylex.intellij.keyboardmaster.configuration.PluginConfiguration
|
||||||
import com.intellij.codeInsight.lookup.LookupManager
|
import com.intellij.codeInsight.lookup.LookupManager
|
||||||
import com.intellij.codeInsight.lookup.impl.LookupImpl
|
import com.intellij.codeInsight.lookup.impl.LookupImpl
|
||||||
import com.intellij.codeInsight.template.impl.editorActions.TypedActionHandlerBase
|
import com.intellij.codeInsight.template.impl.editorActions.TypedActionHandlerBase
|
||||||
@ -20,7 +21,8 @@ class LookupTypedActionHandler(originalHandler: TypedActionHandler?) : TypedActi
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun executeImpl(editor: Editor, charTyped: Char): Boolean {
|
private fun executeImpl(editor: Editor, charTyped: Char): Boolean {
|
||||||
if (charTyped !in '0'..'9') {
|
val mappedIndex = PluginConfiguration.charToIndexMap[charTyped.code]
|
||||||
|
if (mappedIndex == -1) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,7 +33,7 @@ class LookupTypedActionHandler(originalHandler: TypedActionHandler?) : TypedActi
|
|||||||
|
|
||||||
val offset = ProjectLookupListener.getLookupOffset(lookup)
|
val offset = ProjectLookupListener.getLookupOffset(lookup)
|
||||||
|
|
||||||
if (charTyped == '0') {
|
if (mappedIndex == 0) {
|
||||||
val list = lookup.list
|
val list = lookup.list
|
||||||
val itemCount = list.model.size
|
val itemCount = list.model.size
|
||||||
val topIndex = (offset + 9).let { if (it >= itemCount) 0 else it }
|
val topIndex = (offset + 9).let { if (it >= itemCount) 0 else it }
|
||||||
@ -43,7 +45,7 @@ class LookupTypedActionHandler(originalHandler: TypedActionHandler?) : TypedActi
|
|||||||
lookup.refreshUi(false, true)
|
lookup.refreshUi(false, true)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
lookup.selectedIndex = offset + (charTyped - '1')
|
lookup.selectedIndex = offset + mappedIndex - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.chylex.intellij.keyboardmaster.lookup
|
package com.chylex.intellij.keyboardmaster.lookup
|
||||||
|
|
||||||
|
import com.chylex.intellij.keyboardmaster.configuration.PluginConfiguration
|
||||||
import com.intellij.codeInsight.lookup.Lookup
|
import com.intellij.codeInsight.lookup.Lookup
|
||||||
import com.intellij.codeInsight.lookup.LookupElementPresentation
|
import com.intellij.codeInsight.lookup.LookupElementPresentation
|
||||||
import com.intellij.codeInsight.lookup.LookupManagerListener
|
import com.intellij.codeInsight.lookup.LookupManagerListener
|
||||||
@ -14,8 +15,6 @@ class ProjectLookupListener : LookupManagerListener {
|
|||||||
private val OFFSET_KEY = Key.create<Int>("chylexKeyboardMasterOffset")
|
private val OFFSET_KEY = Key.create<Int>("chylexKeyboardMasterOffset")
|
||||||
private val IS_MODIFIED_KEY = Key.create<Boolean>("chylexKeyboardMasterModified")
|
private val IS_MODIFIED_KEY = Key.create<Boolean>("chylexKeyboardMasterModified")
|
||||||
|
|
||||||
private val HINT_TEXT = Array(9) { " [${it + 1}]" }
|
|
||||||
|
|
||||||
fun getLookupOffset(lookup: LookupImpl): Int {
|
fun getLookupOffset(lookup: LookupImpl): Int {
|
||||||
val offset = lookup.getUserData(OFFSET_KEY)
|
val offset = lookup.getUserData(OFFSET_KEY)
|
||||||
if (offset == null || offset >= lookup.list.model.size) {
|
if (offset == null || offset >= lookup.list.model.size) {
|
||||||
@ -44,17 +43,20 @@ class ProjectLookupListener : LookupManagerListener {
|
|||||||
val itemCount = itemList.size
|
val itemCount = itemList.size
|
||||||
val offset = getLookupOffset(newLookup)
|
val offset = getLookupOffset(newLookup)
|
||||||
|
|
||||||
for (digitIndex in 0 until 9) {
|
for (index in 0 until 9) {
|
||||||
val itemIndex = offset + digitIndex
|
val itemIndex = offset + index
|
||||||
if (itemIndex >= itemCount) {
|
if (itemIndex >= itemCount) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item === itemList.getElementAt(itemIndex)) {
|
if (item === itemList.getElementAt(itemIndex)) {
|
||||||
val customized = LookupElementPresentation()
|
val hint = PluginConfiguration.hintText[index]
|
||||||
customized.copyFrom(presentation)
|
if (hint != "") {
|
||||||
customized.appendTailTextItalic(HINT_TEXT[digitIndex], true)
|
val customized = LookupElementPresentation()
|
||||||
return@addPresentationCustomizer customized
|
customized.copyFrom(presentation)
|
||||||
|
customized.appendTailTextItalic(hint, true)
|
||||||
|
return@addPresentationCustomizer customized
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<description><![CDATA[
|
<description><![CDATA[
|
||||||
Collection of keyboard-centric additions.
|
Collection of keyboard-centric additions.
|
||||||
<ul>
|
<ul>
|
||||||
<li>Code completion items can be jumped to using numbers.</li>
|
<li>Code completion items can be jumped to using customizable characters (numbers by default).</li>
|
||||||
</ul>
|
</ul>
|
||||||
]]></description>
|
]]></description>
|
||||||
|
|
||||||
@ -17,6 +17,8 @@
|
|||||||
</projectListeners>
|
</projectListeners>
|
||||||
|
|
||||||
<extensions defaultExtensionNs="com.intellij">
|
<extensions defaultExtensionNs="com.intellij">
|
||||||
|
<applicationService serviceImplementation="com.chylex.intellij.keyboardmaster.configuration.PluginConfiguration" />
|
||||||
|
<applicationConfigurable parentId="tools" instance="com.chylex.intellij.keyboardmaster.configuration.PluginConfigurable" id="com.chylex.keyboardmaster" />
|
||||||
<!--suppress PluginXmlValidity, PluginXmlDynamicPlugin -->
|
<!--suppress PluginXmlValidity, PluginXmlDynamicPlugin -->
|
||||||
<editorTypedHandler implementationClass="com.chylex.intellij.keyboardmaster.lookup.LookupTypedActionHandler" />
|
<editorTypedHandler implementationClass="com.chylex.intellij.keyboardmaster.lookup.LookupTypedActionHandler" />
|
||||||
</extensions>
|
</extensions>
|
||||||
|
Loading…
Reference in New Issue
Block a user