From e441aa0a3f088bbb5a10618900190d2073ad95ca Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Mon, 29 Jun 2015 14:07:56 +0200 Subject: [PATCH] show Kotlin bytecode by explicit request, rather than always --- idea/src/META-INF/plugin.xml | 12 ++--- .../idea/actions/ShowKotlinBytecodeAction.kt | 52 +++++++++++++++++++ .../internal/KotlinBytecodeToolWindow.java | 12 ----- 3 files changed, 57 insertions(+), 19 deletions(-) create mode 100644 idea/src/org/jetbrains/kotlin/idea/actions/ShowKotlinBytecodeAction.kt diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 9d6eb5f4b1a..a2373e50d38 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -105,6 +105,11 @@ + + + + @@ -499,13 +504,6 @@ - - diff --git a/idea/src/org/jetbrains/kotlin/idea/actions/ShowKotlinBytecodeAction.kt b/idea/src/org/jetbrains/kotlin/idea/actions/ShowKotlinBytecodeAction.kt new file mode 100644 index 00000000000..fea79d49978 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/actions/ShowKotlinBytecodeAction.kt @@ -0,0 +1,52 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.idea.actions + +import com.intellij.openapi.actionSystem.AnAction +import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.actionSystem.CommonDataKeys +import com.intellij.openapi.util.IconLoader +import com.intellij.openapi.wm.ToolWindowAnchor +import com.intellij.openapi.wm.ToolWindowManager +import com.intellij.ui.content.ContentFactory +import org.jetbrains.kotlin.idea.JetFileType +import org.jetbrains.kotlin.idea.internal.KotlinBytecodeToolWindow + +public class ShowKotlinBytecodeAction(): AnAction() { + val TOOLWINDOW_ID = "Kotlin Bytecode" + + override fun actionPerformed(e: AnActionEvent) { + val project = e.getProject() ?: return + val toolWindowManager = ToolWindowManager.getInstance(project) + + var toolWindow = toolWindowManager.getToolWindow(TOOLWINDOW_ID) + if (toolWindow == null) { + toolWindow = toolWindowManager.registerToolWindow("Kotlin Bytecode", true, ToolWindowAnchor.RIGHT) + toolWindow.setIcon(IconLoader.getIcon("/org/jetbrains/kotlin/idea/icons/kotlin13.png")) + + val contentManager = toolWindow.getContentManager() + val contentFactory = ContentFactory.SERVICE.getInstance() + contentManager.addContent(contentFactory.createContent(KotlinBytecodeToolWindow(project, toolWindow), "", false)) + } + toolWindow?.activate(null) + } + + override fun update(e: AnActionEvent) { + val file = e.getData(CommonDataKeys.PSI_FILE) + e.getPresentation().setEnabled(e.getProject() != null && file?.getFileType() == JetFileType.INSTANCE) + } +} diff --git a/idea/src/org/jetbrains/kotlin/idea/internal/KotlinBytecodeToolWindow.java b/idea/src/org/jetbrains/kotlin/idea/internal/KotlinBytecodeToolWindow.java index e6db8f4e59a..5a7800c222b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/internal/KotlinBytecodeToolWindow.java +++ b/idea/src/org/jetbrains/kotlin/idea/internal/KotlinBytecodeToolWindow.java @@ -31,8 +31,6 @@ import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.wm.ToolWindow; import com.intellij.openapi.wm.ToolWindowFactory; -import com.intellij.ui.content.ContentFactory; -import com.intellij.ui.content.ContentManager; import com.intellij.util.Alarm; import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.backend.common.output.OutputFile; @@ -362,14 +360,4 @@ public class KotlinBytecodeToolWindow extends JPanel implements Disposable { public void dispose() { EditorFactory.getInstance().releaseEditor(myEditor); } - - public static class Factory implements ToolWindowFactory { - @Override - public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) { - ContentManager contentManager = toolWindow.getContentManager(); - ContentFactory contentFactory = ContentFactory.SERVICE.getInstance(); - contentManager.addContent(contentFactory.createContent( - new KotlinBytecodeToolWindow(project, toolWindow), "", false)); - } - } }