Search in sources :

Example 51 with OpenFileDescriptor

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

the class NavigatableRule method getData.

@Override
public Object getData(DataProvider dataProvider) {
    final Navigatable navigatable = CommonDataKeys.NAVIGATABLE.getData(dataProvider);
    if (navigatable != null && navigatable instanceof OpenFileDescriptor) {
        final OpenFileDescriptor openFileDescriptor = (OpenFileDescriptor) navigatable;
        if (openFileDescriptor.getFile().isValid()) {
            return openFileDescriptor;
        }
    }
    final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataProvider);
    if (element instanceof Navigatable) {
        return element;
    }
    if (element != null) {
        return EditSourceUtil.getDescriptor(element);
    }
    final Object selection = PlatformDataKeys.SELECTED_ITEM.getData(dataProvider);
    if (selection instanceof Navigatable) {
        return selection;
    }
    return null;
}
Also used : OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) PsiElement(com.intellij.psi.PsiElement) Navigatable(com.intellij.pom.Navigatable)

Example 52 with OpenFileDescriptor

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

the class PackageDependenciesNode method getDescriptor.

@Nullable
private OpenFileDescriptor getDescriptor() {
    if (getProject() == null)
        return null;
    final PsiElement psiElement = getPsiElement();
    if (psiElement == null)
        return null;
    final VirtualFile virtualFile = psiElement.getContainingFile().getVirtualFile();
    if (virtualFile == null || !virtualFile.isValid())
        return null;
    return new OpenFileDescriptor(getProject(), virtualFile, psiElement.getTextOffset());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 53 with OpenFileDescriptor

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

the class EditSourceUtil method getDescriptor.

@Nullable
public static Navigatable getDescriptor(@NotNull PsiElement element) {
    PsiElement original = getNavigatableOriginalElement(element);
    if (original != null) {
        element = original;
    } else if (!canNavigate(element)) {
        return null;
    }
    if (element instanceof PomTargetPsiElement) {
        return ((PomTargetPsiElement) element).getTarget();
    }
    final PsiElement navigationElement = element.getNavigationElement();
    if (navigationElement instanceof PomTargetPsiElement) {
        return ((PomTargetPsiElement) navigationElement).getTarget();
    }
    final int offset = navigationElement instanceof PsiFile ? -1 : navigationElement.getTextOffset();
    final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(navigationElement);
    if (virtualFile == null || !virtualFile.isValid()) {
        return null;
    }
    OpenFileDescriptor desc = new OpenFileDescriptor(navigationElement.getProject(), virtualFile, offset);
    desc.setUseCurrentWindow(FileEditorManager.USE_CURRENT_WINDOW.isIn(navigationElement));
    return desc;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 54 with OpenFileDescriptor

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

the class ConsoleViewImpl method getData.

@Override
public Object getData(final String dataId) {
    if (CommonDataKeys.NAVIGATABLE.is(dataId)) {
        if (myEditor == null) {
            return null;
        }
        final LogicalPosition pos = myEditor.getCaretModel().getLogicalPosition();
        final HyperlinkInfo info = myHyperlinks.getHyperlinkInfoByLineAndCol(pos.line, pos.column);
        final OpenFileDescriptor openFileDescriptor = info instanceof FileHyperlinkInfo ? ((FileHyperlinkInfo) info).getDescriptor() : null;
        if (openFileDescriptor == null || !openFileDescriptor.getFile().isValid()) {
            return null;
        }
        return openFileDescriptor;
    }
    if (CommonDataKeys.EDITOR.is(dataId)) {
        return myEditor;
    }
    if (PlatformDataKeys.HELP_ID.is(dataId)) {
        return myHelpId;
    }
    if (LangDataKeys.CONSOLE_VIEW.is(dataId)) {
        return this;
    }
    return null;
}
Also used : OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor)

Example 55 with OpenFileDescriptor

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

the class CodeInsightUtil method positionCursor.

public static Editor positionCursor(final Project project, PsiFile targetFile, @NotNull PsiElement element) {
    TextRange range = element.getTextRange();
    LOG.assertTrue(range != null, "element: " + element + "; valid: " + element.isValid());
    int textOffset = range.getStartOffset();
    OpenFileDescriptor descriptor = new OpenFileDescriptor(project, targetFile.getVirtualFile(), textOffset);
    return FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
}
Also used : TextRange(com.intellij.openapi.util.TextRange) 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