Search in sources :

Example 16 with EditorColorsScheme

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

the class AnnotateToggleAction method computeBgColors.

@Nullable
private static Couple<Map<VcsRevisionNumber, Color>> computeBgColors(@NotNull FileAnnotation fileAnnotation, @NotNull Editor editor) {
    Map<VcsRevisionNumber, Color> commitOrderColors = new HashMap<>();
    Map<VcsRevisionNumber, Color> commitAuthorColors = new HashMap<>();
    EditorColorsScheme colorScheme = editor.getColorsScheme();
    AnnotationsSettings settings = AnnotationsSettings.getInstance();
    List<Color> authorsColorPalette = settings.getAuthorsColors(colorScheme);
    List<Color> orderedColorPalette = settings.getOrderedColors(colorScheme);
    FileAnnotation.AuthorsMappingProvider authorsMappingProvider = fileAnnotation.getAuthorsMappingProvider();
    if (authorsMappingProvider != null) {
        Map<VcsRevisionNumber, String> authorsMap = authorsMappingProvider.getAuthors();
        Map<String, Color> authorColors = new HashMap<>();
        for (String author : ContainerUtil.sorted(authorsMap.values(), Comparing::compare)) {
            int index = authorColors.size();
            Color color = authorsColorPalette.get(index % authorsColorPalette.size());
            authorColors.put(author, color);
        }
        for (Map.Entry<VcsRevisionNumber, String> entry : authorsMap.entrySet()) {
            VcsRevisionNumber revision = entry.getKey();
            String author = entry.getValue();
            Color color = authorColors.get(author);
            commitAuthorColors.put(revision, color);
        }
    }
    FileAnnotation.RevisionsOrderProvider revisionsOrderProvider = fileAnnotation.getRevisionsOrderProvider();
    if (revisionsOrderProvider != null) {
        List<List<VcsRevisionNumber>> orderedRevisions = revisionsOrderProvider.getOrderedRevisions();
        int revisionsCount = orderedRevisions.size();
        for (int index = 0; index < revisionsCount; index++) {
            Color color = orderedColorPalette.get(orderedColorPalette.size() * index / revisionsCount);
            for (VcsRevisionNumber number : orderedRevisions.get(index)) {
                commitOrderColors.put(number, color);
            }
        }
    }
    return Couple.of(commitOrderColors.size() > 1 ? commitOrderColors : null, commitAuthorColors.size() > 1 ? commitAuthorColors : null);
}
Also used : HashMap(java.util.HashMap) VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) ArrayList(java.util.ArrayList) List(java.util.List) FileAnnotation(com.intellij.openapi.vcs.annotate.FileAnnotation) HashMap(java.util.HashMap) Map(java.util.Map) Comparing(com.intellij.openapi.util.Comparing) Nullable(org.jetbrains.annotations.Nullable)

Example 17 with EditorColorsScheme

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

the class XLineBreakpointImpl method updateUI.

public void updateUI() {
    if (isDisposed() || ApplicationManager.getApplication().isUnitTestMode()) {
        return;
    }
    Document document = getDocument();
    if (document == null) {
        return;
    }
    EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
    TextAttributes attributes = scheme.getAttributes(DebuggerColors.BREAKPOINT_ATTRIBUTES);
    RangeHighlighter highlighter = myHighlighter;
    if (highlighter != null && (!highlighter.isValid() || !DocumentUtil.isValidOffset(highlighter.getStartOffset(), document) || !Comparing.equal(highlighter.getTextAttributes(), attributes))) {
        removeHighlighter();
        highlighter = null;
    }
    MarkupModelEx markupModel;
    if (highlighter == null) {
        markupModel = (MarkupModelEx) DocumentMarkupModel.forDocument(document, getProject(), true);
        TextRange range = myType.getHighlightRange(this);
        if (range != null && !range.isEmpty()) {
            range = range.intersection(DocumentUtil.getLineTextRange(document, getLine()));
            if (range != null && !range.isEmpty()) {
                highlighter = markupModel.addRangeHighlighter(range.getStartOffset(), range.getEndOffset(), DebuggerColors.BREAKPOINT_HIGHLIGHTER_LAYER, attributes, HighlighterTargetArea.EXACT_RANGE);
            }
        }
        if (highlighter == null) {
            highlighter = markupModel.addPersistentLineHighlighter(getLine(), DebuggerColors.BREAKPOINT_HIGHLIGHTER_LAYER, attributes);
        }
        if (highlighter == null) {
            return;
        }
        highlighter.setGutterIconRenderer(createGutterIconRenderer());
        highlighter.putUserData(DebuggerColors.BREAKPOINT_HIGHLIGHTER_KEY, Boolean.TRUE);
        highlighter.setEditorFilter(MarkupEditorFilterFactory.createIsNotDiffFilter());
        myHighlighter = highlighter;
    } else {
        markupModel = null;
    }
    updateIcon();
    if (markupModel == null) {
        markupModel = (MarkupModelEx) DocumentMarkupModel.forDocument(document, getProject(), false);
        if (markupModel != null) {
            // renderersChanged false - we don't change gutter size
            markupModel.fireAttributesChanged((RangeHighlighterEx) highlighter, false, false);
        }
    }
}
Also used : MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document)

