Search in sources :

Example 86 with OpenFileDescriptor

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

the class GoToBuckFile method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getProject();
    if (project == null) {
        return;
    }
    Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
    if (editor == null) {
        return;
    }
    final Document document = editor.getDocument();
    if (document == null) {
        return;
    }
    VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(document);
    final VirtualFile file = BuckFileUtil.getBuckFile(virtualFile);
    if (file != null) {
        final OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file);
        // This is for better cursor position.
        final Navigatable n = descriptor.setUseCurrentWindow(false);
        if (!n.canNavigate()) {
            return;
        }
        n.navigate(true);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) Editor(com.intellij.openapi.editor.Editor) Document(com.intellij.openapi.editor.Document) Navigatable(com.intellij.pom.Navigatable)

Example 87 with OpenFileDescriptor

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

the class ProblemsView method addMessage.

public final void addMessage(CompilerMessage message, @NotNull UUID sessionId) {
    final VirtualFile file = message.getVirtualFile();
    Navigatable navigatable = message.getNavigatable();
    if (navigatable == null && file != null) {
        navigatable = new OpenFileDescriptor(myProject, file, -1, -1);
    }
    final CompilerMessageCategory category = message.getCategory();
    final int type = CompilerTask.translateCategory(category);
    final String[] text = convertMessage(message);
    final String groupName = file != null ? file.getPresentableUrl() : category.getPresentableText();
    addMessage(type, text, groupName, navigatable, message.getExportTextPrefix(), message.getRenderTextPrefix(), sessionId);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CompilerMessageCategory(com.intellij.openapi.compiler.CompilerMessageCategory) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) Navigatable(com.intellij.pom.Navigatable)

Example 88 with OpenFileDescriptor

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

the class ExcludeFromValidationAction method getExcludedConfigurationAndFile.

@Nullable
private static Pair<ExcludesConfiguration, VirtualFile> getExcludedConfigurationAndFile(final AnActionEvent event, Project project) {
    Navigatable navigatable = event.getData(CommonDataKeys.NAVIGATABLE);
    if (project != null && navigatable instanceof OpenFileDescriptor) {
        final VirtualFile file = ((OpenFileDescriptor) navigatable).getFile();
        final ExcludesConfiguration configuration = ValidationConfiguration.getExcludedEntriesConfiguration(project);
        return Pair.create(configuration, file);
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ExcludesConfiguration(com.intellij.openapi.compiler.options.ExcludesConfiguration) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) Navigatable(com.intellij.pom.Navigatable) Nullable(org.jetbrains.annotations.Nullable)

Example 89 with OpenFileDescriptor

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

the class AndroidManifestsGroupNode method navigate.

@Override
public void navigate(boolean requestFocus) {
    VirtualFile fileToOpen = findFileToOpen(mySources);
    if (fileToOpen == null) {
        return;
    }
    new OpenFileDescriptor(myProject, fileToOpen).navigate(requestFocus);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor)

Example 90 with OpenFileDescriptor

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

the class GutterIconRenderer method getClickAction.

@Nullable
@Override
public AnAction getClickAction() {
    return new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
            if (editor != null) {
                Project project = editor.getProject();
                VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByIoFile(myFile);
                if (project != null && virtualFile != null) {
                    OpenFileDescriptor descriptor = new OpenFileDescriptor(project, virtualFile, -1);
                    FileEditorManager.getInstance(project).openEditor(descriptor, true);
                }
            }
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Editor(com.intellij.openapi.editor.Editor) AnAction(com.intellij.openapi.actionSystem.AnAction) Nullable(org.jetbrains.annotations.Nullable)

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