Search in sources :

Example 1 with OpenFileDescriptor

use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project buck by facebook.

the class BuckToolWindowFactory method handleClickOnError.

private void handleClickOnError(BuckTreeNodeDetailError node) {
    TreeNode parentNode = node.getParent();
    if (parentNode instanceof BuckTreeNodeFileError) {
        BuckTreeNodeFileError buckParentNode = (BuckTreeNodeFileError) parentNode;
        DataContext dataContext = DataManager.getInstance().getDataContext();
        Project project = DataKeys.PROJECT.getData(dataContext);
        String relativePath = buckParentNode.getFilePath().replace(project.getBasePath(), "");
        VirtualFile virtualFile = project.getBaseDir().findFileByRelativePath(relativePath);
        OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor(project, virtualFile, node.getLine() - 1, node.getColumn() - 1);
        openFileDescriptor.navigate(true);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) TreeNode(javax.swing.tree.TreeNode) BuckTreeNodeFileError(com.facebook.buck.intellij.ideabuck.ui.tree.BuckTreeNodeFileError) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor)

Example 2 with OpenFileDescriptor

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

the class XsltDebuggerSession method openLocation.

@Nullable
public static Editor openLocation(Project project, @NotNull String uri, int lineNumber) {
    try {
        final VirtualFile file = VfsUtil.findFileByURL(new URI(uri).toURL());
        final OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file, lineNumber, 0);
        descriptor.navigate(true);
        return FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
    } catch (MalformedURLException | URISyntaxException e) {
        //To change body of catch statement use File | Settings | File Templates.
        e.printStackTrace();
        return null;
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MalformedURLException(java.net.MalformedURLException) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with OpenFileDescriptor

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

the class PyiRelatedItemLineMarkerProvider method createLineMarkerInfo.

@NotNull
private static RelatedItemLineMarkerInfo<PsiElement> createLineMarkerInfo(@NotNull PsiElement element, @NotNull PsiElement relatedElement, @NotNull String itemTitle) {
    final SmartPointerManager pointerManager = SmartPointerManager.getInstance(element.getProject());
    final SmartPsiElementPointer<PsiElement> relatedElementPointer = pointerManager.createSmartPsiElementPointer(relatedElement);
    final String stubFileName = relatedElement.getContainingFile().getName();
    return new RelatedItemLineMarkerInfo<>(element, element.getTextRange(), ICON, Pass.LINE_MARKERS, element1 -> itemTitle + " in " + stubFileName, new GutterIconNavigationHandler<PsiElement>() {

        @Override
        public void navigate(MouseEvent e, PsiElement elt) {
            final PsiElement restoredRelatedElement = relatedElementPointer.getElement();
            if (restoredRelatedElement == null) {
                return;
            }
            final int offset = restoredRelatedElement instanceof PsiFile ? -1 : restoredRelatedElement.getTextOffset();
            final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(restoredRelatedElement);
            if (virtualFile != null && virtualFile.isValid()) {
                new OpenFileDescriptor(restoredRelatedElement.getProject(), virtualFile, offset).navigate(true);
            }
        }
    }, GutterIconRenderer.Alignment.RIGHT, GotoRelatedItem.createItems(Collections.singletonList(relatedElement)));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SmartPointerManager(com.intellij.psi.SmartPointerManager) MouseEvent(java.awt.event.MouseEvent) RelatedItemLineMarkerInfo(com.intellij.codeInsight.daemon.RelatedItemLineMarkerInfo) PsiFile(com.intellij.psi.PsiFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with OpenFileDescriptor

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

the class CreateLocalVariableFromUsageFix method positionCursor.

@Nullable
protected static Editor positionCursor(Project project, PsiFile targetFile, PsiElement element) {
    TextRange range = element.getTextRange();
    int textOffset = range.getStartOffset();
    VirtualFile vFile = targetFile.getVirtualFile();
    assert vFile != null;
    OpenFileDescriptor descriptor = new OpenFileDescriptor(project, vFile, textOffset);
    return FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TextRange(com.intellij.openapi.util.TextRange) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) TypeConstraint(org.jetbrains.plugins.groovy.lang.psi.expectedTypes.TypeConstraint) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with OpenFileDescriptor

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

the class MavenOpenOrCreateFilesAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    final Project project = MavenActionUtil.getProject(e.getDataContext());
    if (project == null)
        return;
    final List<File> files = getFiles(e);
    final List<VirtualFile> virtualFiles = collectVirtualFiles(files);
    if (files.size() == 1 && virtualFiles.isEmpty()) {
        new WriteCommandAction(project, e.getPresentation().getText()) {

            @Override
            protected void run(@NotNull Result result) throws Throwable {
                File file = files.get(0);
                try {
                    final VirtualFile virtualFile = VfsUtil.createDirectoryIfMissing(file.getParent());
                    if (virtualFile != null) {
                        VirtualFile newFile = virtualFile.createChildData(this, file.getName());
                        virtualFiles.add(newFile);
                        MavenUtil.runFileTemplate(project, newFile, getFileTemplate());
                    }
                } catch (IOException ex) {
                    MavenUtil.showError(project, "Cannot create " + file.getName(), ex);
                }
            }
        }.execute();
        return;
    }
    for (VirtualFile each : virtualFiles) {
        new OpenFileDescriptor(project, each).navigate(true);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Project(com.intellij.openapi.project.Project) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Result(com.intellij.openapi.application.Result)

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