Search in sources :

Example 61 with TextAttributes

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

the class HighlightUsagesHandlerBase method performHighlighting.

protected void performHighlighting() {
    boolean clearHighlights = HighlightUsagesHandler.isClearHighlights(myEditor);
    EditorColorsManager manager = EditorColorsManager.getInstance();
    TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
    TextAttributes writeAttributes = manager.getGlobalScheme().getAttributes(EditorColors.WRITE_SEARCH_RESULT_ATTRIBUTES);
    HighlightUsagesHandler.highlightRanges(HighlightManager.getInstance(myEditor.getProject()), myEditor, attributes, clearHighlights, myReadUsages);
    HighlightUsagesHandler.highlightRanges(HighlightManager.getInstance(myEditor.getProject()), myEditor, writeAttributes, clearHighlights, myWriteUsages);
    if (!clearHighlights) {
        WindowManager.getInstance().getStatusBar(myEditor.getProject()).setInfo(myStatusText);
        // enable f3 navigation
        HighlightHandlerBase.setupFindModel(myEditor.getProject());
    }
    if (myHintText != null) {
        HintManager.getInstance().showInformationHint(myEditor, myHintText);
    }
}
Also used : TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager)

Example 62 with TextAttributes

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

the class SeverityEditorDialog method doOKAction.

@Override
protected void doOKAction() {
    apply((SeverityBasedTextAttributes) myOptionsList.getSelectedValue());
    final Collection<SeverityBasedTextAttributes> infoTypes = new HashSet<>(SeverityUtil.getRegisteredHighlightingInfoTypes(mySeverityRegistrar));
    final ListModel listModel = myOptionsList.getModel();
    final List<HighlightSeverity> order = new ArrayList<>();
    for (int i = listModel.getSize() - 1; i >= 0; i--) {
        SeverityBasedTextAttributes info = (SeverityBasedTextAttributes) listModel.getElementAt(i);
        order.add(info.getSeverity());
        if (!mySeverityRegistrar.isDefaultSeverity(info.getSeverity())) {
            infoTypes.remove(info);
            final Color stripeColor = info.getAttributes().getErrorStripeColor();
            final boolean exists = mySeverityRegistrar.getSeverity(info.getSeverity().getName()) != null;
            if (exists) {
                info.getType().getAttributesKey().getDefaultAttributes().setErrorStripeColor(stripeColor);
            } else {
                HighlightInfoType.HighlightInfoTypeImpl type = info.getType();
                TextAttributesKey key = type.getAttributesKey();
                final TextAttributes defaultAttributes = key.getDefaultAttributes().clone();
                defaultAttributes.setErrorStripeColor(stripeColor);
                key = TextAttributesKey.createTextAttributesKey(key.getExternalName(), defaultAttributes);
                type = new HighlightInfoType.HighlightInfoTypeImpl(type.getSeverity(null), key);
                info = new SeverityBasedTextAttributes(info.getAttributes(), type);
            }
            mySeverityRegistrar.registerSeverity(info, stripeColor != null ? stripeColor : LightColors.YELLOW);
        }
    }
    for (SeverityBasedTextAttributes info : infoTypes) {
        mySeverityRegistrar.unregisterSeverity(info.getSeverity());
    }
    mySeverityRegistrar.setOrder(order);
    super.doOKAction();
}
Also used : HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) HighlightInfoType(com.intellij.codeInsight.daemon.impl.HighlightInfoType) SeverityBasedTextAttributes(com.intellij.codeInsight.daemon.impl.SeverityRegistrar.SeverityBasedTextAttributes) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) SeverityBasedTextAttributes(com.intellij.codeInsight.daemon.impl.SeverityRegistrar.SeverityBasedTextAttributes)

Example 63 with TextAttributes

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

the class FindUtil method doSearch.

