*/
package com.intellij.execution.filters;
-import com.intellij.openapi.editor.colors.CodeInsightColors;
-import com.intellij.openapi.editor.colors.EditorColorsManager;
+import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.editor.colors.*;
import com.intellij.openapi.editor.markup.TextAttributes;
+import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
/**
* @author Yura Cangea
class Result extends ResultItem {
- private static final TextAttributes INACTIVE_HYPERLINK_ATTRIBUTES;
+ private static final Map<TextAttributesKey, TextAttributes> GRAYED_BY_NORMAL_CACHE = ContainerUtil.newConcurrentMap(2);
static {
- TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.HYPERLINK_ATTRIBUTES);
- if (attributes != null) {
- attributes = attributes.clone();
- attributes.setForegroundColor(UIUtil.getInactiveTextColor());
- attributes.setEffectColor(UIUtil.getInactiveTextColor());
- }
- INACTIVE_HYPERLINK_ATTRIBUTES = attributes;
+ EditorColorsManager.getInstance().addEditorColorsListener(new EditorColorsListener() {
+ @Override
+ public void globalSchemeChange(EditorColorsScheme scheme) {
+ // invalidate cache on Appearance Theme/Editor Scheme change
+ GRAYED_BY_NORMAL_CACHE.clear();
+ }
+ }, ApplicationManager.getApplication());
}
protected NextAction myNextAction = NextAction.EXIT;
final int highlightEndOffset,
@Nullable final HyperlinkInfo hyperlinkInfo,
@Nullable final TextAttributes highlightAttributes) {
- super(highlightStartOffset, highlightEndOffset, hyperlinkInfo, highlightAttributes);
+ super(highlightStartOffset, highlightEndOffset, hyperlinkInfo, highlightAttributes, null);
+ myResultItems = null;
+ }
+
+ public Result(final int highlightStartOffset,
+ final int highlightEndOffset,
+ @Nullable final HyperlinkInfo hyperlinkInfo,
+ @Nullable final TextAttributes highlightAttributes,
+ @Nullable final TextAttributes followedHyperlinkAttributes) {
+ super(highlightStartOffset, highlightEndOffset, hyperlinkInfo, highlightAttributes, followedHyperlinkAttributes);
myResultItems = null;
}
public Result(final int highlightStartOffset,
final int highlightEndOffset,
@Nullable final HyperlinkInfo hyperlinkInfo,
- boolean inactiveHyperlink) {
- super(highlightStartOffset, highlightEndOffset, hyperlinkInfo, inactiveHyperlink ? INACTIVE_HYPERLINK_ATTRIBUTES : null);
+ final boolean grayedHyperlink) {
+ super(highlightStartOffset, highlightEndOffset, hyperlinkInfo,
+ grayedHyperlink ? getGrayedHyperlinkAttributes(CodeInsightColors.HYPERLINK_ATTRIBUTES) : null,
+ grayedHyperlink ? getGrayedHyperlinkAttributes(CodeInsightColors.FOLLOWED_HYPERLINK_ATTRIBUTES) : null);
myResultItems = null;
}
public Result(@NotNull List<ResultItem> resultItems) {
- super(-1, -1, null, null);
+ super(-1, -1, null, null, null);
myResultItems = resultItems;
}
public void setNextAction(NextAction nextAction) {
myNextAction = nextAction;
}
+
+ @Nullable
+ private static TextAttributes getGrayedHyperlinkAttributes(@NotNull TextAttributesKey normalHyperlinkAttrsKey) {
+ EditorColorsScheme globalScheme = EditorColorsManager.getInstance().getGlobalScheme();
+ TextAttributes grayedHyperlinkAttrs = GRAYED_BY_NORMAL_CACHE.get(normalHyperlinkAttrsKey);
+ if (grayedHyperlinkAttrs == null) {
+ TextAttributes normalHyperlinkAttrs = globalScheme.getAttributes(normalHyperlinkAttrsKey);
+ if (normalHyperlinkAttrs != null) {
+ grayedHyperlinkAttrs = normalHyperlinkAttrs.clone();
+ grayedHyperlinkAttrs.setForegroundColor(UIUtil.getInactiveTextColor());
+ grayedHyperlinkAttrs.setEffectColor(UIUtil.getInactiveTextColor());
+ GRAYED_BY_NORMAL_CACHE.put(normalHyperlinkAttrsKey, grayedHyperlinkAttrs);
+ }
+ }
+ return grayedHyperlinkAttrs;
+ }
}
enum NextAction {
@Deprecated @Nullable
public final HyperlinkInfo hyperlinkInfo;
+ private final TextAttributes myFollowedHyperlinkAttributes;
+
@SuppressWarnings("deprecation")
public ResultItem(final int highlightStartOffset, final int highlightEndOffset, @Nullable final HyperlinkInfo hyperlinkInfo) {
- this(highlightStartOffset, highlightEndOffset, hyperlinkInfo, null);
+ this(highlightStartOffset, highlightEndOffset, hyperlinkInfo, null, null);
}
@SuppressWarnings("deprecation")
final int highlightEndOffset,
@Nullable final HyperlinkInfo hyperlinkInfo,
@Nullable final TextAttributes highlightAttributes) {
+ this(highlightStartOffset, highlightEndOffset, hyperlinkInfo, highlightAttributes, null);
+ }
+
+ @SuppressWarnings("deprecation")
+ public ResultItem(final int highlightStartOffset,
+ final int highlightEndOffset,
+ @Nullable final HyperlinkInfo hyperlinkInfo,
+ @Nullable final TextAttributes highlightAttributes,
+ @Nullable final TextAttributes followedHyperlinkAttributes) {
this.highlightStartOffset = highlightStartOffset;
this.highlightEndOffset = highlightEndOffset;
this.hyperlinkInfo = hyperlinkInfo;
this.highlightAttributes = highlightAttributes;
+ myFollowedHyperlinkAttributes = followedHyperlinkAttributes;
}
public int getHighlightStartOffset() {
return highlightAttributes;
}
+ @Nullable
+ public TextAttributes getFollowedHyperlinkAttributes() {
+ return myFollowedHyperlinkAttributes;
+ }
+
@Nullable
public HyperlinkInfo getHyperlinkInfo() {
//noinspection deprecation
}
@NotNull
- public RangeHighlighter createHyperlink(final int highlightStartOffset,
- final int highlightEndOffset,
- @Nullable final TextAttributes highlightAttributes,
- @NotNull final HyperlinkInfo hyperlinkInfo) {
+ public RangeHighlighter createHyperlink(int highlightStartOffset,
+ int highlightEndOffset,
+ @Nullable TextAttributes highlightAttributes,
+ @NotNull HyperlinkInfo hyperlinkInfo) {
+ return createHyperlink(highlightStartOffset, highlightEndOffset, highlightAttributes, hyperlinkInfo, null);
+ }
+
+ @NotNull
+ private RangeHighlighter createHyperlink(final int highlightStartOffset,
+ final int highlightEndOffset,
+ @Nullable final TextAttributes highlightAttributes,
+ @NotNull final HyperlinkInfo hyperlinkInfo,
+ @Nullable TextAttributes followedHyperlinkAttributes) {
TextAttributes textAttributes = highlightAttributes != null ? highlightAttributes : getHyperlinkAttributes();
final RangeHighlighter highlighter = myEditor.getMarkupModel().addRangeHighlighter(highlightStartOffset,
highlightEndOffset,
HYPERLINK_LAYER,
textAttributes,
HighlighterTargetArea.EXACT_RANGE);
- associateHyperlink(highlighter, hyperlinkInfo);
+ associateHyperlink(highlighter, hyperlinkInfo, followedHyperlinkAttributes);
return highlighter;
}
public static void associateHyperlink(@NotNull RangeHighlighter highlighter, @NotNull HyperlinkInfo hyperlinkInfo) {
- highlighter.putUserData(HYPERLINK, new HyperlinkInfoTextAttributes(hyperlinkInfo));
+ associateHyperlink(highlighter, hyperlinkInfo, null);
+ }
+
+ private static void associateHyperlink(@NotNull RangeHighlighter highlighter,
+ @NotNull HyperlinkInfo hyperlinkInfo,
+ @Nullable TextAttributes followedHyperlinkAttributes) {
+ highlighter.putUserData(HYPERLINK, new HyperlinkInfoTextAttributes(hyperlinkInfo, followedHyperlinkAttributes));
}
@Nullable
TextAttributes attributes = resultItem.getHighlightAttributes();
if (resultItem.getHyperlinkInfo() != null) {
- createHyperlink(start, end, attributes, resultItem.getHyperlinkInfo());
+ createHyperlink(start, end, attributes, resultItem.getHyperlinkInfo(), resultItem.getFollowedHyperlinkAttributes());
}
else if (attributes != null) {
addHighlighter(start, end, attributes);
return EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.HYPERLINK_ATTRIBUTES);
}
- private static TextAttributes getFollowedHyperlinkAttributes() {
- return EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.FOLLOWED_HYPERLINK_ATTRIBUTES);
+ @NotNull
+ private static TextAttributes getFollowedHyperlinkAttributes(@NotNull RangeHighlighter range) {
+ HyperlinkInfoTextAttributes attrs = HYPERLINK.get(range);
+ TextAttributes result = attrs != null ? attrs.getFollowedHyperlinkAttributes() : null;
+ if (result == null) {
+ result = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.FOLLOWED_HYPERLINK_ATTRIBUTES);
+ }
+ return result;
}
@Nullable
}
if (range == link) {
range.putUserData(OLD_HYPERLINK_TEXT_ATTRIBUTES, range.getTextAttributes());
- markupModel.setRangeHighlighterAttributes(range, getFollowedHyperlinkAttributes());
+ markupModel.setRangeHighlighterAttributes(range, getFollowedHyperlinkAttributes(range));
}
}
//refresh highlighter text attributes
}
private static class HyperlinkInfoTextAttributes extends TextAttributes {
- private HyperlinkInfo myHyperlinkInfo;
+ private final HyperlinkInfo myHyperlinkInfo;
+ private final TextAttributes myFollowedHyperlinkAttributes;
- public HyperlinkInfoTextAttributes(@NotNull HyperlinkInfo hyperlinkInfo) {
+ public HyperlinkInfoTextAttributes(@NotNull HyperlinkInfo hyperlinkInfo, @Nullable TextAttributes followedHyperlinkAttributes) {
myHyperlinkInfo = hyperlinkInfo;
+ myFollowedHyperlinkAttributes = followedHyperlinkAttributes;
}
@NotNull
public HyperlinkInfo getHyperlinkInfo() {
return myHyperlinkInfo;
}
+
+ @Nullable
+ public TextAttributes getFollowedHyperlinkAttributes() {
+ return myFollowedHyperlinkAttributes;
+ }
}
}