Example 18 with EditorColorsScheme

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

the class AbstractValueHint method invokeHint.

public void invokeHint(Runnable hideRunnable) {
    myHideRunnable = hideRunnable;
    if (!canShowHint()) {
        hideHint();
        return;
    }
    if (myType == ValueHintType.MOUSE_ALT_OVER_HINT) {
        EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
        TextAttributes attributes = scheme.getAttributes(EditorColors.REFERENCE_HYPERLINK_COLOR);
        attributes = NavigationUtil.patchAttributesColor(attributes, myCurrentRange, myEditor);
        myHighlighter = myEditor.getMarkupModel().addRangeHighlighter(myCurrentRange.getStartOffset(), myCurrentRange.getEndOffset(), HighlighterLayer.HYPERLINK, attributes, HighlighterTargetArea.EXACT_RANGE);
        Component internalComponent = myEditor.getContentComponent();
        myStoredCursor = internalComponent.getCursor();
        internalComponent.addKeyListener(myEditorKeyListener);
        internalComponent.setCursor(hintCursor());
        if (LOG.isDebugEnabled()) {
            LOG.debug("internalComponent.setCursor(hintCursor())");
        }
    } else {
        evaluateAndShowHint();
    }
}
Also used : TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme)

Example 19 with EditorColorsScheme

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

the class XDebuggerUtilImpl method toggleAndReturnLineBreakpoint.

