mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
hide Show Implementation action just like Quick Doc when not appropriate
This commit is contained in:
+27
-11
@@ -54,6 +54,7 @@ import com.intellij.util.Processor;
|
|||||||
import org.jetbrains.annotations.NonNls;
|
import org.jetbrains.annotations.NonNls;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.annotations.TestOnly;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -77,10 +78,32 @@ public class ShowImplementationsAction extends AnAction implements PopupAction {
|
|||||||
performForContext(e.getDataContext(), true);
|
performForContext(e.getDataContext(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestOnly
|
||||||
public void performForContext(DataContext dataContext) {
|
public void performForContext(DataContext dataContext) {
|
||||||
performForContext(dataContext, true);
|
performForContext(dataContext, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(final AnActionEvent e) {
|
||||||
|
Project project = e.getData(CommonDataKeys.PROJECT);
|
||||||
|
if (project == null) {
|
||||||
|
e.getPresentation().setEnabled(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DataContext dataContext = e.getDataContext();
|
||||||
|
Editor editor = getEditor(dataContext);
|
||||||
|
|
||||||
|
PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext);
|
||||||
|
PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
|
||||||
|
element = getElement(project, file, editor, element);
|
||||||
|
|
||||||
|
PsiFile containingFile = element != null ? element.getContainingFile() : file;
|
||||||
|
boolean enabled = !(containingFile == null || !containingFile.getViewProvider().isPhysical());
|
||||||
|
e.getPresentation().setEnabled(enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected Editor getEditor(DataContext dataContext) {
|
protected Editor getEditor(DataContext dataContext) {
|
||||||
Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
|
Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
|
||||||
|
|
||||||
@@ -98,13 +121,11 @@ public class ShowImplementationsAction extends AnAction implements PopupAction {
|
|||||||
|
|
||||||
public void performForContext(DataContext dataContext, boolean invokedByShortcut) {
|
public void performForContext(DataContext dataContext, boolean invokedByShortcut) {
|
||||||
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
|
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
|
||||||
PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext);
|
|
||||||
|
|
||||||
if (project == null) return;
|
if (project == null) return;
|
||||||
|
|
||||||
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
||||||
|
|
||||||
final Editor editor = getEditor(dataContext);
|
PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext);
|
||||||
|
Editor editor = getEditor(dataContext);
|
||||||
|
|
||||||
PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
|
PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
|
||||||
boolean isInvokedFromEditor = CommonDataKeys.EDITOR.getData(dataContext) != null;
|
boolean isInvokedFromEditor = CommonDataKeys.EDITOR.getData(dataContext) != null;
|
||||||
@@ -162,7 +183,8 @@ public class ShowImplementationsAction extends AnAction implements PopupAction {
|
|||||||
TargetElementUtilBase.getInstance().adjustElement(editor, TargetElementUtilBase.getInstance().getAllAccepted(), element, null);
|
TargetElementUtilBase.getInstance().adjustElement(editor, TargetElementUtilBase.getInstance().getAllAccepted(), element, null);
|
||||||
if (adjustedElement != null) {
|
if (adjustedElement != null) {
|
||||||
element = adjustedElement;
|
element = adjustedElement;
|
||||||
} else if (file != null) {
|
}
|
||||||
|
else if (file != null) {
|
||||||
element = DocumentationManager.getInstance(project).getElementFromLookup(editor, file);
|
element = DocumentationManager.getInstance(project).getElementFromLookup(editor, file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -354,12 +376,6 @@ public class ShowImplementationsAction extends AnAction implements PopupAction {
|
|||||||
return PsiUtilCore.toPsiElementArray(unique);
|
return PsiUtilCore.toPsiElementArray(unique);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update(final AnActionEvent e) {
|
|
||||||
final Project project = e.getData(CommonDataKeys.PROJECT);
|
|
||||||
e.getPresentation().setEnabled(project != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class ImplementationsUpdaterTask extends BackgroundUpdaterTask<ImplementationViewComponent> {
|
private static class ImplementationsUpdaterTask extends BackgroundUpdaterTask<ImplementationViewComponent> {
|
||||||
private String myCaption;
|
private String myCaption;
|
||||||
private Editor myEditor;
|
private Editor myEditor;
|
||||||
|
|||||||
Reference in New Issue
Block a user