Search in sources :

Example 71 with OpenFileDescriptor

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

the class CaptureService method notifyCaptureReady.

/**
   * Notifies listeners of the {@link Capture} being ready, and opens the file with the appropriate editor.
   *
   * @param capture the {@link Capture} to notify listeners of and to open
   */
public void notifyCaptureReady(@NotNull final Capture capture) {
    for (CaptureListener listener : myListeners) {
        listener.onReady(capture);
    }
    OpenFileDescriptor descriptor = new OpenFileDescriptor(myProject, capture.getFile());
    FileEditorManager.getInstance(myProject).openEditor(descriptor, true);
}
Also used : OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor)

Example 72 with OpenFileDescriptor

use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project completable-reactor by ru-fix.

the class EditorPanelFactory method create.

public static JFXPanel create(Project project, String graphModel) {
    JFXPanel swingFxPanel = new JFXPanel();
    GraphViewer graphViewer = new GraphViewer();
    graphViewer.setShortcut(ShortcutType.GOTO_SERIALIZATION_POINT, new Shortcut(true, KeyCode.B));
    graphViewer.registerListener(new GraphViewer.ActionListener() {

        @Override
        public void goToSource(@NotNull ReactorGraphModel.Source source) {
            ApplicationManager.getApplication().invokeLater(() -> ApplicationManager.getApplication().runReadAction(() -> {
                PsiFile foundFile = null;
                if (source.fileName != null) {
                    foundFile = Arrays.stream(PsiShortNamesCache.getInstance(project).getFilesByName(source.fileName)).findAny().orElse(null);
                } else if (source.className != null) {
                    ProjectAndLibrariesScope searchScope = new ProjectAndLibrariesScope(project);
                    PsiClass payloadPsiClass = JavaPsiFacade.getInstance(project).findClass(source.className, searchScope);
                    if (payloadPsiClass != null) {
                        foundFile = payloadPsiClass.getContainingFile();
                    }
                }
                if (foundFile == null) {
                    log.warn("Can not find file for source: " + source);
                    return;
                }
                OpenFileDescriptor descriptor = new OpenFileDescriptor(project, foundFile.getVirtualFile(), source.fileNameLine != null ? source.fileNameLine - 1 : 0, 0);
                descriptor.navigate(true);
            }));
        }

        @Override
        public void goToSubgraph(String subgraphPayloadClass) {
            ApplicationManager.getApplication().invokeLater(() -> ApplicationManager.getApplication().runReadAction(() -> {
                PsiFile foundFile = null;
                if (subgraphPayloadClass != null) {
                    foundFile = Arrays.stream(PsiShortNamesCache.getInstance(project).getFilesByName(subgraphPayloadClass + ".rg")).findAny().orElse(null);
                }
                if (foundFile == null) {
                    log.warn("Can not find file for subgraph: " + subgraphPayloadClass);
                    return;
                }
                OpenFileDescriptor descriptor = new OpenFileDescriptor(project, foundFile.getVirtualFile());
                descriptor.navigate(true);
            }));
        }

        @Override
        public void coordinatesChanged(List<GraphViewer.CoordinateItem> coordinateItems) {
            ReactorGraphModel graphModel = graphViewer.getGraphModel();
            final ReactorGraphModel.Source codeBlockFrom = graphModel.coordinatesSource;
            if (codeBlockFrom == null) {
                log.warn("Coordinates source start location not specified in model.");
                return;
            }
            ApplicationManager.getApplication().invokeLater(() -> {
                ApplicationManager.getApplication().runReadAction(() -> {
                    PsiFile[] foundFiles = PsiShortNamesCache.getInstance(project).getFilesByName(codeBlockFrom.fileName);
                    if (foundFiles.length == 0) {
                        log.warn("No file with name " + codeBlockFrom.fileName + " found");
                        return;
                    }
                    if (foundFiles.length > 1) {
                        log.warn("Found more than one file with name " + codeBlockFrom.fileName);
                    }
                    PsiFile foundFile = foundFiles[0];
                    Document document = PsiDocumentManager.getInstance(project).getDocument(foundFile);
                    TextRange textRange = new TextRange(document.getLineStartOffset(codeBlockFrom.fileNameLine - 1), document.getLineEndOffset(document.getLineCount() - 1));
                    String codeBlock = document.getText(textRange);
                    String newCodeBlock = codeUpdater.updateCoordinates(codeBlock, coordinateItems);
                    WriteCommandAction.runWriteCommandAction(project, () -> document.replaceString(textRange.getStartOffset(), textRange.getEndOffset(), newCodeBlock));
                });
            });
        }
    });
    // Because of https://bugs.openjdk.java.net/browse/JDK-8090517, it is important to disable implicit exit.
    Platform.setImplicitExit(false);
    Platform.runLater(() -> {
        try {
            graphViewer.openGraph(graphModel);
            swingFxPanel.setScene(graphViewer.getScene());
        } catch (Exception exc) {
            log.error("Failed to open graph.", exc);
        }
    });
    return swingFxPanel;
}
Also used : JFXPanel(javafx.embed.swing.JFXPanel) PsiClass(com.intellij.psi.PsiClass) TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) GraphViewer(ru.fix.completable.reactor.graph.viewer.GraphViewer) ProjectAndLibrariesScope(com.intellij.psi.search.ProjectAndLibrariesScope) Shortcut(ru.fix.completable.reactor.graph.viewer.Shortcut) ReactorGraphModel(ru.fix.completable.reactor.api.ReactorGraphModel) PsiFile(com.intellij.psi.PsiFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor)

