Search in sources :

Example 86 with FileEditor

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

the class DaemonCodeAnalyzerImpl method addFileLevelHighlight.

@Override
public void addFileLevelHighlight(@NotNull final Project project, final int group, @NotNull final HighlightInfo info, @NotNull final PsiFile psiFile) {
    VirtualFile vFile = psiFile.getViewProvider().getVirtualFile();
    final FileEditorManager manager = FileEditorManager.getInstance(project);
    for (FileEditor fileEditor : manager.getEditors(vFile)) {
        if (fileEditor instanceof TextEditor) {
            FileLevelIntentionComponent component = new FileLevelIntentionComponent(info.getDescription(), info.getSeverity(), info.getGutterIconRenderer(), info.quickFixActionRanges, project, psiFile, ((TextEditor) fileEditor).getEditor(), info.getToolTip());
            manager.addTopComponent(fileEditor, component);
            List<HighlightInfo> fileLevelInfos = fileEditor.getUserData(FILE_LEVEL_HIGHLIGHTS);
            if (fileLevelInfos == null) {
                fileLevelInfos = new ArrayList<>();
                fileEditor.putUserData(FILE_LEVEL_HIGHLIGHTS, fileLevelInfos);
            }
            info.fileLevelComponent = component;
            info.setGroup(group);
            fileLevelInfos.add(info);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) FileLevelIntentionComponent(com.intellij.codeInsight.intention.impl.FileLevelIntentionComponent)

Example 87 with FileEditor

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

the class DaemonCodeAnalyzerImpl method getSelectedEditors.

@NotNull
private Collection<FileEditor> getSelectedEditors() {
    ApplicationManager.getApplication().assertIsDispatchThread();
    // Editors in modal context
    List<Editor> editors = getActiveEditors();
    Collection<FileEditor> activeTextEditors = new THashSet<>(editors.size());
    for (Editor editor : editors) {
        if (editor.isDisposed())
            continue;
        TextEditor textEditor = TextEditorProvider.getInstance().getTextEditor(editor);
        activeTextEditors.add(textEditor);
    }
    if (ApplicationManager.getApplication().getCurrentModalityState() != ModalityState.NON_MODAL) {
        return activeTextEditors;
    }
    // Editors in tabs.
    Collection<FileEditor> result = new THashSet<>();
    Collection<VirtualFile> files = new THashSet<>(activeTextEditors.size());
    final FileEditor[] tabEditors = FileEditorManager.getInstance(myProject).getSelectedEditors();
    for (FileEditor tabEditor : tabEditors) {
        if (!tabEditor.isValid())
            continue;
        VirtualFile file = ((FileEditorManagerEx) FileEditorManager.getInstance(myProject)).getFile(tabEditor);
        if (file != null) {
            files.add(file);
        }
        result.add(tabEditor);
    }
    // do not duplicate documents
    for (FileEditor fileEditor : activeTextEditors) {
        VirtualFile file = ((FileEditorManagerEx) FileEditorManager.getInstance(myProject)).getFile(fileEditor);
        if (file != null && files.contains(file))
            continue;
        result.add(fileEditor);
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Editor(com.intellij.openapi.editor.Editor) THashSet(gnu.trove.THashSet) FileEditorManagerEx(com.intellij.openapi.fileEditor.ex.FileEditorManagerEx) NotNull(org.jetbrains.annotations.NotNull)

Example 88 with FileEditor

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

the class ShowUsagesAction method getEditorFor.

@Nullable
private static Editor getEditorFor(@NotNull Usage usage) {
    FileEditorLocation location = usage.getLocation();
    FileEditor newFileEditor = location == null ? null : location.getEditor();
    return newFileEditor instanceof TextEditor ? ((TextEditor) newFileEditor).getEditor() : null;
}
Also used : FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) FileEditorLocation(com.intellij.openapi.fileEditor.FileEditorLocation) Nullable(org.jetbrains.annotations.Nullable)

Example 89 with FileEditor

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

the class StructureViewUpdatingTest method testJavaClassStructure.

public void testJavaClassStructure() throws Exception {
    final PsiClass psiClass = JavaDirectoryService.getInstance().getClasses(getPackageDirectory("com/package1"))[0];
    final VirtualFile virtualFile = psiClass.getContainingFile().getVirtualFile();
    final FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
    FileEditor[] fileEditors = fileEditorManager.openFile(virtualFile, false);
    final FileEditor fileEditor = fileEditors[0];
    try {
        final StructureViewComponent structureViewComponent = (StructureViewComponent) fileEditor.getStructureViewBuilder().createStructureView(fileEditor, myProject);
        final Document document = PsiDocumentManager.getInstance(myProject).getDocument(psiClass.getContainingFile());
        structureViewComponent.setActionActive(InheritedMembersNodeProvider.ID, true);
        PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class1.java\n" + " -Class1\n" + "  getValue(): int\n" + "  getClass(): Class<? extends Object>\n" + "  hashCode(): int\n" + "  equals(Object): boolean\n" + "  clone(): Object\n" + "  toString(): String\n" + "  notify(): void\n" + "  notifyAll(): void\n" + "  wait(long): void\n" + "  wait(long, int): void\n" + "  wait(): void\n" + "  finalize(): void\n" + "  myField1: boolean\n" + "  myField2: boolean\n");
        new WriteCommandAction.Simple(getProject()) {

            @Override
            protected void run() throws Throwable {
                final int offset = document.getLineStartOffset(5);
                document.insertString(offset, "    boolean myNewField = false;\n");
            }
        }.execute().throwException();
        PsiDocumentManager.getInstance(myProject).commitDocument(document);
        PlatformTestUtil.waitForAlarm(600);
        //TreeUtil.expand(structureViewComponent.getTree(), 3);
        PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class1.java\n" + " -Class1\n" + "  getValue(): int\n" + "  getClass(): Class<? extends Object>\n" + "  hashCode(): int\n" + "  equals(Object): boolean\n" + "  clone(): Object\n" + "  toString(): String\n" + "  notify(): void\n" + "  notifyAll(): void\n" + "  wait(long): void\n" + "  wait(long, int): void\n" + "  wait(): void\n" + "  finalize(): void\n" + "  myField1: boolean\n" + "  myField2: boolean\n" + "  myNewField: boolean = false\n");
        Disposer.dispose(structureViewComponent);
    } finally {
        fileEditorManager.closeFile(virtualFile);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FileEditor(com.intellij.openapi.fileEditor.FileEditor) PsiClass(com.intellij.psi.PsiClass) StructureViewComponent(com.intellij.ide.structureView.newStructureView.StructureViewComponent) Document(com.intellij.openapi.editor.Document)

Example 90 with FileEditor

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

the class NavigationUtil method activatePsiElementIfOpen.

private static boolean activatePsiElementIfOpen(@NotNull PsiElement elt, boolean searchForOpen, boolean requestFocus) {
    if (!elt.isValid())
        return false;
    elt = elt.getNavigationElement();
    final PsiFile file = elt.getContainingFile();
    if (file == null || !file.isValid())
        return false;
    VirtualFile vFile = file.getVirtualFile();
    if (vFile == null)
        return false;
    if (!EditorHistoryManager.getInstance(elt.getProject()).hasBeenOpen(vFile))
        return false;
    final FileEditorManager fem = FileEditorManager.getInstance(elt.getProject());
    if (!fem.isFileOpen(vFile)) {
        fem.openFile(vFile, requestFocus, searchForOpen);
    }
    final TextRange range = elt.getTextRange();
    if (range == null)
        return false;
    final FileEditor[] editors = fem.getEditors(vFile);
    for (FileEditor editor : editors) {
        if (editor instanceof TextEditor) {
            final Editor text = ((TextEditor) editor).getEditor();
            final int offset = text.getCaretModel().getOffset();
            if (range.containsOffset(offset)) {
                // select the file
                fem.openFile(vFile, requestFocus, searchForOpen);
                return true;
            }
        }
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) PsiFile(com.intellij.psi.PsiFile) TextRange(com.intellij.openapi.util.TextRange) TextEditor(com.intellij.openapi.fileEditor.TextEditor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Editor(com.intellij.openapi.editor.Editor)

Aggregations

FileEditor (com.intellij.openapi.fileEditor.FileEditor)140 TextEditor (com.intellij.openapi.fileEditor.TextEditor)54 VirtualFile (com.intellij.openapi.vfs.VirtualFile)53 Editor (com.intellij.openapi.editor.Editor)41 Project (com.intellij.openapi.project.Project)34 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)27 DataContext (com.intellij.openapi.actionSystem.DataContext)20 Nullable (org.jetbrains.annotations.Nullable)19 PsiFile (com.intellij.psi.PsiFile)16 Document (com.intellij.openapi.editor.Document)14 IpnbFileEditor (org.jetbrains.plugins.ipnb.editor.IpnbFileEditor)14 NotNull (org.jetbrains.annotations.NotNull)13 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)9 IpnbFilePanel (org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel)8 StructureViewBuilder (com.intellij.ide.structureView.StructureViewBuilder)6 StructureViewComponent (com.intellij.ide.structureView.newStructureView.StructureViewComponent)6 StructureViewComposite (com.intellij.ide.structureView.impl.StructureViewComposite)5 FileEditorManagerEx (com.intellij.openapi.fileEditor.ex.FileEditorManagerEx)5 PsiElement (com.intellij.psi.PsiElement)5 List (java.util.List)5