Search in sources :

Example 46 with TextEditor

use of com.intellij.openapi.fileEditor.TextEditor 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 47 with TextEditor

use of com.intellij.openapi.fileEditor.TextEditor 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 48 with TextEditor

use of com.intellij.openapi.fileEditor.TextEditor 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 49 with TextEditor

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

the class ProxyUndoRedoAction method register.

public static void register(@Nullable Project project, @NotNull Editor editor, @NotNull JComponent component) {
    UndoManager undoManager = project != null ? UndoManager.getInstance(project) : UndoManager.getGlobalInstance();
    TextEditor textEditor = TextEditorProvider.getInstance().getTextEditor(editor);
    if (undoManager != null) {
        DiffUtil.registerAction(new ProxyUndoRedoAction(undoManager, textEditor, true), component);
        DiffUtil.registerAction(new ProxyUndoRedoAction(undoManager, textEditor, false), component);
    }
}
Also used : TextEditor(com.intellij.openapi.fileEditor.TextEditor) UndoManager(com.intellij.openapi.command.undo.UndoManager)

Example 50 with TextEditor

use of com.intellij.openapi.fileEditor.TextEditor 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

TextEditor (com.intellij.openapi.fileEditor.TextEditor)75 FileEditor (com.intellij.openapi.fileEditor.FileEditor)52 Editor (com.intellij.openapi.editor.Editor)29 VirtualFile (com.intellij.openapi.vfs.VirtualFile)23 Project (com.intellij.openapi.project.Project)20 Document (com.intellij.openapi.editor.Document)13 Nullable (org.jetbrains.annotations.Nullable)12 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)11 PsiFile (com.intellij.psi.PsiFile)8 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)6 NotNull (org.jetbrains.annotations.NotNull)6 Disposable (com.intellij.openapi.Disposable)3 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)3 EditorNotificationPanel (com.intellij.ui.EditorNotificationPanel)3 LightweightHint (com.intellij.ui.LightweightHint)3 NonNls (org.jetbrains.annotations.NonNls)3 HighlightingPass (com.intellij.codeHighlighting.HighlightingPass)2 TextEditorHighlightingPass (com.intellij.codeHighlighting.TextEditorHighlightingPass)2 TemplateBuilder (com.intellij.codeInsight.template.TemplateBuilder)2 UndoManager (com.intellij.openapi.command.undo.UndoManager)2