Example 73 with OpenFileDescriptor

use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project sonarlint-intellij by SonarSource.

the class IssueTree method navigate.

@CheckForNull
private OpenFileDescriptor navigate() {
    DefaultMutableTreeNode node = getSelectedNode();
    if (!(node instanceof IssueNode)) {
        return null;
    }
    LiveIssue issue = ((IssueNode) node).issue();
    if (!issue.isValid()) {
        return null;
    }
    int offset;
    RangeMarker range = issue.getRange();
    if (range != null) {
        offset = range.getStartOffset();
    } else {
        offset = 0;
    }
    return new OpenFileDescriptor(project, issue.psiFile().getVirtualFile(), offset);
}
Also used : LiveIssue(org.sonarlint.intellij.issue.LiveIssue) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) IssueNode(org.sonarlint.intellij.ui.nodes.IssueNode) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) RangeMarker(com.intellij.openapi.editor.RangeMarker) CheckForNull(javax.annotation.CheckForNull)

Example 74 with OpenFileDescriptor

use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project sonarlint-intellij by SonarSource.

the class FlowsTree method navigateToSelected.

private void navigateToSelected() {
    DefaultMutableTreeNode node = getSelectedNode();
    if (!(node instanceof LocationNode)) {
        return;
    }
    RangeMarker rangeMarker = ((LocationNode) node).rangeMarker();
    if (rangeMarker == null || !rangeMarker.isValid()) {
        return;
    }
    PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(rangeMarker.getDocument());
    if (psiFile != null) {
        new OpenFileDescriptor(project, psiFile.getVirtualFile(), rangeMarker.getStartOffset()).navigate(false);
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) LocationNode(org.sonarlint.intellij.ui.nodes.LocationNode) PsiFile(com.intellij.psi.PsiFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) RangeMarker(com.intellij.openapi.editor.RangeMarker)

Example 75 with OpenFileDescriptor

use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project sonarlint-intellij by SonarSource.

the class AbstractIssuesPanel method occurrence.

@CheckForNull
private OccurenceNavigator.OccurenceInfo occurrence(@Nullable IssueNode node) {
    if (node == null) {
        return null;
    }
    TreePath path = new TreePath(node.getPath());
    tree.getSelectionModel().setSelectionPath(path);
    tree.scrollPathToVisible(path);
    RangeMarker range = node.issue().getRange();
    int startOffset = (range != null) ? range.getStartOffset() : 0;
    return new OccurenceNavigator.OccurenceInfo(new OpenFileDescriptor(project, node.issue().psiFile().getVirtualFile(), startOffset), -1, -1);
}
Also used : TreePath(javax.swing.tree.TreePath) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) RangeMarker(com.intellij.openapi.editor.RangeMarker) CheckForNull(javax.annotation.CheckForNull)

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