use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class PsiNavigateUtil method navigate.
public static void navigate(@Nullable final PsiElement psiElement) {
if (psiElement != null && psiElement.isValid()) {
final PsiElement navigationElement = psiElement.getNavigationElement();
final int offset = navigationElement instanceof PsiFile ? -1 : navigationElement.getTextOffset();
VirtualFile virtualFile = PsiUtilCore.getVirtualFile(psiElement);
if (virtualFile != null && virtualFile.isValid()) {
new OpenFileDescriptor(navigationElement.getProject(), virtualFile, offset).navigate(true);
} else if (navigationElement instanceof Navigatable) {
((Navigatable) navigationElement).navigate(true);
}
}
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class LazyEditor method getEditor.
private Editor getEditor() {
if (myEditor == null) {
final Project project = myFile.getProject();
myEditor = FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, myFile.getVirtualFile(), 0), false);
assert myEditor != null;
}
return myEditor;
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class InspectionResultsView method getSelectedNavigatable.
@Nullable
private Navigatable getSelectedNavigatable(final CommonProblemDescriptor descriptor, final PsiElement psiElement) {
if (descriptor instanceof ProblemDescriptorBase) {
Navigatable navigatable = ((ProblemDescriptorBase) descriptor).getNavigatable();
if (navigatable != null) {
return navigatable;
}
}
if (psiElement == null || !psiElement.isValid())
return null;
PsiFile containingFile = psiElement.getContainingFile();
VirtualFile virtualFile = containingFile == null ? null : containingFile.getVirtualFile();
if (virtualFile != null) {
int startOffset = psiElement.getTextOffset();
if (descriptor instanceof ProblemDescriptorBase) {
final TextRange textRange = ((ProblemDescriptorBase) descriptor).getTextRangeForNavigation();
if (textRange != null) {
if (virtualFile instanceof VirtualFileWindow) {
virtualFile = ((VirtualFileWindow) virtualFile).getDelegate();
}
startOffset = textRange.getStartOffset();
}
}
return new OpenFileDescriptor(myProject, virtualFile, startOffset);
}
return null;
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class InspectionResultsViewUtil method getNavigatableForInvalidNode.
@Nullable
static Navigatable getNavigatableForInvalidNode(ProblemDescriptionNode node) {
RefEntity element = node.getElement();
while (element != null && !element.isValid()) {
element = element.getOwner();
}
if (!(element instanceof RefElement))
return null;
PsiElement containingElement = ((RefElement) element).getElement();
if (!(containingElement instanceof NavigatablePsiElement) || !containingElement.isValid())
return null;
final int lineNumber = node.getLineNumber();
if (lineNumber != -1) {
final PsiFile containingFile = containingElement.getContainingFile();
if (containingFile != null) {
final VirtualFile file = containingFile.getVirtualFile();
final Document document = FileDocumentManager.getInstance().getDocument(file);
if (document != null && document.getLineCount() > lineNumber) {
return new OpenFileDescriptor(containingElement.getProject(), file, lineNumber, 0);
}
}
}
return (Navigatable) containingElement;
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class GotoClassAction method gotoActionPerformed.
@Override
public void gotoActionPerformed(@NotNull AnActionEvent e) {
final Project project = e.getProject();
if (project == null)
return;
FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.popup.class");
PsiDocumentManager.getInstance(project).commitAllDocuments();
final GotoClassModel2 model = new GotoClassModel2(project);
showNavigationPopup(e, model, new GotoActionCallback<Language>() {
@Override
protected ChooseByNameFilter<Language> createFilter(@NotNull ChooseByNamePopup popup) {
return new ChooseByNameLanguageFilter(popup, model, GotoClassSymbolConfiguration.getInstance(project), project);
}
@Override
public void elementChosen(ChooseByNamePopup popup, Object element) {
ApplicationManager.getApplication().runReadAction(() -> {
if (element instanceof PsiElement && ((PsiElement) element).isValid()) {
PsiElement psiElement = getElement(((PsiElement) element), popup);
psiElement = psiElement.getNavigationElement();
VirtualFile file = PsiUtilCore.getVirtualFile(psiElement);
if (file != null && popup.getLinePosition() != -1) {
OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file, popup.getLinePosition(), popup.getColumnPosition());
Navigatable n = descriptor.setUseCurrentWindow(popup.isOpenInCurrentWindowRequested());
if (n.canNavigate()) {
n.navigate(true);
return;
}
}
if (file != null && popup.getMemberPattern() != null) {
NavigationUtil.activateFileWithPsiElement(psiElement, !popup.isOpenInCurrentWindowRequested());
Navigatable member = findMember(popup.getMemberPattern(), psiElement, file);
if (member != null) {
member.navigate(true);
}
}
NavigationUtil.activateFileWithPsiElement(psiElement, !popup.isOpenInCurrentWindowRequested());
} else {
EditSourceUtil.navigate(((NavigationItem) element), true, popup.isOpenInCurrentWindowRequested());
}
});
}
}, IdeBundle.message("go.to.class.toolwindow.title"), true);
}
Aggregations