Search in sources :

Example 16 with TextEditor

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

the class LargeFileNotificationProvider method createNotificationPanel.

@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) {
    if (!(fileEditor instanceof LargeFileEditorProvider.LargeTextFileEditor))
        return null;
    Editor editor = ((TextEditor) fileEditor).getEditor();
    Project project = editor.getProject();
    if (project == null || editor.getUserData(HIDDEN_KEY) != null || PropertiesComponent.getInstance().isTrueValue(DISABLE_KEY)) {
        return null;
    }
    EditorNotificationPanel panel = new EditorNotificationPanel();
    panel.createActionLabel("Hide notification", () -> {
        editor.putUserData(HIDDEN_KEY, "true");
        update(file, project);
    });
    panel.createActionLabel("Don't show again", () -> {
        PropertiesComponent.getInstance().setValue(DISABLE_KEY, "true");
        update(file, project);
    });
    return panel.text(String.format("This file is too large for editing (%s). Read only preview mode is activated.", StringUtil.formatFileSize(file.getLength())));
}
Also used : Project(com.intellij.openapi.project.Project) TextEditor(com.intellij.openapi.fileEditor.TextEditor) EditorNotificationPanel(com.intellij.ui.EditorNotificationPanel) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) Nullable(org.jetbrains.annotations.Nullable)

Example 17 with TextEditor

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

the class DaemonCodeAnalyzerImpl method runPasses.

