From abc190b6c3c3e961279570a9f723e6ce23f9d98f Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Fri, 24 Jan 2014 02:05:32 +0400 Subject: [PATCH] hide Show Implementation action just like Quick Doc when not appropriate --- .../actions/ShowImplementationsAction.java | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hint/actions/ShowImplementationsAction.java b/platform/lang-impl/src/com/intellij/codeInsight/hint/actions/ShowImplementationsAction.java index 2af811074a54..77995ac6fd2a 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hint/actions/ShowImplementationsAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/hint/actions/ShowImplementationsAction.java @@ -54,6 +54,7 @@ import com.intellij.util.Processor; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.TestOnly; import java.lang.ref.WeakReference; import java.util.*; @@ -77,10 +78,32 @@ public class ShowImplementationsAction extends AnAction implements PopupAction { performForContext(e.getDataContext(), true); } + @TestOnly public void performForContext(DataContext dataContext) { 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) { Editor editor = CommonDataKeys.EDITOR.getData(dataContext); @@ -98,13 +121,11 @@ public class ShowImplementationsAction extends AnAction implements PopupAction { public void performForContext(DataContext dataContext, boolean invokedByShortcut) { final Project project = CommonDataKeys.PROJECT.getData(dataContext); - PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext); - if (project == null) return; - 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); 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); if (adjustedElement != null) { element = adjustedElement; - } else if (file != null) { + } + else if (file != null) { element = DocumentationManager.getInstance(project).getElementFromLookup(editor, file); } } @@ -354,12 +376,6 @@ public class ShowImplementationsAction extends AnAction implements PopupAction { 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 { private String myCaption; private Editor myEditor;