Search in sources :

Example 1 with MarkupModel

use of com.intellij.openapi.editor.markup.MarkupModel in project intellij-community by JetBrains.

the class EditorTextFieldControl method updateComponent.

@Override
protected void updateComponent() {
    final DomElement domElement = getDomElement();
    if (domElement == null || !domElement.isValid())
        return;
    final EditorTextField textField = getEditorTextField(getComponent());
    final Project project = getProject();
    ApplicationManager.getApplication().invokeLater(() -> {
        if (!project.isOpen())
            return;
        if (!getDomWrapper().isValid())
            return;
        final DomElement domElement1 = getDomElement();
        if (domElement1 == null || !domElement1.isValid())
            return;
        final DomElementAnnotationsManager manager = DomElementAnnotationsManager.getInstance(project);
        final DomElementsProblemsHolder holder = manager.getCachedProblemHolder(domElement1);
        final List<DomElementProblemDescriptor> errorProblems = holder.getProblems(domElement1);
        final List<DomElementProblemDescriptor> warningProblems = new ArrayList<>(holder.getProblems(domElement1, true, HighlightSeverity.WARNING));
        warningProblems.removeAll(errorProblems);
        Color background = getDefaultBackground();
        if (errorProblems.size() > 0 && textField.getText().trim().length() == 0) {
            background = getErrorBackground();
        } else if (warningProblems.size() > 0) {
            background = getWarningBackground();
        }
        final Editor editor = textField.getEditor();
        if (editor != null) {
            final MarkupModel markupModel = editor.getMarkupModel();
            markupModel.removeAllHighlighters();
            if (!errorProblems.isEmpty() && editor.getDocument().getLineCount() > 0) {
                final TextAttributes attributes = SimpleTextAttributes.ERROR_ATTRIBUTES.toTextAttributes();
                attributes.setEffectType(EffectType.WAVE_UNDERSCORE);
                attributes.setEffectColor(attributes.getForegroundColor());
                markupModel.addLineHighlighter(0, 0, attributes);
                editor.getContentComponent().setToolTipText(errorProblems.get(0).getDescriptionTemplate());
            }
        }
        textField.setBackground(background);
    });
}
Also used : Project(com.intellij.openapi.project.Project) DomElementsProblemsHolder(com.intellij.util.xml.highlighting.DomElementsProblemsHolder) DomElement(com.intellij.util.xml.DomElement) EditorTextField(com.intellij.ui.EditorTextField) DomElementProblemDescriptor(com.intellij.util.xml.highlighting.DomElementProblemDescriptor) ArrayList(java.util.ArrayList) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) Editor(com.intellij.openapi.editor.Editor) MarkupModel(com.intellij.openapi.editor.markup.MarkupModel) DomElementAnnotationsManager(com.intellij.util.xml.highlighting.DomElementAnnotationsManager)

Example 2 with MarkupModel

use of com.intellij.openapi.editor.markup.MarkupModel in project intellij-community by JetBrains.

the class GrInplaceParameterIntroducer method updateTitle.