@NotNull
public static <P extends XBreakpointProperties> Promise<XLineBreakpoint> toggleAndReturnLineBreakpoint(@NotNull final Project project, @NotNull final XLineBreakpointType<P> type, @NotNull final XSourcePosition position, final boolean temporary, @Nullable final Editor editor, boolean canRemove) {
    return new WriteAction<Promise<XLineBreakpoint>>() {

        @Override
        protected void run(@NotNull Result<Promise<XLineBreakpoint>> result) throws Throwable {
            final VirtualFile file = position.getFile();
            final int line = position.getLine();
            final XBreakpointManager breakpointManager = XDebuggerManager.getInstance(project).getBreakpointManager();
            XLineBreakpoint<P> breakpoint = breakpointManager.findBreakpointAtLine(type, file, line);
            if (breakpoint != null) {
                if (!temporary && canRemove) {
                    breakpointManager.removeBreakpoint(breakpoint);
                }
            } else {
                List<? extends XLineBreakpointType<P>.XLineBreakpointVariant<P>> variants = type.computeVariants(project, position);
                if (!variants.isEmpty() && editor != null) {
                    RelativePoint relativePoint = DebuggerUIUtil.getPositionForPopup(editor, line);
                    if (variants.size() > 1 && relativePoint != null) {
                        final AsyncPromise<XLineBreakpoint> res = new AsyncPromise<>();
                        class MySelectionListener implements ListSelectionListener {

                            RangeHighlighter myHighlighter = null;

                            @Override
                            public void valueChanged(ListSelectionEvent e) {
                                if (!e.getValueIsAdjusting()) {
                                    updateHighlighter(((JList) e.getSource()).getSelectedValue());
                                }
                            }

                            public void initialSet(Object value) {
                                if (myHighlighter == null) {
                                    updateHighlighter(value);
                                }
                            }

                            void updateHighlighter(Object value) {
                                clearHighlighter();
                                if (value instanceof XLineBreakpointType.XLineBreakpointVariant) {
                                    TextRange range = ((XLineBreakpointType.XLineBreakpointVariant) value).getHighlightRange();
                                    TextRange lineRange = DocumentUtil.getLineTextRange(editor.getDocument(), line);
                                    if (range != null) {
                                        range = range.intersection(lineRange);
                                    } else {
                                        range = lineRange;
                                    }
                                    if (range != null && !range.isEmpty()) {
                                        EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
                                        TextAttributes attributes = scheme.getAttributes(DebuggerColors.BREAKPOINT_ATTRIBUTES);
                                        myHighlighter = editor.getMarkupModel().addRangeHighlighter(range.getStartOffset(), range.getEndOffset(), DebuggerColors.BREAKPOINT_HIGHLIGHTER_LAYER, attributes, HighlighterTargetArea.EXACT_RANGE);
                                    }
                                }
                            }

                            private void clearHighlighter() {
                                if (myHighlighter != null) {
                                    myHighlighter.dispose();
                                }
                            }
                        }
                        // calculate default item
                        int caretOffset = editor.getCaretModel().getOffset();
                        XLineBreakpointType<P>.XLineBreakpointVariant<P> defaultVariant = null;
                        for (XLineBreakpointType<P>.XLineBreakpointVariant<P> variant : variants) {
                            TextRange range = variant.getHighlightRange();
                            if (range != null && range.contains(caretOffset)) {
                                //noinspection ConstantConditions
                                if (defaultVariant == null || defaultVariant.getHighlightRange().getLength() > range.getLength()) {
                                    defaultVariant = variant;
                                }
                            }
                        }
                        final int defaultIndex = defaultVariant != null ? variants.indexOf(defaultVariant) : 0;
                        final MySelectionListener selectionListener = new MySelectionListener();
                        ListPopupImpl popup = new ListPopupImpl(new BaseListPopupStep<XLineBreakpointType.XLineBreakpointVariant>("Set Breakpoint", variants) {

                            @NotNull
                            @Override
                            public String getTextFor(XLineBreakpointType.XLineBreakpointVariant value) {
                                return value.getText();
                            }

                            @Override
                            public Icon getIconFor(XLineBreakpointType.XLineBreakpointVariant value) {
                                return value.getIcon();
                            }

                            @Override
                            public void canceled() {
                                selectionListener.clearHighlighter();
                            }

                            @Override
                            public PopupStep onChosen(final XLineBreakpointType.XLineBreakpointVariant selectedValue, boolean finalChoice) {
                                selectionListener.clearHighlighter();
                                ApplicationManager.getApplication().runWriteAction(() -> {
                                    P properties = (P) selectedValue.createProperties();
                                    res.setResult(breakpointManager.addLineBreakpoint(type, file.getUrl(), line, properties, temporary));
                                });
                                return FINAL_CHOICE;
                            }

                            @Override
                            public int getDefaultOptionIndex() {
                                return defaultIndex;
                            }
                        }) {

                            @Override
                            protected void afterShow() {
                                super.afterShow();
                                selectionListener.initialSet(getList().getSelectedValue());
                            }
                        };
                        DebuggerUIUtil.registerExtraHandleShortcuts(popup, IdeActions.ACTION_TOGGLE_LINE_BREAKPOINT);
                        popup.setAdText(DebuggerUIUtil.getSelectionShortcutsAdText(IdeActions.ACTION_TOGGLE_LINE_BREAKPOINT));
                        popup.addListSelectionListener(selectionListener);
                        popup.show(relativePoint);
                        result.setResult(res);
                        return;
                    } else {
                        P properties = variants.get(0).createProperties();
                        result.setResult(Promise.resolve(breakpointManager.addLineBreakpoint(type, file.getUrl(), line, properties, temporary)));
                        return;
                    }
                }
                P properties = type.createBreakpointProperties(file, line);
                result.setResult(Promise.resolve(breakpointManager.addLineBreakpoint(type, file.getUrl(), line, properties, temporary)));
                return;
            }
            result.setResult(rejectedPromise());
        }
    }.execute().getResultObject();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ListSelectionEvent(javax.swing.event.ListSelectionEvent) RelativePoint(com.intellij.ui.awt.RelativePoint) AsyncPromise(org.jetbrains.concurrency.AsyncPromise) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) WriteAction(com.intellij.openapi.application.WriteAction) TextRange(com.intellij.openapi.util.TextRange) RelativePoint(com.intellij.ui.awt.RelativePoint) ListSelectionListener(javax.swing.event.ListSelectionListener) ListPopupImpl(com.intellij.ui.popup.list.ListPopupImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with EditorColorsScheme

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

the class ExecutionPointHighlighter method addHighlighter.

private void addHighlighter() {
    adjustCounter(myEditor, 1);
    int line = mySourcePosition.getLine();
    Document document = myEditor.getDocument();
    if (line < 0 || line >= document.getLineCount())
        return;
    if (myRangeHighlighter != null)
        return;
    EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
    TextAttributes attributes = myNotTopFrame ? scheme.getAttributes(DebuggerColors.NOT_TOP_FRAME_ATTRIBUTES) : scheme.getAttributes(DebuggerColors.EXECUTIONPOINT_ATTRIBUTES);
    MarkupModel markupModel = DocumentMarkupModel.forDocument(document, myProject, true);
    if (mySourcePosition instanceof HighlighterProvider) {
        TextRange range = ((HighlighterProvider) mySourcePosition).getHighlightRange();
        if (range != null) {
            TextRange lineRange = DocumentUtil.getLineTextRange(document, line);
            range = range.intersection(lineRange);
            if (range != null && !range.isEmpty() && !range.equals(lineRange)) {
                myRangeHighlighter = markupModel.addRangeHighlighter(range.getStartOffset(), range.getEndOffset(), DebuggerColors.EXECUTION_LINE_HIGHLIGHTERLAYER, attributes, HighlighterTargetArea.EXACT_RANGE);
            }
        }
    }
    if (myRangeHighlighter == null) {
        myRangeHighlighter = markupModel.addLineHighlighter(line, DebuggerColors.EXECUTION_LINE_HIGHLIGHTERLAYER, attributes);
    }
    myRangeHighlighter.putUserData(EXECUTION_POINT_HIGHLIGHTER_KEY, true);
    myRangeHighlighter.setEditorFilter(MarkupEditorFilterFactory.createIsNotDiffFilter());
    myRangeHighlighter.setGutterIconRenderer(myGutterIconRenderer);
}
Also used : EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel)

Aggregations

EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)103 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