@Nullable
private static FindResult doSearch(@NotNull Project project, @NotNull final Editor editor, int offset, boolean toWarn, @NotNull FindModel model, boolean adjustEditor) {
    FindManager findManager = FindManager.getInstance(project);
    Document document = editor.getDocument();
    final FindResult result = findManager.findString(document.getCharsSequence(), offset, model, getVirtualFile(editor));
    boolean isFound = result.isStringFound();
    final SelectionModel selection = editor.getSelectionModel();
    if (isFound && !model.isGlobal()) {
        if (!selectionMayContainRange(selection, result)) {
            isFound = false;
        } else if (!selectionStrictlyContainsRange(selection, result)) {
            final int[] starts = selection.getBlockSelectionStarts();
            for (int newOffset : starts) {
                if (newOffset > result.getStartOffset()) {
                    return doSearch(project, editor, newOffset, toWarn, model, adjustEditor);
                }
            }
        }
    }
    if (!isFound) {
        if (toWarn) {
            processNotFound(editor, model.getStringToFind(), model, project);
        }
        return null;
    }
    if (adjustEditor) {
        final CaretModel caretModel = editor.getCaretModel();
        final ScrollingModel scrollingModel = editor.getScrollingModel();
        int oldCaretOffset = caretModel.getOffset();
        boolean forward = oldCaretOffset < result.getStartOffset();
        final ScrollType scrollType = forward ? ScrollType.CENTER_DOWN : ScrollType.CENTER_UP;
        if (model.isGlobal()) {
            int targetCaretPosition = result.getEndOffset();
            if (selection.getSelectionEnd() - selection.getSelectionStart() == result.getLength()) {
                // keeping caret's position relative to selection
                // use case: FindNext is used after SelectNextOccurrence action
                targetCaretPosition = caretModel.getOffset() - selection.getSelectionStart() + result.getStartOffset();
            }
            if (caretModel.getCaretAt(editor.offsetToVisualPosition(targetCaretPosition)) != null) {
                // use case: FindNext is used after SelectNextOccurrence action
                return result;
            }
            caretModel.moveToOffset(targetCaretPosition);
            selection.removeSelection();
            scrollingModel.scrollToCaret(scrollType);
            scrollingModel.runActionOnScrollingFinished(() -> {
                scrollingModel.scrollTo(editor.offsetToLogicalPosition(result.getStartOffset()), scrollType);
                scrollingModel.scrollTo(editor.offsetToLogicalPosition(result.getEndOffset()), scrollType);
            });
        } else {
            moveCaretAndDontChangeSelection(editor, result.getStartOffset(), scrollType);
            moveCaretAndDontChangeSelection(editor, result.getEndOffset(), scrollType);
        }
        IdeDocumentHistory.getInstance(project).includeCurrentCommandAsNavigation();
        EditorColorsManager manager = EditorColorsManager.getInstance();
        TextAttributes selectionAttributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
        if (!model.isGlobal()) {
            final RangeHighlighterEx segmentHighlighter = (RangeHighlighterEx) editor.getMarkupModel().addRangeHighlighter(result.getStartOffset(), result.getEndOffset(), HighlighterLayer.SELECTION + 1, selectionAttributes, HighlighterTargetArea.EXACT_RANGE);
            MyListener listener = new MyListener(editor, segmentHighlighter);
            caretModel.addCaretListener(listener);
        } else {
            selection.setSelection(result.getStartOffset(), result.getEndOffset());
        }
    }
    return result;
}
Also used : EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) LightweightHint(com.intellij.ui.LightweightHint) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) Nullable(org.jetbrains.annotations.Nullable)

Example 64 with TextAttributes

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

the class SearchEverywherePsiRenderer method customizeNonPsiElementLeftRenderer.

@Override
protected boolean customizeNonPsiElementLeftRenderer(ColoredListCellRenderer renderer, JList list, Object value, int index, boolean selected, boolean hasFocus) {
    if (!(value instanceof NavigationItem))
        return false;
    NavigationItem item = (NavigationItem) value;
    TextAttributes attributes = getNavigationItemAttributes(item);
    SimpleTextAttributes nameAttributes = attributes != null ? SimpleTextAttributes.fromTextAttributes(attributes) : null;
    Color color = list.getForeground();
    if (nameAttributes == null)
        nameAttributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, color);
    renderer.append(item + " ", nameAttributes);
    ItemPresentation itemPresentation = item.getPresentation();
    assert itemPresentation != null;
    renderer.setIcon(itemPresentation.getIcon(true));
    String locationString = itemPresentation.getLocationString();
    if (!StringUtil.isEmpty(locationString)) {
        renderer.append(locationString, new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, JBColor.GRAY));
    }
    return true;
}
Also used : NavigationItem(com.intellij.navigation.NavigationItem) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) JBColor(com.intellij.ui.JBColor) ItemPresentation(com.intellij.navigation.ItemPresentation) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes)

Example 65 with TextAttributes

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

the class ModuleToDoNode method update.

@Override
public void update(PresentationData presentation) {
    if (DumbService.getInstance(getProject()).isDumb())
        return;
    String newName = getValue().getName();
    int nameEndOffset = newName.length();
    int todoItemCount = getTodoItemCount(getValue());
    int fileCount = getFileCount(getValue());
    newName = IdeBundle.message("node.todo.group", newName, todoItemCount, fileCount);
    myHighlightedRegions.clear();
    TextAttributes textAttributes = new TextAttributes();
    if (CopyPasteManager.getInstance().isCutElement(getValue())) {
        textAttributes.setForegroundColor(CopyPasteManager.CUT_COLOR);
    }
    myHighlightedRegions.add(new HighlightedRegion(0, nameEndOffset, textAttributes));
    EditorColorsScheme colorsScheme = UsageTreeColorsScheme.getInstance().getScheme();
    myHighlightedRegions.add(new HighlightedRegion(nameEndOffset, newName.length(), colorsScheme.getAttributes(UsageTreeColors.NUMBER_OF_USAGES)));
    presentation.setIcon(ModuleType.get(getValue()).getIcon());
    presentation.setPresentableText(newName);
}
Also used : TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) HighlightedRegion(com.intellij.ui.HighlightedRegion) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme)

Aggregations

TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)205 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)40 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)31 NotNull (org.jetbrains.annotations.NotNull)29 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)28 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)26 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)26 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)23 TextRange (com.intellij.openapi.util.TextRange)21 Nullable (org.jetbrains.annotations.Nullable)21 ArrayList (java.util.ArrayList)19 Editor (com.intellij.openapi.editor.Editor)18 Project (com.intellij.openapi.project.Project)17 PsiElement (com.intellij.psi.PsiElement)12 HighlightInfoType (com.intellij.codeInsight.daemon.impl.HighlightInfoType)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 JBColor (com.intellij.ui.JBColor)10 Document (com.intellij.openapi.editor.Document)9 ContainerUtil (com.intellij.util.containers.ContainerUtil)9 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)8