@Override
protected void updateTitle(@Nullable GrVariable variable, String value) {
    if (getPreviewEditor() == null || variable == null)
        return;
    final PsiElement declarationScope = ((PsiParameter) variable).getDeclarationScope();
    if (declarationScope instanceof PsiMethod) {
        final PsiMethod psiMethod = (PsiMethod) declarationScope;
        final StringBuilder buf = new StringBuilder();
        buf.append(psiMethod.getName()).append(" (");
        boolean frst = true;
        final List<TextRange> ranges2Remove = new ArrayList<>();
        TextRange addedRange = null;
        int i = 0;
        for (PsiParameter parameter : psiMethod.getParameterList().getParameters()) {
            if (frst) {
                frst = false;
            } else {
                buf.append(", ");
            }
            int startOffset = buf.length();
            /*if (myMustBeFinal || myPanel.isGenerateFinal()) {
          buf.append("final ");
        }*/
            buf.append(parameter.getType().getPresentableText()).append(" ").append(variable == parameter ? value : parameter.getName());
            int endOffset = buf.length();
            if (variable == parameter) {
                addedRange = new TextRange(startOffset, endOffset);
            } else if (myParametersToRemove.contains(i)) {
                ranges2Remove.add(new TextRange(startOffset, endOffset));
            }
            i++;
        }
        assert addedRange != null;
        buf.append(")");
        setPreviewText(buf.toString());
        final MarkupModel markupModel = DocumentMarkupModel.forDocument(getPreviewEditor().getDocument(), myProject, true);
        markupModel.removeAllHighlighters();
        for (TextRange textRange : ranges2Remove) {
            markupModel.addRangeHighlighter(textRange.getStartOffset(), textRange.getEndOffset(), 0, getTestAttributesForRemoval(), HighlighterTargetArea.EXACT_RANGE);
        }
        markupModel.addRangeHighlighter(addedRange.getStartOffset(), addedRange.getEndOffset(), 0, getTextAttributesForAdd(), HighlighterTargetArea.EXACT_RANGE);
    //revalidate();
    }
}
Also used : PsiParameter(com.intellij.psi.PsiParameter) PsiMethod(com.intellij.psi.PsiMethod) ArrayList(java.util.ArrayList) TIntArrayList(gnu.trove.TIntArrayList) TextRange(com.intellij.openapi.util.TextRange) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel) MarkupModel(com.intellij.openapi.editor.markup.MarkupModel) PsiElement(com.intellij.psi.PsiElement)

Example 3 with MarkupModel

use of com.intellij.openapi.editor.markup.MarkupModel in project intellij-community by JetBrains.

the class LineStatusTracker method createHighlighter.

@Override
@CalledInAwt
protected void createHighlighter(@NotNull Range range) {
    myApplication.assertIsDispatchThread();
    if (range.getHighlighter() != null) {
        LOG.error("Multiple highlighters registered for the same Range");
        return;
    }
    if (myMode == Mode.SILENT)
        return;
    int first = range.getLine1() >= getLineCount(myDocument) ? myDocument.getTextLength() : myDocument.getLineStartOffset(range.getLine1());
    int second = range.getLine2() >= getLineCount(myDocument) ? myDocument.getTextLength() : myDocument.getLineStartOffset(range.getLine2());
    MarkupModel markupModel = DocumentMarkupModel.forDocument(myDocument, myProject, true);
    RangeHighlighter highlighter = LineStatusMarkerRenderer.createRangeHighlighter(range, new TextRange(first, second), markupModel);
    highlighter.setLineMarkerRenderer(LineStatusMarkerRenderer.createRenderer(range, (editor) -> {
        return new LineStatusTrackerDrawing.MyLineStatusMarkerPopup(this, editor, range);
    }));
    highlighter.setEditorFilter(MarkupEditorFilterFactory.createIsNotDiffFilter());
    range.setHighlighter(highlighter);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) Key(com.intellij.openapi.util.Key) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) DiffUtil.getLineCount(com.intellij.diff.util.DiffUtil.getLineCount) TextRange(com.intellij.openapi.util.TextRange) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel) FileEditor(com.intellij.openapi.fileEditor.FileEditor) MarkupModel(com.intellij.openapi.editor.markup.MarkupModel) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) EditorNotificationPanel(com.intellij.ui.EditorNotificationPanel) List(java.util.List) VcsDirtyScopeManager(com.intellij.openapi.vcs.changes.VcsDirtyScopeManager) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) Project(com.intellij.openapi.project.Project) MarkupEditorFilterFactory(com.intellij.openapi.editor.markup.MarkupEditorFilterFactory) NotNull(org.jetbrains.annotations.NotNull) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl) CalledInAwt(org.jetbrains.annotations.CalledInAwt) TransactionGuard(com.intellij.openapi.application.TransactionGuard) javax.swing(javax.swing) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) TextRange(com.intellij.openapi.util.TextRange) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel) MarkupModel(com.intellij.openapi.editor.markup.MarkupModel) CalledInAwt(org.jetbrains.annotations.CalledInAwt)

Example 4 with MarkupModel

use of com.intellij.openapi.editor.markup.MarkupModel in project intellij-community by JetBrains.

the class BreakpointItem method showInEditor.

