Search in sources :

Example 41 with OpenFileDescriptor

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);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) PsiElement(com.intellij.psi.PsiElement) Navigatable(com.intellij.pom.Navigatable)

Example 42 with OpenFileDescriptor

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;
}
Also used : Project(com.intellij.openapi.project.Project) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor)

Example 43 with OpenFileDescriptor

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileWindow(com.intellij.injected.editor.VirtualFileWindow) TextRange(com.intellij.openapi.util.TextRange) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) Navigatable(com.intellij.pom.Navigatable) Nullable(org.jetbrains.annotations.Nullable)

Example 44 with OpenFileDescriptor

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;
}
Also used : RefElement(com.intellij.codeInspection.reference.RefElement) VirtualFile(com.intellij.openapi.vfs.VirtualFile) RefEntity(com.intellij.codeInspection.reference.RefEntity) PsiFile(com.intellij.psi.PsiFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) Document(com.intellij.openapi.editor.Document) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement) PsiElement(com.intellij.psi.PsiElement) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement) Navigatable(com.intellij.pom.Navigatable) Nullable(org.jetbrains.annotations.Nullable)

Example 45 with OpenFileDescriptor

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Navigatable(com.intellij.pom.Navigatable) Project(com.intellij.openapi.project.Project) Language(com.intellij.lang.Language) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) PsiElement(com.intellij.psi.PsiElement)

Aggregations

OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)155 VirtualFile (com.intellij.openapi.vfs.VirtualFile)97 Project (com.intellij.openapi.project.Project)40 Editor (com.intellij.openapi.editor.Editor)30 PsiElement (com.intellij.psi.PsiElement)27 PsiFile (com.intellij.psi.PsiFile)21 Navigatable (com.intellij.pom.Navigatable)19 Nullable (org.jetbrains.annotations.Nullable)18 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)10 Document (com.intellij.openapi.editor.Document)9 FileEditor (com.intellij.openapi.fileEditor.FileEditor)9 TextRange (com.intellij.openapi.util.TextRange)9 IncorrectOperationException (com.intellij.util.IncorrectOperationException)9 File (java.io.File)9 Result (com.intellij.openapi.application.Result)8 EditorImpl (com.intellij.openapi.editor.impl.EditorImpl)8 NotNull (org.jetbrains.annotations.NotNull)6 TemplateBuilder (com.intellij.codeInsight.template.TemplateBuilder)5 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)5 XmlTag (com.intellij.psi.xml.XmlTag)5