Search in sources :

Example 21 with RangeHighlighter

use of com.intellij.openapi.editor.markup.RangeHighlighter 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 22 with RangeHighlighter

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

the class IntroduceVariableHandler method getSettings.

@Override
public IntroduceVariableSettings getSettings(Project project, Editor editor, PsiExpression expr, PsiExpression[] occurrences, TypeSelectorManagerImpl typeSelectorManager, boolean declareFinalIfAll, boolean anyAssignmentLHS, final InputValidator validator, PsiElement anchor, JavaReplaceChoice replaceChoice) {
    if (replaceChoice == null && ApplicationManager.getApplication().isUnitTestMode()) {
        replaceChoice = JavaReplaceChoice.NO;
    }
    if (replaceChoice != null) {
        return super.getSettings(project, editor, expr, occurrences, typeSelectorManager, declareFinalIfAll, anyAssignmentLHS, validator, anchor, replaceChoice);
    }
    ArrayList<RangeHighlighter> highlighters = new ArrayList<>();
    HighlightManager highlightManager = null;
    if (editor != null) {
        highlightManager = HighlightManager.getInstance(project);
        EditorColorsManager colorsManager = EditorColorsManager.getInstance();
        TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
        if (occurrences.length > 1) {
            highlightManager.addOccurrenceHighlights(editor, occurrences, attributes, true, highlighters);
        }
    }
    IntroduceVariableDialog dialog = new IntroduceVariableDialog(project, expr, occurrences.length, anyAssignmentLHS, declareFinalIfAll, typeSelectorManager, validator);
    if (!dialog.showAndGet()) {
        if (occurrences.length > 1) {
            WindowManager.getInstance().getStatusBar(project).setInfo(RefactoringBundle.message("press.escape.to.remove.the.highlighting"));
        }
    } else {
        if (editor != null) {
            for (RangeHighlighter highlighter : highlighters) {
                highlightManager.removeSegmentHighlighter(editor, highlighter);
            }
        }
    }
    return dialog;
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) HighlightManager(com.intellij.codeInsight.highlighting.HighlightManager) ArrayList(java.util.ArrayList) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager)

Example 23 with RangeHighlighter

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

the class MultipleJdksHighlightingTest method testInFileReferencesHighlighting2.

public void testInFileReferencesHighlighting2() {
    ModuleRootModificationUtil.addDependency(myJava8Module, myJava7Module);
    myFixture.copyFileToProject("java7/p/List7.java");
    myFixture.configureByFiles("java8/p/" + getTestName(false) + ".java");
    HighlightUsagesHandler.invoke(myFixture.getProject(), myFixture.getEditor(), myFixture.getFile());
    final RangeHighlighter highlighter = assertOneElement(myFixture.getEditor().getMarkupModel().getAllHighlighters());
    assertEquals(60, highlighter.getStartOffset());
    assertEquals(66, highlighter.getEndOffset());
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter)

Example 24 with RangeHighlighter

use of com.intellij.openapi.editor.markup.RangeHighlighter 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 25 with RangeHighlighter

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

the class SimpleDiffChange method destroyHighlighter.

public void destroyHighlighter() {
    for (RangeHighlighter highlighter : myHighlighters) {
        highlighter.dispose();
    }
    myHighlighters.clear();
    for (MyGutterOperation operation : myOperations) {
        operation.dispose();
    }
    myOperations.clear();
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter)

Aggregations

RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)102 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)29 TextRange (com.intellij.openapi.util.TextRange)23 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)18 Editor (com.intellij.openapi.editor.Editor)17 ArrayList (java.util.ArrayList)16 NotNull (org.jetbrains.annotations.NotNull)15 Project (com.intellij.openapi.project.Project)13 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)10 MarkupModel (com.intellij.openapi.editor.markup.MarkupModel)10 Document (com.intellij.openapi.editor.Document)9 RelativePoint (com.intellij.ui.awt.RelativePoint)8 Nullable (org.jetbrains.annotations.Nullable)8 EditorEx (com.intellij.openapi.editor.ex.EditorEx)7 MarkupModelEx (com.intellij.openapi.editor.ex.MarkupModelEx)7 PsiElement (com.intellij.psi.PsiElement)6 EditorWindow (com.intellij.injected.editor.EditorWindow)4 Result (com.intellij.openapi.application.Result)4 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)4 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)4