Added context menu to Kotlin signature icon with "Edit" action.

This commit is contained in:
Evgeny Gerashchenko
2012-09-05 19:55:45 +04:00
parent 091e1f9601
commit fe126b2d99
2 changed files with 78 additions and 9 deletions
@@ -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);
}
}
@@ -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<PsiMethod> NAVIGATION_HANDLER = new GutterIconNavigationHandler<PsiMethod>() {
@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>((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<PsiMethod> {
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<PsiMethod>(this) {
@Nullable
@Override
public ActionGroup getPopupMenuActions() {
DefaultActionGroup actionGroup = new DefaultActionGroup();
actionGroup.add(new EditSignatureAction(getElement()));
return actionGroup;
}
};
}
}
}