Last active
December 3, 2018 01:01
-
-
Save masanobuimai/e839265005beb505dff98515b97551b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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