diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/ktSignature/EditSignatureAction.java b/idea/src/org/jetbrains/jet/plugin/codeInsight/ktSignature/EditSignatureAction.java new file mode 100644 index 00000000000..d9f26bb9e9b --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/ktSignature/EditSignatureAction.java @@ -0,0 +1,52 @@ +/* + * Copyright 2010-2012 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.jet.plugin.codeInsight.ktSignature; + +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.actionSystem.PlatformDataKeys; +import com.intellij.openapi.editor.Editor; +import com.intellij.psi.PsiMethod; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.awt.*; + +/** + * @author Evgeny Gerashchenko + * @since 5 Sep 12 + */ +public class EditSignatureAction extends AnAction { + private final PsiMethod annotationOwner; + + public EditSignatureAction(PsiMethod annotationOwner) { + super("Edit"); + this.annotationOwner = annotationOwner; + } + + @Override + public void actionPerformed(AnActionEvent e) { + actionPerformed(e.getDataContext(), null); + } + + public void actionPerformed(@NotNull DataContext dataContext, @Nullable Point point) { + Editor editor = PlatformDataKeys.EDITOR.getData(dataContext); + assert editor != null; + EditSignatureBalloon.invokeEditSignature(annotationOwner, editor, point); + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/ktSignature/KotlinSignatureInJavaMarkerProvider.java b/idea/src/org/jetbrains/jet/plugin/codeInsight/ktSignature/KotlinSignatureInJavaMarkerProvider.java index 33dc3b4aa5c..1c2c1b35a2d 100644 --- a/idea/src/org/jetbrains/jet/plugin/codeInsight/ktSignature/KotlinSignatureInJavaMarkerProvider.java +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/ktSignature/KotlinSignatureInJavaMarkerProvider.java @@ -22,8 +22,9 @@ import com.intellij.codeInsight.daemon.LineMarkerInfo; import com.intellij.codeInsight.daemon.LineMarkerProvider; import com.intellij.ide.DataManager; import com.intellij.ide.util.PropertiesComponent; -import com.intellij.openapi.actionSystem.PlatformDataKeys; +import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.markup.GutterIconRenderer; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiAnnotation; @@ -62,12 +63,9 @@ public class KotlinSignatureInJavaMarkerProvider implements LineMarkerProvider { private static final GutterIconNavigationHandler NAVIGATION_HANDLER = new GutterIconNavigationHandler() { @Override public void navigate(MouseEvent e, PsiMethod element) { - if (!UIUtil.isActionClick(e, MouseEvent.MOUSE_RELEASED)) return; - - Editor editor = PlatformDataKeys.EDITOR.getData(DataManager.getInstance().getDataContext(e.getComponent())); - assert editor != null; - - EditSignatureBalloon.invokeEditSignature(element, editor, e.getPoint()); + if (UIUtil.isActionClick(e, MouseEvent.MOUSE_RELEASED)) { + new EditSignatureAction(element).actionPerformed(DataManager.getInstance().getDataContext(e.getComponent()), e.getPoint()); + } } }; @@ -76,8 +74,7 @@ public class KotlinSignatureInJavaMarkerProvider implements LineMarkerProvider { @Nullable public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement element) { if (isMarkersEnabled(element.getProject()) && findKotlinSignatureAnnotation(element) != null) { - return new LineMarkerInfo((PsiMethod) element, element.getTextOffset(), JetIcons.SMALL_LOGO, Pass.UPDATE_ALL, - TOOLTIP_PROVIDER, NAVIGATION_HANDLER); + return new MyLineMarkerInfo(element); } return null; } @@ -94,4 +91,24 @@ public class KotlinSignatureInJavaMarkerProvider implements LineMarkerProvider { PropertiesComponent.getInstance(project).setValue(SHOW_MARKERS_PROPERTY, Boolean.toString(value)); refreshMarkers(project); } + + private static class MyLineMarkerInfo extends LineMarkerInfo { + public MyLineMarkerInfo(PsiElement element) { + super((PsiMethod) element, element.getTextOffset(), JetIcons.SMALL_LOGO, Pass.UPDATE_ALL, TOOLTIP_PROVIDER, NAVIGATION_HANDLER); + } + + @Nullable + @Override + public GutterIconRenderer createGutterRenderer() { + return new LineMarkerGutterIconRenderer(this) { + @Nullable + @Override + public ActionGroup getPopupMenuActions() { + DefaultActionGroup actionGroup = new DefaultActionGroup(); + actionGroup.add(new EditSignatureAction(getElement())); + return actionGroup; + } + }; + } + } }