protected static void showInEditor(DetailView panel, VirtualFile virtualFile, int line) {
    TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(DebuggerColors.BREAKPOINT_ATTRIBUTES);
    DetailView.PreviewEditorState state = DetailView.PreviewEditorState.create(virtualFile, line, attributes);
    if (state.equals(panel.getEditorState())) {
        return;
    }
    panel.navigateInPreviewEditor(state);
    TextAttributes softerAttributes = attributes.clone();
    Color backgroundColor = softerAttributes.getBackgroundColor();
    if (backgroundColor != null) {
        softerAttributes.setBackgroundColor(ColorUtil.softer(backgroundColor));
    }
    final Editor editor = panel.getEditor();
    if (editor != null) {
        final MarkupModel editorModel = editor.getMarkupModel();
        final MarkupModel documentModel = DocumentMarkupModel.forDocument(editor.getDocument(), editor.getProject(), false);
        for (RangeHighlighter highlighter : documentModel.getAllHighlighters()) {
            if (highlighter.getUserData(DebuggerColors.BREAKPOINT_HIGHLIGHTER_KEY) == Boolean.TRUE) {
                final int line1 = editor.offsetToLogicalPosition(highlighter.getStartOffset()).line;
                if (line1 != line) {
                    editorModel.addLineHighlighter(line1, DebuggerColors.BREAKPOINT_HIGHLIGHTER_LAYER + 1, softerAttributes);
                }
            }
        }
    }
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) DetailView(com.intellij.ui.popup.util.DetailView) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) Editor(com.intellij.openapi.editor.Editor) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel) MarkupModel(com.intellij.openapi.editor.markup.MarkupModel)

Example 5 with MarkupModel

use of com.intellij.openapi.editor.markup.MarkupModel in project intellij-community by JetBrains.

the class UnifiedEditorRangeHighlighter method apply.

public void apply(@Nullable Project project, @NotNull Document document) {
    MarkupModel model = DocumentMarkupModel.forDocument(document, project, true);
    for (Element piece : myPieces) {
        RangeHighlighterEx delegate = piece.getDelegate();
        if (!delegate.isValid())
            continue;
        RangeHighlighter highlighter = model.addRangeHighlighter(piece.getStart(), piece.getEnd(), delegate.getLayer(), delegate.getTextAttributes(), delegate.getTargetArea());
        highlighter.setEditorFilter(delegate.getEditorFilter());
        highlighter.setCustomRenderer(delegate.getCustomRenderer());
        highlighter.setErrorStripeMarkColor(delegate.getErrorStripeMarkColor());
        highlighter.setErrorStripeTooltip(delegate.getErrorStripeTooltip());
        highlighter.setGutterIconRenderer(delegate.getGutterIconRenderer());
        highlighter.setLineMarkerRenderer(delegate.getLineMarkerRenderer());
        highlighter.setLineSeparatorColor(delegate.getLineSeparatorColor());
        highlighter.setThinErrorStripeMark(delegate.isThinErrorStripeMark());
        highlighter.setLineSeparatorPlacement(delegate.getLineSeparatorPlacement());
        highlighter.setLineSeparatorRenderer(delegate.getLineSeparatorRenderer());
    }
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel) MarkupModel(com.intellij.openapi.editor.markup.MarkupModel)

Aggregations

MarkupModel (com.intellij.openapi.editor.markup.MarkupModel)23 DocumentMarkupModel (com.intellij.openapi.editor.impl.DocumentMarkupModel)12 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)10 Editor (com.intellij.openapi.editor.Editor)8 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)8 Project (com.intellij.openapi.project.Project)8 TextRange (com.intellij.openapi.util.TextRange)8 List (java.util.List)6 NotNull (org.jetbrains.annotations.NotNull)5 Document (com.intellij.openapi.editor.Document)4 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)4 ArrayList (java.util.ArrayList)4 javax.swing (javax.swing)4 Segment (com.intellij.openapi.util.Segment)3 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)2 EditorFactory (com.intellij.openapi.editor.EditorFactory)2 EditorEx (com.intellij.openapi.editor.ex.EditorEx)2 MarkupModelEx (com.intellij.openapi.editor.ex.MarkupModelEx)2 RangeHighlighterEx (com.intellij.openapi.editor.ex.RangeHighlighterEx)2 EditorUtil (com.intellij.openapi.editor.ex.util.EditorUtil)2