Search in sources :

Example 66 with TextEditor

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

the class CodeInsightTestCase method undo.

protected void undo() {
    UndoManager undoManager = UndoManager.getInstance(myProject);
    TextEditor textEditor = TextEditorProvider.getInstance().getTextEditor(getEditor());
    undoManager.undo(textEditor);
}
Also used : TextEditor(com.intellij.openapi.fileEditor.TextEditor) UndoManager(com.intellij.openapi.command.undo.UndoManager)

Example 67 with TextEditor

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

the class SearchBackAction method update.

@Override
public void update(AnActionEvent event) {
    Presentation presentation = event.getPresentation();
    Project project = event.getData(CommonDataKeys.PROJECT);
    if (project == null) {
        presentation.setEnabled(false);
        return;
    }
    final FileEditor editor = event.getData(PlatformDataKeys.FILE_EDITOR);
    presentation.setEnabled(editor instanceof TextEditor);
}
Also used : Project(com.intellij.openapi.project.Project) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor)

Example 68 with TextEditor

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

the class TreeBasedStructureViewBuilder method createStructureView.

@Override
@NotNull
public StructureView createStructureView(FileEditor fileEditor, @NotNull Project project) {
    final StructureViewModel model = createStructureViewModel(fileEditor instanceof TextEditor ? ((TextEditor) fileEditor).getEditor() : null);
    StructureView view = StructureViewFactory.getInstance(project).createStructureView(fileEditor, model, project, isRootNodeShown());
    Disposer.register(view, new Disposable() {

        @Override
        public void dispose() {
            model.dispose();
        }
    });
    return view;
}
Also used : Disposable(com.intellij.openapi.Disposable) TextEditor(com.intellij.openapi.fileEditor.TextEditor) NotNull(org.jetbrains.annotations.NotNull)

Example 69 with TextEditor

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

the class PassExecutorService method submitPasses.

