Search in sources :

Example 56 with OpenFileDescriptor

use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.

the class JavaGotoSuperHandler method invoke.

@Override
public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile file) {
    FeatureUsageTracker.getInstance().triggerFeatureUsed(GotoSuperAction.FEATURE_ID);
    int offset = editor.getCaretModel().getOffset();
    PsiElement[] superElements = findSuperElements(file, offset);
    if (superElements.length == 0)
        return;
    if (superElements.length == 1) {
        PsiElement superElement = superElements[0].getNavigationElement();
        final PsiFile containingFile = superElement.getContainingFile();
        if (containingFile == null)
            return;
        final VirtualFile virtualFile = containingFile.getVirtualFile();
        if (virtualFile == null)
            return;
        OpenFileDescriptor descriptor = new OpenFileDescriptor(project, virtualFile, superElement.getTextOffset());
        FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
    } else if (superElements[0] instanceof PsiMethod) {
        boolean showMethodNames = !PsiUtil.allMethodsHaveSameSignature((PsiMethod[]) superElements);
        PsiElementListNavigator.openTargets(editor, (PsiMethod[]) superElements, CodeInsightBundle.message("goto.super.method.chooser.title"), CodeInsightBundle.message("goto.super.method.findUsages.title", ((PsiMethod) superElements[0]).getName()), new MethodCellRenderer(showMethodNames));
    } else {
        NavigationUtil.getPsiElementPopup(superElements, CodeInsightBundle.message("goto.super.class.chooser.title")).showInBestPositionFor(editor);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) MethodCellRenderer(com.intellij.ide.util.MethodCellRenderer)

Example 57 with OpenFileDescriptor

use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.

the class DuplicatesImpl method invoke.

public static void invoke(final Project project, final MatchProvider provider) {
    final List<Match> duplicates = provider.getDuplicates();
    int idx = 0;
    final Ref<Boolean> showAll = new Ref<>();
    final String confirmDuplicatePrompt = getConfirmationPrompt(provider, duplicates);
    for (final Match match : duplicates) {
        final PsiFile file = match.getFile();
        final VirtualFile virtualFile = file.getVirtualFile();
        if (virtualFile == null || !virtualFile.isValid())
            return;
        if (!CommonRefactoringUtil.checkReadOnlyStatus(project, file))
            return;
        final Editor editor = FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, virtualFile), false);
        LOG.assertTrue(editor != null);
        if (!match.getMatchStart().isValid() || !match.getMatchEnd().isValid())
            continue;
        if (replaceMatch(project, provider, match, editor, ++idx, duplicates.size(), showAll, confirmDuplicatePrompt, false))
            return;
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Ref(com.intellij.openapi.util.Ref) PsiFile(com.intellij.psi.PsiFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) Editor(com.intellij.openapi.editor.Editor)

Example 58 with OpenFileDescriptor

use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.

the class InjectedLanguageUtil method openEditorFor.

public static Editor openEditorFor(@NotNull PsiFile file, @NotNull Project project) {
    Document document = PsiDocumentManager.getInstance(project).getDocument(file);
    // may return editor injected in current selection in the host editor, not for the file passed as argument
    VirtualFile virtualFile = file.getVirtualFile();
    if (virtualFile == null) {
        return null;
    }
    if (virtualFile instanceof VirtualFileWindow) {
        virtualFile = ((VirtualFileWindow) virtualFile).getDelegate();
    }
    Editor editor = FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, virtualFile, -1), false);
    if (editor == null || editor instanceof EditorWindow || editor.isDisposed())
        return editor;
    if (document instanceof DocumentWindowImpl) {
        return EditorWindowImpl.create((DocumentWindowImpl) document, (EditorImpl) editor, file);
    }
    return editor;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) Document(com.intellij.openapi.editor.Document) Editor(com.intellij.openapi.editor.Editor)

Example 59 with OpenFileDescriptor

use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.

the class AnnotateStackTraceAction method getHyperlinkVirtualFile.

@Nullable
@CalledWithReadLock
private static VirtualFile getHyperlinkVirtualFile(@NotNull List<RangeHighlighter> links) {
    RangeHighlighter key = ContainerUtil.getLastItem(links);
    if (key == null)
        return null;
    HyperlinkInfo info = EditorHyperlinkSupport.getHyperlinkInfo(key);
    if (!(info instanceof FileHyperlinkInfo))
        return null;
    OpenFileDescriptor descriptor = ((FileHyperlinkInfo) info).getDescriptor();
    return descriptor != null ? descriptor.getFile() : null;
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) FileHyperlinkInfo(com.intellij.execution.filters.FileHyperlinkInfo) FileHyperlinkInfo(com.intellij.execution.filters.FileHyperlinkInfo) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo) CalledWithReadLock(org.jetbrains.annotations.CalledWithReadLock) Nullable(org.jetbrains.annotations.Nullable)

Example 60 with OpenFileDescriptor

use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.

the class UsageViewUtil method navigateTo.

public static void navigateTo(@NotNull UsageInfo info, boolean requestFocus) {
    int offset = info.getNavigationOffset();
    VirtualFile file = info.getVirtualFile();
    Project project = info.getProject();
    if (file != null) {
        FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, file, offset), requestFocus);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor)

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