Search in sources :

Example 41 with TextEditor

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

the class AnnotateLocalFileAction method perform.

private static void perform(AnActionEvent e, boolean selected) {
    final VcsContext context = VcsContextFactory.SERVICE.getInstance().createContextOn(e);
    if (!selected) {
        for (Editor editor : getEditors(context)) {
            editor.getGutter().closeAllAnnotations();
        }
    } else {
        Project project = assertNotNull(context.getProject());
        VirtualFile selectedFile = assertNotNull(context.getSelectedFile());
        Editor editor = context.getEditor();
        if (editor == null) {
            FileEditor[] fileEditors = FileEditorManager.getInstance(project).openFile(selectedFile, false);
            for (FileEditor fileEditor : fileEditors) {
                if (fileEditor instanceof TextEditor) {
                    editor = ((TextEditor) fileEditor).getEditor();
                }
            }
        }
        LOG.assertTrue(editor != null);
        doAnnotate(editor, project);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor)

Example 42 with TextEditor

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

the class EditorNotificationsImpl method createTask.

@Nullable
private ReadTask createTask(@NotNull final ProgressIndicator indicator, @NotNull final VirtualFile file) {
    List<FileEditor> editors = ContainerUtil.filter(FileEditorManager.getInstance(myProject).getAllEditors(file), editor -> !(editor instanceof TextEditor) || AsyncEditorLoader.isEditorLoaded(((TextEditor) editor).getEditor()));
    if (editors.isEmpty())
        return null;
    return new ReadTask() {

        private boolean isOutdated() {
            if (myProject.isDisposed() || !file.isValid() || indicator != getCurrentProgress(file)) {
                return true;
            }
            for (FileEditor editor : editors) {
                if (!editor.isValid()) {
                    return true;
                }
            }
            return false;
        }

        @Nullable
        @Override
        public Continuation performInReadAction(@NotNull ProgressIndicator indicator) throws ProcessCanceledException {
            if (isOutdated())
                return null;
            final List<Provider> providers = DumbService.getInstance(myProject).filterByDumbAwareness(EXTENSION_POINT_NAME.getExtensions(myProject));
            final List<Runnable> updates = ContainerUtil.newArrayList();
            for (final FileEditor editor : editors) {
                for (final Provider<?> provider : providers) {
                    final JComponent component = provider.createNotificationPanel(file, editor);
                    updates.add(() -> updateNotification(editor, provider.getKey(), component));
                }
            }
            return new Continuation(() -> {
                if (!isOutdated()) {
                    file.putUserData(CURRENT_UPDATES, null);
                    for (Runnable update : updates) {
                        update.run();
                    }
                }
            }, ModalityState.any());
        }

        @Override
        public void onCanceled(@NotNull ProgressIndicator ignored) {
            if (getCurrentProgress(file) == indicator) {
                updateNotifications(file);
            }
        }
    };
}
Also used : FileEditor(com.intellij.openapi.fileEditor.FileEditor) NotNull(org.jetbrains.annotations.NotNull) RefactoringElementListenerProvider(com.intellij.refactoring.listeners.RefactoringElementListenerProvider) TextEditor(com.intellij.openapi.fileEditor.TextEditor) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ReadTask(com.intellij.openapi.progress.util.ReadTask) Nullable(org.jetbrains.annotations.Nullable)

Example 43 with TextEditor

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

the class XDebuggerSmartStepIntoHandler method perform.

@Override
protected void perform(@NotNull XDebugSession session, DataContext dataContext) {
    XSmartStepIntoHandler<?> handler = session.getDebugProcess().getSmartStepIntoHandler();
    XSourcePosition position = session.getTopFramePosition();
    if (position == null || handler == null)
        return;
    FileEditor editor = FileEditorManager.getInstance(session.getProject()).getSelectedEditor(position.getFile());
    if (editor instanceof TextEditor) {
        doSmartStepInto(handler, position, session, ((TextEditor) editor).getEditor());
    }
}
Also used : FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) XSourcePosition(com.intellij.xdebugger.XSourcePosition)

Example 44 with TextEditor

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

the class XDebuggerInlayUtil method createInlay.

public static void createInlay(@NotNull Project project, @NotNull VirtualFile file, int offset, String inlayText) {
    UIUtil.invokeLaterIfNeeded(() -> {
        FileEditor editor = FileEditorManager.getInstance(project).getSelectedEditor(file);
        if (editor instanceof TextEditor) {
            Editor e = ((TextEditor) editor).getEditor();
            CharSequence text = e.getDocument().getImmutableCharSequence();
            int insertOffset = offset;
            while (insertOffset < text.length() && Character.isJavaIdentifierPart(text.charAt(insertOffset))) insertOffset++;
            List<Inlay> existing = e.getInlayModel().getInlineElementsInRange(insertOffset, insertOffset);
            for (Inlay inlay : existing) {
                if (inlay.getRenderer() instanceof MyRenderer) {
                    Disposer.dispose(inlay);
                }
            }
            e.getInlayModel().addInlineElement(insertOffset, new MyRenderer(inlayText));
        }
    });
}
Also used : FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) Inlay(com.intellij.openapi.editor.Inlay) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor)

Example 45 with TextEditor

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

the class DetectableIndentOptionsProvider method getNotificationInfo.

@Nullable
@Override
public EditorNotificationInfo getNotificationInfo(@NotNull final Project project, @NotNull final VirtualFile file, @NotNull final FileEditor fileEditor, @NotNull IndentOptions userOptions, @NotNull IndentOptions detectedOptions) {
    final NotificationLabels labels = getNotificationLabels(userOptions, detectedOptions);
    final Editor editor = fileEditor instanceof TextEditor ? ((TextEditor) fileEditor).getEditor() : null;
    if (labels == null || editor == null)
        return null;
    ActionLabelData okAction = new ActionLabelData(ApplicationBundle.message("code.style.indents.detector.accept"), () -> setAccepted(file));
    ActionLabelData disableForSingleFile = new ActionLabelData(labels.revertToOldSettingsLabel, () -> {
        disableForFile(file);
        if (editor instanceof EditorEx) {
            ((EditorEx) editor).reinitSettings();
        }
    });
    ActionLabelData showSettings = new ActionLabelData(ApplicationBundle.message("code.style.indents.detector.show.settings"), () -> ShowSettingsUtilImpl.showSettingsDialog(project, "preferences.sourceCode", "detect indent"));
    final List<ActionLabelData> actions = ContainerUtil.newArrayList(okAction, disableForSingleFile, showSettings);
    return new EditorNotificationInfo() {

        @NotNull
        @Override
        public List<ActionLabelData> getLabelAndActions() {
            return actions;
        }

        @NotNull
        @Override
        public String getTitle() {
            return labels.title;
        }
    };
}
Also used : TextEditor(com.intellij.openapi.fileEditor.TextEditor) EditorEx(com.intellij.openapi.editor.ex.EditorEx) ActionLabelData(com.intellij.psi.codeStyle.EditorNotificationInfo.ActionLabelData) TextEditor(com.intellij.openapi.fileEditor.TextEditor) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Nullable(org.jetbrains.annotations.Nullable)

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