Skip to content

Instantly share code, notes, and snippets.

@masanobuimai
Last active December 3, 2018 01:01
Show Gist options
  • Save masanobuimai/e839265005beb505dff98515b97551b4 to your computer and use it in GitHub Desktop.
Save masanobuimai/e839265005beb505dff98515b97551b4 to your computer and use it in GitHub Desktop.
import com.intellij.ide.script.IDE
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.KeyboardShortcut
import com.intellij.openapi.keymap.KeymapManager
import com.intellij.openapi.project.ProjectManager
import org.jetbrains.ide.script.IdeScriptEngineManager
import javax.swing.KeyStroke
val ide = bindings["IDE"] as IDE
fun action(name: String, shortcut: String,
action: (AnActionEvent) -> Unit) {
val actions = ActionManager.getInstance()
val keymaps = KeymapManager.getInstance()
actions.unregisterAction(name)
keymaps.activeKeymap.removeAllActionShortcuts(name)
actions.registerAction(name, object : AnAction(name, name, null) {
override fun actionPerformed(e: AnActionEvent) {
action(e)
}
})
keymaps.activeKeymap.addShortcut(name,
KeyboardShortcut(KeyStroke.getKeyStroke(shortcut), null))
}
import com.intellij.openapi.diagnostic.Logger
val LOG = Logger.getInstance("mars")
action("TestMe!!", "alt shift P", { e ->
run {
LOG.info("hello kotlin!!!")
ide.print("HELLO KOTLIN")
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment