diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/actions/ClearScratchAction.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/actions/ClearScratchAction.kt
index ed3324e1563..f564f3ea11c 100644
--- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/actions/ClearScratchAction.kt
+++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/actions/ClearScratchAction.kt
@@ -17,19 +17,18 @@
package org.jetbrains.kotlin.idea.scratch.actions
import com.intellij.icons.AllIcons
-import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
+import com.intellij.openapi.actionSystem.CommonDataKeys
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.scratch.ScratchFileLanguageProvider
-import org.jetbrains.kotlin.idea.scratch.ui.ScratchTopPanel
-class ClearScratchAction(private val scratchPanel: ScratchTopPanel) : AnAction(
- KotlinBundle.message("scratch.clear.button"),
+class ClearScratchAction : ScratchAction(
KotlinBundle.message("scratch.clear.button"),
AllIcons.Actions.GC
) {
override fun actionPerformed(e: AnActionEvent) {
- val scratchFile = scratchPanel.scratchFile
+ val editor = e.getData(CommonDataKeys.EDITOR) ?: return
+ val scratchFile = getScratchPanel(editor)?.scratchFile ?: return
val psiFile = scratchFile.getPsiFile() ?: return
ScratchFileLanguageProvider.get(psiFile.language)?.getOutputHandler()?.clear(scratchFile)
diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/actions/RunScratchAction.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/actions/RunScratchAction.kt
index dc0e7f937f5..cf28507cee6 100644
--- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/actions/RunScratchAction.kt
+++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/actions/RunScratchAction.kt
@@ -17,25 +17,34 @@
package org.jetbrains.kotlin.idea.scratch.actions
import com.intellij.icons.AllIcons
-import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
+import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.compiler.CompilerManager
+import com.intellij.openapi.keymap.KeymapManager
+import com.intellij.openapi.keymap.KeymapUtil
import com.intellij.openapi.project.DumbService
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.scratch.ScratchFile
import org.jetbrains.kotlin.idea.scratch.ScratchFileLanguageProvider
import org.jetbrains.kotlin.idea.scratch.output.ScratchOutputHandlerAdapter
import org.jetbrains.kotlin.idea.scratch.printDebugMessage
-import org.jetbrains.kotlin.idea.scratch.ui.ScratchTopPanel
import org.jetbrains.kotlin.idea.scratch.LOG as log
-class RunScratchAction(private val scratchPanel: ScratchTopPanel) : AnAction(
- KotlinBundle.message("scratch.run.button"),
+class RunScratchAction : ScratchAction(
KotlinBundle.message("scratch.run.button"),
AllIcons.Actions.Execute
) {
+
+ init {
+ KeymapManager.getInstance().activeKeymap.getShortcuts("Kotlin.RunScratch").firstOrNull()?.let {
+ templatePresentation.text += " (${KeymapUtil.getShortcutText(it)})"
+ }
+ }
+
override fun actionPerformed(e: AnActionEvent) {
val project = e.project ?: return
+ val editor = e.getData(CommonDataKeys.EDITOR) ?: return
+ val scratchPanel = getScratchPanel(editor) ?: return
val scratchFile = scratchPanel.scratchFile
val psiFile = scratchFile.getPsiFile() ?: return
diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/actions/ScratchAction.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/actions/ScratchAction.kt
new file mode 100644
index 00000000000..f6542bc05e6
--- /dev/null
+++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/actions/ScratchAction.kt
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
+ * that can be found in the license/LICENSE.txt file.
+ */
+
+package org.jetbrains.kotlin.idea.scratch.actions
+
+import com.intellij.openapi.actionSystem.AnAction
+import com.intellij.openapi.actionSystem.AnActionEvent
+import com.intellij.openapi.editor.Editor
+import com.intellij.openapi.fileEditor.FileEditorManager
+import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider
+import org.jetbrains.kotlin.idea.scratch.getScratchPanel
+import org.jetbrains.kotlin.idea.scratch.ui.ScratchTopPanel
+import javax.swing.Icon
+
+abstract class ScratchAction(message: String, icon: Icon) : AnAction(message, message, icon) {
+ override fun update(e: AnActionEvent) {
+ val presentation = e.presentation
+
+ val project = e.project ?: return
+ val editor = FileEditorManager.getInstance(project).selectedTextEditor ?: return
+ val scratchPanel = getScratchPanel(editor)
+
+ presentation.isVisible = scratchPanel != null
+ }
+
+ protected fun getScratchPanel(editor: Editor): ScratchTopPanel? {
+ return TextEditorProvider.getInstance().getTextEditor(editor).getScratchPanel()
+ }
+}
\ No newline at end of file
diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/ui/ScratchTopPanel.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/ui/ScratchTopPanel.kt
index 70e67e8988c..d4715bcb942 100644
--- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/ui/ScratchTopPanel.kt
+++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/ui/ScratchTopPanel.kt
@@ -121,9 +121,9 @@ class ScratchTopPanel private constructor(val scratchFile: ScratchFile) : JPanel
private fun createActionsToolbar(): JComponent {
val toolbarGroup = DefaultActionGroup().apply {
- add(RunScratchAction(this@ScratchTopPanel))
+ add(RunScratchAction())
addSeparator()
- add(ClearScratchAction(this@ScratchTopPanel))
+ add(ClearScratchAction())
}
return ActionManager.getInstance().createActionToolbar(ActionPlaces.EDITOR_TOOLBAR, toolbarGroup, true).component
diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml
index 2511fbe6a0b..fc9bcedc38f 100644
--- a/idea/src/META-INF/plugin.xml
+++ b/idea/src/META-INF/plugin.xml
@@ -230,6 +230,15 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
+
+
+
+
+
+
+
diff --git a/idea/src/META-INF/plugin.xml.173 b/idea/src/META-INF/plugin.xml.173
index c090a0feab2..3ed788f4488 100644
--- a/idea/src/META-INF/plugin.xml.173
+++ b/idea/src/META-INF/plugin.xml.173
@@ -228,6 +228,15 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
+
+
+
+
+
+
+
diff --git a/idea/src/META-INF/plugin.xml.181 b/idea/src/META-INF/plugin.xml.181
index 937b49c6723..d4830ccb535 100644
--- a/idea/src/META-INF/plugin.xml.181
+++ b/idea/src/META-INF/plugin.xml.181
@@ -229,6 +229,15 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
+
+
+
+
+
+
+
diff --git a/idea/src/META-INF/plugin.xml.183 b/idea/src/META-INF/plugin.xml.183
index acee5a437d8..07cc471768f 100644
--- a/idea/src/META-INF/plugin.xml.183
+++ b/idea/src/META-INF/plugin.xml.183
@@ -230,6 +230,15 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
+
+
+
+
+
+
+
diff --git a/idea/src/META-INF/plugin.xml.as31 b/idea/src/META-INF/plugin.xml.as31
index 47c633b89ca..de71a9656a1 100644
--- a/idea/src/META-INF/plugin.xml.as31
+++ b/idea/src/META-INF/plugin.xml.as31
@@ -228,6 +228,15 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
+
+
+
+
+
+
+
diff --git a/idea/src/META-INF/plugin.xml.as32 b/idea/src/META-INF/plugin.xml.as32
index 1480714a3ef..013563f1806 100644
--- a/idea/src/META-INF/plugin.xml.as32
+++ b/idea/src/META-INF/plugin.xml.as32
@@ -228,6 +228,15 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
+
+
+
+
+
+
+
diff --git a/idea/src/META-INF/plugin.xml.as33 b/idea/src/META-INF/plugin.xml.as33
index 5346d7fa6f3..d7be7ef8faa 100644
--- a/idea/src/META-INF/plugin.xml.as33
+++ b/idea/src/META-INF/plugin.xml.as33
@@ -229,6 +229,15 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
+
+
+
+
+
+
+
diff --git a/idea/tests/org/jetbrains/kotlin/idea/scratch/AbstractScratchRunActionTest.kt b/idea/tests/org/jetbrains/kotlin/idea/scratch/AbstractScratchRunActionTest.kt
index e3568ab5659..3f15f124ae4 100644
--- a/idea/tests/org/jetbrains/kotlin/idea/scratch/AbstractScratchRunActionTest.kt
+++ b/idea/tests/org/jetbrains/kotlin/idea/scratch/AbstractScratchRunActionTest.kt
@@ -114,7 +114,7 @@ abstract class AbstractScratchRunActionTest : FileEditorManagerTestCase() {
val (editor, scratchPanel) = getEditorWithScratchPanel(myManager, scratchFile)?: error("Couldn't find scratch panel")
scratchPanel.setReplMode(isRepl)
- val action = RunScratchAction(scratchPanel)
+ val action = RunScratchAction()
val event = getActionEvent(scratchFile, action)
launchAction(event, action)