Search in sources :

Example 61 with EditorColorsScheme

use of com.intellij.openapi.editor.colors.EditorColorsScheme in project android by JetBrains.

the class MergedManifestFixture method getDefaultBackgroundColor.

public Color getDefaultBackgroundColor() {
    EditorColorsManager colorsManager = EditorColorsManager.getInstance();
    EditorColorsScheme scheme = colorsManager.getGlobalScheme();
    return scheme.getDefaultBackground();
}
Also used : EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager)

Example 62 with EditorColorsScheme

use of com.intellij.openapi.editor.colors.EditorColorsScheme in project intellij-community by JetBrains.

the class VcsPreviewPanel method updateView.

@Override
public void updateView() {
    EditorColorsScheme colorsScheme = myEditor.getColorsScheme();
    StringBuilder sb = new StringBuilder();
    sb.append("Deleted line below\n\n" + "Modified line\n\n" + "Added line\n\n" + "Line with modified whitespaces\n\n" + "Added line\n" + "Line with modified whitespaces and deletion after\n");
    int additionalLines = Math.max(0, AnnotationsSettings.getInstance().getOrderedColors(colorsScheme).size() - StringUtil.countNewLines(sb));
    sb.append(StringUtil.repeat("\n", additionalLines));
    myEditor.getDocument().setText(sb);
    myEditor.getMarkupModel().removeAllHighlighters();
    myEditor.getGutterComponentEx().closeAllAnnotations();
    addHighlighter(new Range(1, 1, 0, 1), EditorColors.DELETED_LINES_COLOR);
    addHighlighter(createModifiedRange(2, Range.MODIFIED), EditorColors.MODIFIED_LINES_COLOR);
    addHighlighter(createModifiedRange(4, Range.INSERTED), EditorColors.ADDED_LINES_COLOR);
    addHighlighter(createModifiedRange(6, Range.EQUAL), EditorColors.WHITESPACES_MODIFIED_LINES_COLOR);
    addHighlighter(createModifiedRange(8, Range.INSERTED, Range.EQUAL, Range.DELETED), EditorColors.WHITESPACES_MODIFIED_LINES_COLOR);
    List<Color> annotationColors = AnnotationsSettings.getInstance().getOrderedColors(colorsScheme);
    List<Integer> anchorIndexes = AnnotationsSettings.getInstance().getAnchorIndexes(colorsScheme);
    myEditor.getGutterComponentEx().registerTextAnnotation(new MyTextAnnotationGutterProvider(annotationColors, anchorIndexes));
}
Also used : EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) Range(com.intellij.openapi.vcs.ex.Range) TextRange(com.intellij.openapi.util.TextRange) InnerRange(com.intellij.openapi.vcs.ex.Range.InnerRange)

Example 63 with EditorColorsScheme

use of com.intellij.openapi.editor.colors.EditorColorsScheme in project intellij-community by JetBrains.

the class HighlightUtil method highlightElements.

public static void highlightElements(@NotNull final Collection<? extends PsiElement> elementCollection, @NotNull final String statusBarText) {
    if (elementCollection.isEmpty()) {
        return;
    }
    final Application application = ApplicationManager.getApplication();
    application.invokeLater(() -> {
        final PsiElement[] elements = PsiUtilCore.toPsiElementArray(elementCollection);
        final PsiElement firstElement = elements[0];
        if (!firstElement.isValid()) {
            return;
        }
        final Project project = firstElement.getProject();
        final FileEditorManager editorManager = FileEditorManager.getInstance(project);
        final EditorColorsManager editorColorsManager = EditorColorsManager.getInstance();
        final Editor editor = editorManager.getSelectedTextEditor();
        if (editor == null) {
            return;
        }
        final EditorColorsScheme globalScheme = editorColorsManager.getGlobalScheme();
        final TextAttributes textattributes = globalScheme.getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
        final HighlightManager highlightManager = HighlightManager.getInstance(project);
        highlightManager.addOccurrenceHighlights(editor, elements, textattributes, true, null);
        final FindManager findmanager = FindManager.getInstance(project);
        FindModel findmodel = findmanager.getFindNextModel();
        if (findmodel == null) {
            findmodel = findmanager.getFindInFileModel();
        }
        findmodel.setSearchHighlighters(true);
        findmanager.setFindWasPerformed();
        findmanager.setFindNextModel(findmodel);
        application.invokeLater(() -> {
            final WindowManager windowManager = WindowManager.getInstance();
            final StatusBar statusBar = windowManager.getStatusBar(project);
            if (statusBar != null) {
                statusBar.setInfo(statusBarText);
            }
        });
    });
}
Also used : FindModel(com.intellij.find.FindModel) HighlightManager(com.intellij.codeInsight.highlighting.HighlightManager) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) StatusBar(com.intellij.openapi.wm.StatusBar) WindowManager(com.intellij.openapi.wm.WindowManager) Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FindManager(com.intellij.find.FindManager) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) Editor(com.intellij.openapi.editor.Editor) Application(com.intellij.openapi.application.Application) PsiElement(com.intellij.psi.PsiElement)

Example 64 with EditorColorsScheme

use of com.intellij.openapi.editor.colors.EditorColorsScheme in project intellij-community by JetBrains.

the class TextWithMarkupProcessor method collectTransferableData.

