Search in sources :

Example 11 with EditorColorsManager

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

the class RemoveUnusedVariableFix method showSideEffectsWarning.

public static RemoveUnusedVariableUtil.RemoveMode showSideEffectsWarning(List<PsiElement> sideEffects, PsiVariable variable, Editor editor, boolean canCopeWithSideEffects, @NonNls String beforeText, @NonNls String afterText) {
    if (sideEffects.isEmpty())
        return RemoveUnusedVariableUtil.RemoveMode.DELETE_ALL;
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        return canCopeWithSideEffects ? RemoveUnusedVariableUtil.RemoveMode.MAKE_STATEMENT : RemoveUnusedVariableUtil.RemoveMode.DELETE_ALL;
    }
    Project project = editor.getProject();
    HighlightManager highlightManager = HighlightManager.getInstance(project);
    PsiElement[] elements = PsiUtilCore.toPsiElementArray(sideEffects);
    EditorColorsManager manager = EditorColorsManager.getInstance();
    TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
    highlightManager.addOccurrenceHighlights(editor, elements, attributes, true, null);
    SideEffectWarningDialog dialog = new SideEffectWarningDialog(project, false, variable, beforeText, afterText, canCopeWithSideEffects);
    dialog.show();
    int code = dialog.getExitCode();
    return RemoveUnusedVariableUtil.RemoveMode.values()[code];
}
Also used : Project(com.intellij.openapi.project.Project) HighlightManager(com.intellij.codeInsight.highlighting.HighlightManager) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager)

Example 12 with EditorColorsManager

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

the class HighlightUsagesHandler method highlightOtherOccurrences.

public static void highlightOtherOccurrences(final List<PsiElement> otherOccurrences, Editor editor, boolean clearHighlights) {
    EditorColorsManager manager = EditorColorsManager.getInstance();
    TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
    PsiElement[] elements = PsiUtilCore.toPsiElementArray(otherOccurrences);
    doHighlightElements(editor, elements, attributes, clearHighlights);
}
Also used : TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement)

Example 13 with EditorColorsManager

use of com.intellij.openapi.editor.colors.EditorColorsManager 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 14 with EditorColorsManager

use of com.intellij.openapi.editor.colors.EditorColorsManager 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 15 with EditorColorsManager

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

the class InplaceRefactoring method highlightTemplateVariables.

private void highlightTemplateVariables(Template template, Editor topLevelEditor) {
    //add highlights
    if (myHighlighters != null) {
        // can be null if finish is called during testing
        Map<TextRange, TextAttributes> rangesToHighlight = new HashMap<>();
        final TemplateState templateState = TemplateManagerImpl.getTemplateState(topLevelEditor);
        if (templateState != null) {
            EditorColorsManager colorsManager = EditorColorsManager.getInstance();
            for (int i = 0; i < templateState.getSegmentsCount(); i++) {
                final TextRange segmentOffset = templateState.getSegmentRange(i);
                final String name = template.getSegmentName(i);
                TextAttributes attributes = null;
                if (name.equals(PRIMARY_VARIABLE_NAME)) {
                    attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.WRITE_SEARCH_RESULT_ATTRIBUTES);
                } else if (name.equals(OTHER_VARIABLE_NAME)) {
                    attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
                }
                if (attributes == null)
                    continue;
                rangesToHighlight.put(segmentOffset, attributes);
            }
        }
        addHighlights(rangesToHighlight, topLevelEditor, myHighlighters, HighlightManager.getInstance(myProject));
    }
}
Also used : TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) TemplateState(com.intellij.codeInsight.template.impl.TemplateState) RelativePoint(com.intellij.ui.awt.RelativePoint)

Aggregations

EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)43 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)37 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)22 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)14 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)9 Editor (com.intellij.openapi.editor.Editor)7 Project (com.intellij.openapi.project.Project)7 TextRange (com.intellij.openapi.util.TextRange)7 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)6 ArrayList (java.util.ArrayList)6 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)4 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)3 WindowManager (com.intellij.openapi.wm.WindowManager)3 PsiElement (com.intellij.psi.PsiElement)3 Nullable (org.jetbrains.annotations.Nullable)3 FindManager (com.intellij.find.FindManager)2 FindModel (com.intellij.find.FindModel)2 Application (com.intellij.openapi.application.Application)2 Document (com.intellij.openapi.editor.Document)2 StatusBar (com.intellij.openapi.wm.StatusBar)2