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);
});
}
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();
}
}
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);
}
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);
}
}
}
}
}
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());
}
}
Aggregations