@NotNull
@Override
public List<RawTextWithMarkup> collectTransferableData(PsiFile file, Editor editor, int[] startOffsets, int[] endOffsets) {
    if (!RichCopySettings.getInstance().isEnabled()) {
        return Collections.emptyList();
    }
    try {
        RichCopySettings settings = RichCopySettings.getInstance();
        List<Caret> carets = editor.getCaretModel().getAllCarets();
        Caret firstCaret = carets.get(0);
        final int indentSymbolsToStrip;
        final int firstLineStartOffset;
        if (Registry.is("editor.richcopy.strip.indents") && carets.size() == 1) {
            Pair<Integer, Integer> p = calcIndentSymbolsToStrip(editor.getDocument(), firstCaret.getSelectionStart(), firstCaret.getSelectionEnd());
            firstLineStartOffset = p.first;
            indentSymbolsToStrip = p.second;
        } else {
            firstLineStartOffset = firstCaret.getSelectionStart();
            indentSymbolsToStrip = 0;
        }
        logInitial(editor, startOffsets, endOffsets, indentSymbolsToStrip, firstLineStartOffset);
        CharSequence text = editor.getDocument().getCharsSequence();
        EditorColorsScheme schemeToUse = settings.getColorsScheme(editor.getColorsScheme());
        EditorHighlighter highlighter = HighlighterFactory.createHighlighter(file.getViewProvider().getVirtualFile(), schemeToUse, file.getProject());
        highlighter.setText(text);
        MarkupModel markupModel = DocumentMarkupModel.forDocument(editor.getDocument(), file.getProject(), false);
        Context context = new Context(text, schemeToUse, indentSymbolsToStrip);
        int endOffset = 0;
        Caret prevCaret = null;
        for (Caret caret : carets) {
            int caretSelectionStart = caret.getSelectionStart();
            int caretSelectionEnd = caret.getSelectionEnd();
            int startOffsetToUse;
            int additionalShift = 0;
            if (caret == firstCaret) {
                startOffsetToUse = firstLineStartOffset;
            } else {
                startOffsetToUse = caretSelectionStart;
                assert prevCaret != null;
                String prevCaretSelectedText = prevCaret.getSelectedText();
                // Block selection fills short lines by white spaces
                int fillStringLength = prevCaretSelectedText == null ? 0 : prevCaretSelectedText.length() - (prevCaret.getSelectionEnd() - prevCaret.getSelectionStart());
                context.addCharacter(endOffset + fillStringLength);
                additionalShift = fillStringLength + 1;
            }
            context.reset(endOffset - caretSelectionStart + additionalShift);
            endOffset = caretSelectionEnd;
            prevCaret = caret;
            if (endOffset <= startOffsetToUse) {
                continue;
            }
            MyMarkupIterator markupIterator = new MyMarkupIterator(text, new CompositeRangeIterator(schemeToUse, new HighlighterRangeIterator(highlighter, startOffsetToUse, endOffset), new MarkupModelRangeIterator(markupModel, schemeToUse, startOffsetToUse, endOffset)), schemeToUse);
            try {
                context.iterate(markupIterator, endOffset);
            } finally {
                markupIterator.dispose();
            }
        }
        SyntaxInfo syntaxInfo = context.finish();
        logSyntaxInfo(syntaxInfo);
        createResult(syntaxInfo, editor);
        return ObjectUtils.notNull(myResult, Collections.<RawTextWithMarkup>emptyList());
    } catch (Exception e) {
        // catching the exception so that the rest of copy/paste functionality can still work fine
        LOG.error(e);
    }
    return Collections.emptyList();
}
Also used : RichCopySettings(com.intellij.openapi.editor.richcopy.settings.RichCopySettings) SyntaxInfo(com.intellij.openapi.editor.richcopy.model.SyntaxInfo) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel) MarkupModel(com.intellij.openapi.editor.markup.MarkupModel) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter) NotNull(org.jetbrains.annotations.NotNull)

Example 65 with EditorColorsScheme

use of com.intellij.openapi.editor.colors.EditorColorsScheme in project intellij-community by JetBrains.

the class EditorTextField method initOneLineMode.

private void initOneLineMode(final EditorEx editor) {
    final boolean isOneLineMode = isOneLineMode();
    // set mode in editor
    editor.setOneLineMode(isOneLineMode);
    EditorColorsManager colorsManager = EditorColorsManager.getInstance();
    final EditorColorsScheme defaultScheme = UIUtil.isUnderDarcula() ? colorsManager.getGlobalScheme() : colorsManager.getScheme(EditorColorsManager.DEFAULT_SCHEME_NAME);
    EditorColorsScheme customGlobalScheme = isOneLineMode ? defaultScheme : null;
    editor.setColorsScheme(editor.createBoundColorSchemeDelegate(customGlobalScheme));
    EditorColorsScheme colorsScheme = editor.getColorsScheme();
    editor.getSettings().setCaretRowShown(false);
    // color scheme settings:
    setupEditorFont(editor);
    updateBorder(editor);
    editor.setBackgroundColor(getBackgroundColor(isEnabled(), colorsScheme));
}
Also used : EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager)

Aggregations

EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)105 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)31 NotNull (org.jetbrains.annotations.NotNull)28 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)17 Nullable (org.jetbrains.annotations.Nullable)15 Document (com.intellij.openapi.editor.Document)14 Project (com.intellij.openapi.project.Project)14 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)12 Editor (com.intellij.openapi.editor.Editor)11 DocumentMarkupModel (com.intellij.openapi.editor.impl.DocumentMarkupModel)10 EditorEx (com.intellij.openapi.editor.ex.EditorEx)8 TextRange (com.intellij.openapi.util.TextRange)8 EditorHighlighter (com.intellij.openapi.editor.highlighter.EditorHighlighter)7 PsiFile (com.intellij.psi.PsiFile)7 List (java.util.List)7 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)6 ApplicationManager (com.intellij.openapi.application.ApplicationManager)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 java.awt (java.awt)6 java.util (java.util)6