hide Show Implementation action just like Quick Doc when not appropriate

This commit is contained in:
Gregory.Shrago
2014-01-24 02:06:24 +04:00
parent 2ad99bc082
commit abc190b6c3
@@ -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<ImplementationViewComponent> {
private String myCaption;
private Editor myEditor;