mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
tweaks for ctrl click handler (cherry picked from commit a5ef770)
This commit is contained in:
+17
-1
@@ -27,6 +27,7 @@ import com.intellij.ide.util.DefaultPsiElementCellRenderer;
|
||||
import com.intellij.ide.util.EditSourceUtil;
|
||||
import com.intellij.injected.editor.EditorWindow;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.Presentation;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
@@ -194,7 +195,7 @@ public class GotoDeclarationAction extends BaseCodeInsightAction implements Code
|
||||
|
||||
for (GotoDeclarationHandler handler : Extensions.getExtensions(GotoDeclarationHandler.EP_NAME)) {
|
||||
try {
|
||||
PsiElement[] result = handler.getGotoDeclarationTargets(elementAt, editor);
|
||||
PsiElement[] result = handler.getGotoDeclarationTargets(elementAt, offset, editor);
|
||||
if (result != null && result.length > 0) {
|
||||
return result;
|
||||
}
|
||||
@@ -234,6 +235,21 @@ public class GotoDeclarationAction extends BaseCodeInsightAction implements Code
|
||||
}
|
||||
}
|
||||
|
||||
for (GotoDeclarationHandler handler : Extensions.getExtensions(GotoDeclarationHandler.EP_NAME)) {
|
||||
try {
|
||||
final String text = handler.getActionText(event.getDataContext());
|
||||
|
||||
if (text != null) {
|
||||
Presentation presentation = event.getPresentation();
|
||||
presentation.setText(text);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (AbstractMethodError e) {
|
||||
LOG.error(handler.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
super.update(event);
|
||||
}
|
||||
}
|
||||
|
||||
+13
-3
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.intellij.codeInsight.navigation.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -30,10 +31,19 @@ public interface GotoDeclarationHandler {
|
||||
/**
|
||||
* Provides an array of target declarations for given {@code sourceElement}.
|
||||
*
|
||||
*
|
||||
* @param sourceElement input psiElement
|
||||
* @param editor
|
||||
* @return all target declarations as an array of {@code PsiElement} or null if none was found
|
||||
* @param offset offset in the file
|
||||
*@param editor @return all target declarations as an array of {@code PsiElement} or null if none was found
|
||||
*/
|
||||
@Nullable
|
||||
PsiElement[] getGotoDeclarationTargets(PsiElement sourceElement, Editor editor);
|
||||
PsiElement[] getGotoDeclarationTargets(PsiElement sourceElement, int offset, Editor editor);
|
||||
|
||||
/**
|
||||
* Provides the custom action text
|
||||
* @return the custom text or null to use the default text
|
||||
* @param context the action data context
|
||||
*/
|
||||
@Nullable
|
||||
String getActionText(DataContext context);
|
||||
}
|
||||
|
||||
+7
-1
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.navigation.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -25,11 +26,16 @@ import org.jetbrains.annotations.Nullable;
|
||||
public abstract class GotoDeclarationHandlerBase implements GotoDeclarationHandler {
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiElement[] getGotoDeclarationTargets(PsiElement sourceElement, Editor editor) {
|
||||
public PsiElement[] getGotoDeclarationTargets(PsiElement sourceElement, int offset, Editor editor) {
|
||||
final PsiElement target = getGotoDeclarationTarget(sourceElement, editor);
|
||||
return target != null ? new PsiElement[] {target} : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public abstract PsiElement getGotoDeclarationTarget(PsiElement sourceElement, Editor editor);
|
||||
|
||||
@Override
|
||||
public String getActionText(DataContext context) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.jetbrains.android;
|
||||
|
||||
import com.intellij.codeInsight.navigation.actions.GotoDeclarationHandler;
|
||||
import com.intellij.navigation.NavigationItem;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.meta.PsiMetaOwner;
|
||||
@@ -35,7 +36,7 @@ import java.util.List;
|
||||
*/
|
||||
public class AndroidGotoDeclarationHandler implements GotoDeclarationHandler {
|
||||
@Override
|
||||
public PsiElement[] getGotoDeclarationTargets(PsiElement sourceElement, Editor editor) {
|
||||
public PsiElement[] getGotoDeclarationTargets(PsiElement sourceElement, int offset, Editor editor) {
|
||||
if (!(sourceElement instanceof PsiIdentifier)) {
|
||||
return null;
|
||||
}
|
||||
@@ -103,4 +104,9 @@ public class AndroidGotoDeclarationHandler implements GotoDeclarationHandler {
|
||||
}
|
||||
return wrappedResources.length > 0 ? wrappedResources : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getActionText(DataContext context) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user