@NotNull
@TestOnly
List<HighlightInfo> runPasses(@NotNull PsiFile file, @NotNull Document document, @NotNull List<TextEditor> textEditors, @NotNull int[] toIgnore, boolean canChangeDocument, @Nullable final Runnable callbackWhileWaiting) throws ProcessCanceledException {
    assert myInitialized;
    assert !myDisposed;
    ApplicationEx application = ApplicationManagerEx.getApplicationEx();
    application.assertIsDispatchThread();
    if (application.isWriteAccessAllowed()) {
        throw new AssertionError("Must not start highlighting from within write action, or deadlock is imminent");
    }
    DaemonProgressIndicator.setDebug(!ApplicationInfoImpl.isInStressTest());
    ((FileTypeManagerImpl) FileTypeManager.getInstance()).drainReDetectQueue();
    // pump first so that queued event do not interfere
    UIUtil.dispatchAllInvocationEvents();
    // refresh will fire write actions interfering with highlighting
    while (RefreshQueueImpl.isRefreshInProgress() || HeavyProcessLatch.INSTANCE.isRunning()) {
        UIUtil.dispatchAllInvocationEvents();
    }
    long dstart = System.currentTimeMillis();
    while (mustWaitForSmartMode && DumbService.getInstance(myProject).isDumb()) {
        if (System.currentTimeMillis() > dstart + 100000) {
            throw new IllegalStateException("Timeout waiting for smart mode. If you absolutely want to be dumb, please use DaemonCodeAnalyzerImpl.mustWaitForSmartMode(false).");
        }
        UIUtil.dispatchAllInvocationEvents();
    }
    UIUtil.dispatchAllInvocationEvents();
    Project project = file.getProject();
    FileStatusMap fileStatusMap = getFileStatusMap();
    fileStatusMap.allowDirt(canChangeDocument);
    Map<FileEditor, HighlightingPass[]> map = new HashMap<>();
    for (TextEditor textEditor : textEditors) {
        if (textEditor instanceof TextEditorImpl) {
            try {
                ((TextEditorImpl) textEditor).waitForLoaded(10, TimeUnit.SECONDS);
            } catch (TimeoutException e) {
                throw new RuntimeException(textEditor + " has not completed loading in 10 seconds");
            }
        }
        TextEditorBackgroundHighlighter highlighter = (TextEditorBackgroundHighlighter) textEditor.getBackgroundHighlighter();
        if (highlighter == null) {
            Editor editor = textEditor.getEditor();
            throw new RuntimeException("Null highlighter from " + textEditor + "; loaded: " + AsyncEditorLoader.isEditorLoaded(editor));
        }
        final List<TextEditorHighlightingPass> passes = highlighter.getPasses(toIgnore);
        HighlightingPass[] array = passes.toArray(new HighlightingPass[passes.size()]);
        assert array.length != 0 : "Highlighting is disabled for the file " + file;
        map.put(textEditor, array);
    }
    for (int ignoreId : toIgnore) {
        fileStatusMap.markFileUpToDate(document, ignoreId);
    }
    myUpdateRunnableFuture.cancel(false);
    final DaemonProgressIndicator progress = createUpdateProgress();
    myPassExecutorService.submitPasses(map, progress);
    try {
        long start = System.currentTimeMillis();
        while (progress.isRunning() && System.currentTimeMillis() < start + 5 * 60 * 1000) {
            wrap(() -> {
                progress.checkCanceled();
                if (callbackWhileWaiting != null) {
                    callbackWhileWaiting.run();
                }
                waitInOtherThread(50, canChangeDocument);
                UIUtil.dispatchAllInvocationEvents();
                Throwable savedException = PassExecutorService.getSavedException(progress);
                if (savedException != null)
                    throw savedException;
            });
        }
        if (progress.isRunning() && !progress.isCanceled()) {
            throw new RuntimeException("Highlighting still running after " + (System.currentTimeMillis() - start) / 1000 + " seconds.\n" + ThreadDumper.dumpThreadsToString());
        }
        final HighlightingSessionImpl session = (HighlightingSessionImpl) HighlightingSessionImpl.getOrCreateHighlightingSession(file, textEditors.get(0).getEditor(), progress, null);
        wrap(() -> {
            if (!waitInOtherThread(60000, canChangeDocument)) {
                throw new TimeoutException("Unable to complete in 60s");
            }
            session.waitForHighlightInfosApplied();
        });
        UIUtil.dispatchAllInvocationEvents();
        UIUtil.dispatchAllInvocationEvents();
        assert progress.isCanceled() && progress.isDisposed();
        return getHighlights(document, null, project);
    } finally {
        DaemonProgressIndicator.setDebug(false);
        fileStatusMap.allowDirt(true);
        waitForTermination();
    }
}
Also used : FileEditor(com.intellij.openapi.fileEditor.FileEditor) THashMap(gnu.trove.THashMap) FileTypeManagerImpl(com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl) HighlightingPass(com.intellij.codeHighlighting.HighlightingPass) TextEditorHighlightingPass(com.intellij.codeHighlighting.TextEditorHighlightingPass) TextEditorHighlightingPass(com.intellij.codeHighlighting.TextEditorHighlightingPass) Project(com.intellij.openapi.project.Project) TextEditor(com.intellij.openapi.fileEditor.TextEditor) ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx) TextEditorImpl(com.intellij.openapi.fileEditor.impl.text.TextEditorImpl) TextEditor(com.intellij.openapi.fileEditor.TextEditor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Editor(com.intellij.openapi.editor.Editor) TestOnly(org.jetbrains.annotations.TestOnly) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with TextEditor

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

the class EditorNotificationActions method collectDescriptorsForEditor.

public static void collectDescriptorsForEditor(@NotNull Editor editor, @NotNull List<HighlightInfo.IntentionActionDescriptor> descriptors) {
    Project project = editor.getProject();
    if (project == null)
        return;
    FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
    if (!(fileEditorManager instanceof FileEditorManagerImpl))
        return;
    TextEditor fileEditor = TextEditorProvider.getInstance().getTextEditor(editor);
    List<JComponent> components = ((FileEditorManagerImpl) fileEditorManager).getTopComponents(fileEditor);
    for (JComponent component : components) {
        if (component instanceof IntentionActionProvider) {
            IntentionActionWithOptions action = ((IntentionActionProvider) component).getIntentionAction();
            if (action != null) {
                descriptors.add(new HighlightInfo.IntentionActionDescriptor(action, action.getOptions(), null));
            }
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) TextEditor(com.intellij.openapi.fileEditor.TextEditor) FileEditorManagerImpl(com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl) IntentionActionWithOptions(com.intellij.codeInsight.intention.IntentionActionWithOptions) IntentionActionProvider(com.intellij.codeInsight.intention.IntentionActionProvider)

Example 19 with TextEditor

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

the class HippieWordCompletionHandler method computeVariants.

private static List<CompletionVariant> computeVariants(@NotNull final Editor editor, CamelHumpMatcher matcher, PsiFile file, boolean includeWordsFromOtherFiles) {
    final ArrayList<CompletionVariant> words = new ArrayList<>();
    final List<CompletionVariant> afterWords = new ArrayList<>();
    if (includeWordsFromOtherFiles) {
        for (FileEditor fileEditor : FileEditorManager.getInstance(file.getProject()).getAllEditors()) {
            if (fileEditor instanceof TextEditor) {
                Editor anotherEditor = ((TextEditor) fileEditor).getEditor();
                if (anotherEditor != editor) {
                    addWordsForEditor((EditorEx) anotherEditor, matcher, words, afterWords, false);
                }
            }
        }
    } else {
        addWordsForEditor((EditorEx) editor, matcher, words, afterWords, true);
    }
    Set<String> allWords = new HashSet<>();
    List<CompletionVariant> result = new ArrayList<>();
    Collections.reverse(words);
    for (CompletionVariant variant : words) {
        if (!allWords.contains(variant.variant)) {
            result.add(variant);
            allWords.add(variant.variant);
        }
    }
    Collections.reverse(result);
    allWords.clear();
    for (CompletionVariant variant : afterWords) {
        if (!allWords.contains(variant.variant)) {
            result.add(variant);
            allWords.add(variant.variant);
        }
    }
    return result;
}
Also used : FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor)

Example 20 with TextEditor

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

the class FindUsagesManager method findUsageInFile.

private boolean findUsageInFile(@NotNull FileEditor editor, @NotNull FileSearchScope direction) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    if (myLastSearchInFileData == null)
        return false;
    PsiElement[] primaryElements = myLastSearchInFileData.getPrimaryElements();
    PsiElement[] secondaryElements = myLastSearchInFileData.getSecondaryElements();
    if (primaryElements.length == 0) {
        //all elements have been invalidated
        Messages.showMessageDialog(myProject, FindBundle.message("find.searched.elements.have.been.changed.error"), FindBundle.message("cannot.search.for.usages.title"), Messages.getInformationIcon());
        //clearFindingNextUsageInFile();
        return false;
    }
    //todo
    TextEditor textEditor = (TextEditor) editor;
    Document document = textEditor.getEditor().getDocument();
    PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(document);
    if (psiFile == null)
        return false;
    final FindUsagesHandler handler = getFindUsagesHandler(primaryElements[0], false);
    if (handler == null)
        return false;
    findUsagesInEditor(primaryElements, secondaryElements, handler, psiFile, direction, myLastSearchInFileData.myOptions, textEditor);
    return true;
}
Also used : TextEditor(com.intellij.openapi.fileEditor.TextEditor) Document(com.intellij.openapi.editor.Document)

Aggregations

TextEditor (com.intellij.openapi.fileEditor.TextEditor)81 FileEditor (com.intellij.openapi.fileEditor.FileEditor)57 Editor (com.intellij.openapi.editor.Editor)32 VirtualFile (com.intellij.openapi.vfs.VirtualFile)28 Project (com.intellij.openapi.project.Project)21 Document (com.intellij.openapi.editor.Document)14 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)13 Nullable (org.jetbrains.annotations.Nullable)13 PsiFile (com.intellij.psi.PsiFile)11 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)6 NotNull (org.jetbrains.annotations.NotNull)6 Disposable (com.intellij.openapi.Disposable)3 EditorEx (com.intellij.openapi.editor.ex.EditorEx)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