mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 19:02:13 +07:00
NavigateAction
This commit is contained in:
@@ -16,11 +16,9 @@
|
||||
package com.intellij.codeInsight.daemon.impl;
|
||||
|
||||
import com.intellij.codeHighlighting.Pass;
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzerSettings;
|
||||
import com.intellij.codeInsight.daemon.LineMarkerInfo;
|
||||
import com.intellij.codeInsight.daemon.LineMarkerProvider;
|
||||
import com.intellij.codeInsight.daemon.MergeableLineMarkerInfo;
|
||||
import com.intellij.codeInsight.daemon.*;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.openapi.actionSystem.IdeActions;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.colors.CodeInsightColors;
|
||||
@@ -75,7 +73,8 @@ public class JavaLineMarkerProvider implements LineMarkerProvider {
|
||||
|
||||
final Icon icon = overrides ? AllIcons.Gutter.OverridingMethod : AllIcons.Gutter.ImplementingMethod;
|
||||
final MarkerType type = MarkerType.OVERRIDING_METHOD;
|
||||
return new ArrowUpLineMarkerInfo(element, icon, type);
|
||||
ArrowUpLineMarkerInfo info = new ArrowUpLineMarkerInfo(element, icon, type);
|
||||
return NavigateAction.setNavigateAction(info, "Go to super method", "GotoSuperMethod");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +83,8 @@ public class JavaLineMarkerProvider implements LineMarkerProvider {
|
||||
if (interfaceMethod != null && firstChild != null) {
|
||||
final Icon icon = AllIcons.Gutter.ImplementingMethod;
|
||||
final MarkerType type = MarkerType.OVERRIDING_METHOD;
|
||||
return new ArrowUpLineMarkerInfo(firstChild, icon, type);
|
||||
ArrowUpLineMarkerInfo info = new ArrowUpLineMarkerInfo(firstChild, icon, type);
|
||||
return NavigateAction.setNavigateAction(info, "Go to super method", "GotoSuperMethod");
|
||||
}
|
||||
|
||||
if (myDaemonSettings.SHOW_METHOD_SEPARATORS && firstChild == null) {
|
||||
@@ -183,6 +183,7 @@ public class JavaLineMarkerProvider implements LineMarkerProvider {
|
||||
icon, Pass.UPDATE_OVERRIDEN_MARKERS, type.getTooltip(),
|
||||
type.getNavigationHandler(),
|
||||
GutterIconRenderer.Alignment.RIGHT);
|
||||
NavigateAction.setNavigateAction(info, aClass.isInterface() ? "Go to implementation(s)" : "Go to subclass(es)", IdeActions.ACTION_GOTO_IMPLEMENTATION);
|
||||
result.add(info);
|
||||
}
|
||||
}
|
||||
@@ -243,12 +244,12 @@ public class JavaLineMarkerProvider implements LineMarkerProvider {
|
||||
}
|
||||
}
|
||||
if (range == null) range = method;
|
||||
final MarkerType type = MarkerType.OVERRIDEN_METHOD;
|
||||
final MarkerType type = MarkerType.OVERRIDDEN_METHOD;
|
||||
LineMarkerInfo<PsiElement> info = new LineMarkerInfo<PsiElement>(range, range.getTextRange(),
|
||||
icon, Pass.UPDATE_OVERRIDEN_MARKERS, type.getTooltip(),
|
||||
type.getNavigationHandler(),
|
||||
GutterIconRenderer.Alignment.RIGHT);
|
||||
info.setNavigateActionTextProvider(type.getNavigateActionText());
|
||||
NavigateAction.setNavigateAction(info, overrides ? "Go to overriding methods" : "Go to implementation(s)", IdeActions.ACTION_GOTO_IMPLEMENTATION);
|
||||
result.add(info);
|
||||
}
|
||||
}
|
||||
@@ -257,7 +258,6 @@ public class JavaLineMarkerProvider implements LineMarkerProvider {
|
||||
private ArrowUpLineMarkerInfo(@NotNull PsiElement element, Icon icon, @NotNull MarkerType markerType) {
|
||||
super(element, element.getTextRange(), icon, Pass.UPDATE_ALL, markerType.getTooltip(),
|
||||
markerType.getNavigationHandler(), GutterIconRenderer.Alignment.LEFT);
|
||||
setNavigateActionTextProvider(markerType.getNavigateActionText());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.intellij.codeInsight.daemon.DaemonBundle;
|
||||
import com.intellij.codeInsight.daemon.GutterIconNavigationHandler;
|
||||
import com.intellij.codeInsight.navigation.ListBackgroundUpdaterTask;
|
||||
import com.intellij.ide.util.*;
|
||||
import com.intellij.openapi.actionSystem.IdeActions;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
@@ -49,7 +50,36 @@ import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
|
||||
public class MarkerType {
|
||||
public static final MarkerType OVERRIDING_METHOD = new MarkerType(new NullableFunction<PsiElement, String>() {
|
||||
|
||||
private final GutterIconNavigationHandler<PsiElement> handler;
|
||||
private final Function<PsiElement, String> myTooltip;
|
||||
|
||||
public MarkerType(@NotNull Function<PsiElement, String> tooltip, @NotNull final LineMarkerNavigator navigator,
|
||||
@Nullable Function<PsiElement, String> actionText, @Nullable String actionId) {
|
||||
myTooltip = tooltip;
|
||||
handler = new GutterIconNavigationHandler<PsiElement>() {
|
||||
@Override
|
||||
public void navigate(MouseEvent e, PsiElement elt) {
|
||||
navigator.browse(e, elt);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public MarkerType(@NotNull Function<PsiElement, String> tooltip, @NotNull final LineMarkerNavigator navigator) {
|
||||
this(tooltip, navigator, null, null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public GutterIconNavigationHandler<PsiElement> getNavigationHandler() {
|
||||
return handler;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Function<PsiElement, String> getTooltip() {
|
||||
return myTooltip;
|
||||
}
|
||||
|
||||
static final MarkerType OVERRIDING_METHOD = new MarkerType(new NullableFunction<PsiElement, String>() {
|
||||
@Override
|
||||
public String fun(PsiElement element) {
|
||||
PsiElement parent = getParentMethod(element);
|
||||
@@ -66,7 +96,7 @@ public class MarkerType {
|
||||
PsiMethod method = (PsiMethod)parent;
|
||||
navigateToOverridingMethod(e, method, method != element.getParent());
|
||||
}
|
||||
}, new ConstantFunction<PsiElement, String>("Go to overriding method(s)"));
|
||||
}, new ConstantFunction<PsiElement, String>("Go to overriding method(s)"), IdeActions.ACTION_GOTO_IMPLEMENTATION);
|
||||
|
||||
@Nullable
|
||||
public static String calculateOverridingMethodTooltip(PsiMethod method, boolean acceptSelf) {
|
||||
@@ -115,7 +145,7 @@ public class MarkerType {
|
||||
}
|
||||
|
||||
public static final String SEARCHING_FOR_OVERRIDING_METHODS = "Searching for Overriding Methods";
|
||||
public static final MarkerType OVERRIDEN_METHOD = new MarkerType(new NullableFunction<PsiElement, String>() {
|
||||
static final MarkerType OVERRIDDEN_METHOD = new MarkerType(new NullableFunction<PsiElement, String>() {
|
||||
@Override
|
||||
public String fun(PsiElement element) {
|
||||
PsiElement parent = element.getParent();
|
||||
@@ -132,7 +162,7 @@ public class MarkerType {
|
||||
navigateToOverriddenMethod(e, (PsiMethod)parent);
|
||||
|
||||
}
|
||||
}, new ConstantFunction<PsiElement, String>("Go to overriding methods"));
|
||||
}, new ConstantFunction<PsiElement, String>("Go to overridden method"), IdeActions.ACTION_GOTO_IMPLEMENTATION);
|
||||
|
||||
public static String getOverriddenMethodTooltip(final PsiMethod method) {
|
||||
PsiElementProcessor.CollectElementsWithLimit<PsiMethod> processor = new PsiElementProcessor.CollectElementsWithLimit<PsiMethod>(5);
|
||||
@@ -202,8 +232,8 @@ public class MarkerType {
|
||||
PsiElementListNavigator.openTargets(e, overridings, methodsUpdater.getCaption(overridings.length), "Overriding methods of " + method.getName(), renderer, methodsUpdater);
|
||||
}
|
||||
|
||||
public static final String SEARCHING_FOR_OVERRIDDEN_METHODS = "Searching for Overridden Methods";
|
||||
public static final MarkerType SUBCLASSED_CLASS = new MarkerType(new NullableFunction<PsiElement, String>() {
|
||||
private static final String SEARCHING_FOR_OVERRIDDEN_METHODS = "Searching for Overridden Methods";
|
||||
static final MarkerType SUBCLASSED_CLASS = new MarkerType(new NullableFunction<PsiElement, String>() {
|
||||
@Override
|
||||
public String fun(PsiElement element) {
|
||||
PsiElement parent = element.getParent();
|
||||
@@ -228,7 +258,7 @@ public class MarkerType {
|
||||
final PsiClass aClass = (PsiClass)parent;
|
||||
return aClass.isInterface() ? "Go to implementation(s)" : "Go to subclass(es)";
|
||||
}
|
||||
});
|
||||
}, IdeActions.ACTION_GOTO_IMPLEMENTATION);
|
||||
|
||||
public static String getSubclassedClassTooltip(PsiClass aClass) {
|
||||
PsiElementProcessor.CollectElementsWithLimit<PsiClass> processor = new PsiElementProcessor.CollectElementsWithLimit<PsiClass>(5, new THashSet<PsiClass>());
|
||||
@@ -290,40 +320,6 @@ public class MarkerType {
|
||||
PsiElementListNavigator.openTargets(e, inheritors, subclassUpdater.getCaption(inheritors.length), CodeInsightBundle.message("goto.implementation.findUsages.title", aClass.getName()), renderer, subclassUpdater);
|
||||
}
|
||||
|
||||
private final GutterIconNavigationHandler<PsiElement> handler;
|
||||
private final Function<PsiElement, String> myTooltip;
|
||||
private final Function<PsiElement, String> myNavigateActionText;
|
||||
|
||||
public MarkerType(@NotNull Function<PsiElement, String> tooltip, @NotNull final LineMarkerNavigator navigator,
|
||||
@Nullable Function<PsiElement, String> actionText) {
|
||||
myTooltip = tooltip;
|
||||
handler = new GutterIconNavigationHandler<PsiElement>() {
|
||||
@Override
|
||||
public void navigate(MouseEvent e, PsiElement elt) {
|
||||
navigator.browse(e, elt);
|
||||
}
|
||||
};
|
||||
myNavigateActionText = actionText;
|
||||
}
|
||||
|
||||
public MarkerType(@NotNull Function<PsiElement, String> tooltip, @NotNull final LineMarkerNavigator navigator) {
|
||||
this(tooltip, navigator, null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public GutterIconNavigationHandler<PsiElement> getNavigationHandler() {
|
||||
return handler;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Function<PsiElement, String> getTooltip() {
|
||||
return myTooltip;
|
||||
}
|
||||
|
||||
public Function<PsiElement, String> getNavigateActionText() {
|
||||
return myNavigateActionText;
|
||||
}
|
||||
|
||||
private static class SubclassUpdater extends ListBackgroundUpdaterTask {
|
||||
private final PsiClass myClass;
|
||||
private final PsiClassOrFunctionalExpressionListCellRenderer myRenderer;
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package com.intellij.codeInsight.daemon;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.editor.markup.GutterIconRenderer;
|
||||
import com.intellij.openapi.editor.markup.RangeHighlighter;
|
||||
import com.intellij.openapi.editor.markup.SeparatorPlacement;
|
||||
@@ -31,7 +30,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
public class LineMarkerInfo<T extends PsiElement> {
|
||||
@@ -45,7 +43,7 @@ public class LineMarkerInfo<T extends PsiElement> {
|
||||
|
||||
public final int updatePass;
|
||||
@Nullable private final Function<? super T, String> myTooltipProvider;
|
||||
@Nullable private Function<? super T, String> myNavigateActionTextProvider;
|
||||
private AnAction myNavigateAction = new NavigateAction<T>(this);
|
||||
@NotNull private final GutterIconRenderer.Alignment myIconAlignment;
|
||||
@Nullable private final GutterIconNavigationHandler<T> myNavigationHandler;
|
||||
|
||||
@@ -112,31 +110,8 @@ public class LineMarkerInfo<T extends PsiElement> {
|
||||
return elementRef.get();
|
||||
}
|
||||
|
||||
public void setNavigateActionTextProvider(@Nullable Function<? super T, String> navigateActionTextProvider) {
|
||||
myNavigateActionTextProvider = navigateActionTextProvider;
|
||||
}
|
||||
|
||||
private class NavigateAction extends AnAction {
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
if (myNavigationHandler != null) {
|
||||
MouseEvent mouseEvent = (MouseEvent)e.getInputEvent();
|
||||
T element = getElement();
|
||||
if (element == null || !element.isValid()) return;
|
||||
|
||||
myNavigationHandler.navigate(mouseEvent, element);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
if (myNavigateActionTextProvider == null) return;
|
||||
T element = getElement();
|
||||
if (element != null && element.isValid()) {
|
||||
String text = myNavigateActionTextProvider.fun(element);
|
||||
e.getPresentation().setText(text);
|
||||
}
|
||||
}
|
||||
public void setNavigateAction(AnAction navigateAction) {
|
||||
myNavigateAction = navigateAction;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -163,7 +138,7 @@ public class LineMarkerInfo<T extends PsiElement> {
|
||||
|
||||
@Override
|
||||
public AnAction getClickAction() {
|
||||
return myInfo.new NavigateAction();
|
||||
return myInfo.myNavigateAction;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2000-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 com.intellij.codeInsight.daemon;
|
||||
|
||||
import com.intellij.openapi.actionSystem.ActionManager;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.ShortcutSet;
|
||||
import com.intellij.psi.PsiElement;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
public class NavigateAction<T extends PsiElement> extends AnAction {
|
||||
private LineMarkerInfo<T> myInfo;
|
||||
|
||||
public NavigateAction(String text,
|
||||
LineMarkerInfo<T> info,
|
||||
String originalActionId) {
|
||||
super(text);
|
||||
myInfo = info;
|
||||
ShortcutSet set = ActionManager.getInstance().getAction(originalActionId).getShortcutSet();
|
||||
setShortcutSet(set);
|
||||
}
|
||||
|
||||
public NavigateAction(LineMarkerInfo<T> info) {
|
||||
myInfo = info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
if (myInfo.getNavigationHandler() != null) {
|
||||
MouseEvent mouseEvent = (MouseEvent)e.getInputEvent();
|
||||
T element = myInfo.getElement();
|
||||
if (element == null || !element.isValid()) return;
|
||||
|
||||
myInfo.getNavigationHandler().navigate(mouseEvent, element);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T extends PsiElement> LineMarkerInfo<T> setNavigateAction(LineMarkerInfo<T> info, String text, String originalActionId) {
|
||||
NavigateAction<T> action = new NavigateAction<T>(text, info, originalActionId);
|
||||
info.setNavigateAction(action);
|
||||
return info;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user