void submitPasses(@NotNull Map<FileEditor, HighlightingPass[]> passesMap, @NotNull DaemonProgressIndicator updateProgress) {
    if (isDisposed())
        return;
    // null keys are ok
    MultiMap<Document, FileEditor> documentToEditors = MultiMap.createSet();
    MultiMap<FileEditor, TextEditorHighlightingPass> documentBoundPasses = MultiMap.createSmart();
    MultiMap<FileEditor, EditorBoundHighlightingPass> editorBoundPasses = MultiMap.createSmart();
    List<Pair<FileEditor, TextEditorHighlightingPass>> passesWithNoDocuments = new ArrayList<>();
    Set<VirtualFile> vFiles = new HashSet<>();
    for (Map.Entry<FileEditor, HighlightingPass[]> entry : passesMap.entrySet()) {
        FileEditor fileEditor = entry.getKey();
        HighlightingPass[] passes = entry.getValue();
        Document document;
        if (fileEditor instanceof TextEditor) {
            Editor editor = ((TextEditor) fileEditor).getEditor();
            LOG.assertTrue(!(editor instanceof EditorWindow));
            document = editor.getDocument();
        } else {
            VirtualFile virtualFile = ((FileEditorManagerEx) FileEditorManager.getInstance(myProject)).getFile(fileEditor);
            document = virtualFile == null ? null : FileDocumentManager.getInstance().getDocument(virtualFile);
        }
        if (document != null) {
            vFiles.add(FileDocumentManager.getInstance().getFile(document));
        }
        int prevId = 0;
        for (final HighlightingPass pass : passes) {
            if (pass instanceof EditorBoundHighlightingPass) {
                EditorBoundHighlightingPass editorPass = (EditorBoundHighlightingPass) pass;
                // have to make ids unique for this document
                editorPass.setId(nextPassId.incrementAndGet());
                editorBoundPasses.putValue(fileEditor, editorPass);
            } else {
                TextEditorHighlightingPass textEditorHighlightingPass = convertToTextHighlightingPass(pass, document, nextPassId, prevId);
                document = textEditorHighlightingPass.getDocument();
                documentBoundPasses.putValue(fileEditor, textEditorHighlightingPass);
                if (document == null) {
                    passesWithNoDocuments.add(Pair.create(fileEditor, textEditorHighlightingPass));
                } else {
                    documentToEditors.putValue(document, fileEditor);
                }
                prevId = textEditorHighlightingPass.getId();
            }
        }
    }
    List<ScheduledPass> freePasses = new ArrayList<>(documentToEditors.size() * 5);
    List<ScheduledPass> dependentPasses = new ArrayList<>(documentToEditors.size() * 10);
    // (fileEditor, passId) -> created pass
    Map<Pair<FileEditor, Integer>, ScheduledPass> toBeSubmitted = new THashMap<>(passesMap.size());
    final AtomicInteger threadsToStartCountdown = new AtomicInteger(0);
    for (Map.Entry<Document, Collection<FileEditor>> entry : documentToEditors.entrySet()) {
        Collection<FileEditor> fileEditors = entry.getValue();
        Document document = entry.getKey();
        FileEditor preferredFileEditor = getPreferredFileEditor(document, fileEditors);
        List<TextEditorHighlightingPass> passes = (List<TextEditorHighlightingPass>) documentBoundPasses.get(preferredFileEditor);
        if (passes.isEmpty()) {
            continue;
        }
        sortById(passes);
        for (TextEditorHighlightingPass currentPass : passes) {
            createScheduledPass(preferredFileEditor, currentPass, toBeSubmitted, passes, freePasses, dependentPasses, updateProgress, threadsToStartCountdown);
        }
    }
    for (Map.Entry<FileEditor, Collection<EditorBoundHighlightingPass>> entry : editorBoundPasses.entrySet()) {
        FileEditor fileEditor = entry.getKey();
        Collection<EditorBoundHighlightingPass> createdEditorBoundPasses = entry.getValue();
        List<TextEditorHighlightingPass> createdDocumentBoundPasses = (List<TextEditorHighlightingPass>) documentBoundPasses.get(fileEditor);
        List<TextEditorHighlightingPass> allCreatedPasses = new ArrayList<>(createdDocumentBoundPasses);
        allCreatedPasses.addAll(createdEditorBoundPasses);
        for (EditorBoundHighlightingPass pass : createdEditorBoundPasses) {
            createScheduledPass(fileEditor, pass, toBeSubmitted, allCreatedPasses, freePasses, dependentPasses, updateProgress, threadsToStartCountdown);
        }
    }
    for (Pair<FileEditor, TextEditorHighlightingPass> pair : passesWithNoDocuments) {
        FileEditor fileEditor = pair.first;
        TextEditorHighlightingPass pass = pair.second;
        createScheduledPass(fileEditor, pass, toBeSubmitted, ContainerUtil.emptyList(), freePasses, dependentPasses, updateProgress, threadsToStartCountdown);
    }
    if (CHECK_CONSISTENCY && !ApplicationInfoImpl.isInStressTest()) {
        assertConsistency(freePasses, toBeSubmitted, threadsToStartCountdown);
    }
    log(updateProgress, null, vFiles + " ----- starting " + threadsToStartCountdown.get(), freePasses);
    for (ScheduledPass dependentPass : dependentPasses) {
        mySubmittedPasses.put(dependentPass, Job.NULL_JOB);
    }
    for (ScheduledPass freePass : freePasses) {
        submit(freePass);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Document(com.intellij.openapi.editor.Document) THashMap(gnu.trove.THashMap) EditorBoundHighlightingPass(com.intellij.codeHighlighting.EditorBoundHighlightingPass) Pair(com.intellij.openapi.util.Pair) HighlightingPass(com.intellij.codeHighlighting.HighlightingPass) EditorBoundHighlightingPass(com.intellij.codeHighlighting.EditorBoundHighlightingPass) TextEditorHighlightingPass(com.intellij.codeHighlighting.TextEditorHighlightingPass) FileEditorManagerEx(com.intellij.openapi.fileEditor.ex.FileEditorManagerEx) EditorWindow(com.intellij.injected.editor.EditorWindow) TextEditorHighlightingPass(com.intellij.codeHighlighting.TextEditorHighlightingPass) TextEditor(com.intellij.openapi.fileEditor.TextEditor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TextEditor(com.intellij.openapi.fileEditor.TextEditor) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) THashMap(gnu.trove.THashMap) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) MultiMap(com.intellij.util.containers.MultiMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 70 with TextEditor

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

the class PassExecutorService method createScheduledPass.

@NotNull
private ScheduledPass createScheduledPass(@NotNull FileEditor fileEditor, @NotNull TextEditorHighlightingPass pass, @NotNull Map<Pair<FileEditor, Integer>, ScheduledPass> toBeSubmitted, @NotNull List<TextEditorHighlightingPass> textEditorHighlightingPasses, @NotNull List<ScheduledPass> freePasses, @NotNull List<ScheduledPass> dependentPasses, @NotNull DaemonProgressIndicator updateProgress, @NotNull AtomicInteger threadsToStartCountdown) {
    int passId = pass.getId();
    Pair<FileEditor, Integer> key = Pair.create(fileEditor, passId);
    ScheduledPass scheduledPass = toBeSubmitted.get(key);
    if (scheduledPass != null)
        return scheduledPass;
    scheduledPass = new ScheduledPass(fileEditor, pass, updateProgress, threadsToStartCountdown);
    threadsToStartCountdown.incrementAndGet();
    toBeSubmitted.put(key, scheduledPass);
    for (int predecessorId : pass.getCompletionPredecessorIds()) {
        ScheduledPass predecessor = findOrCreatePredecessorPass(fileEditor, toBeSubmitted, textEditorHighlightingPasses, freePasses, dependentPasses, updateProgress, threadsToStartCountdown, predecessorId);
        if (predecessor != null) {
            predecessor.addSuccessorOnCompletion(scheduledPass);
        }
    }
    for (int predecessorId : pass.getStartingPredecessorIds()) {
        ScheduledPass predecessor = findOrCreatePredecessorPass(fileEditor, toBeSubmitted, textEditorHighlightingPasses, freePasses, dependentPasses, updateProgress, threadsToStartCountdown, predecessorId);
        if (predecessor != null) {
            predecessor.addSuccessorOnSubmit(scheduledPass);
        }
    }
    if (scheduledPass.myRunningPredecessorsCount.get() == 0 && !freePasses.contains(scheduledPass)) {
        freePasses.add(scheduledPass);
    } else if (!dependentPasses.contains(scheduledPass)) {
        dependentPasses.add(scheduledPass);
    }
    if (pass.isRunIntentionPassAfter() && fileEditor instanceof TextEditor) {
        Editor editor = ((TextEditor) fileEditor).getEditor();
        ShowIntentionsPass ip = new ShowIntentionsPass(myProject, editor, -1);
        ip.setId(nextPassId.incrementAndGet());
        ip.setCompletionPredecessorIds(new int[] { scheduledPass.myPass.getId() });
        createScheduledPass(fileEditor, ip, toBeSubmitted, textEditorHighlightingPasses, freePasses, dependentPasses, updateProgress, threadsToStartCountdown);
    }
    return scheduledPass;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) NotNull(org.jetbrains.annotations.NotNull)

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