Return a color settings page of base attribute without a need to use a modified API

This commit is contained in:
Rustam Vishnyakov
2013-01-10 17:33:45 +04:00
parent f5bc5025df
commit dc450546f6
7 changed files with 48 additions and 67 deletions
@@ -16,7 +16,6 @@
package com.intellij.openapi.options.colors;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import org.jetbrains.annotations.Nullable;
/**
* Describes a text attribute key the attributes for which can be configured in a custom
@@ -27,20 +26,6 @@ import org.jetbrains.annotations.Nullable;
public final class AttributesDescriptor {
private final TextAttributesKey myKey;
private final String myDisplayName;
private ColorSettingsPage mySettingsPage;
/**
* Creates an attribute descriptor with the specified name and text attributes key.
*
* @param settingsPage The settings page hosting the attribute.
* @param displayName the name of the attribute shown in the colors list.
* @param key the attributes key for which the colors are specified.
*/
public AttributesDescriptor(ColorSettingsPage settingsPage, String displayName, TextAttributesKey key) {
myKey = key;
myDisplayName = displayName;
mySettingsPage = settingsPage;
}
/**
* Creates an attribute descriptor with the specified name and text attributes key.
@@ -70,12 +55,4 @@ public final class AttributesDescriptor {
public String getDisplayName() {
return myDisplayName;
}
/**
* @return The settings page hosting the attribute.
*/
@Nullable
public ColorSettingsPage getSettingsPage() {
return mySettingsPage;
}
}
@@ -17,6 +17,7 @@ package com.intellij.openapi.options.colors;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.util.Pair;
import org.jetbrains.annotations.Nullable;
/**
@@ -49,6 +50,6 @@ public abstract class ColorSettingsPages {
public abstract ColorSettingsPage[] getRegisteredPages();
@Nullable
public abstract AttributesDescriptor getAttributeDescriptor(TextAttributesKey key);
public abstract Pair<ColorSettingsPage,AttributesDescriptor> getAttributeDescriptor(TextAttributesKey key);
}
@@ -20,6 +20,8 @@ import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.markup.EffectType;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.options.colors.AttributesDescriptor;
import com.intellij.openapi.options.colors.ColorSettingsPage;
import com.intellij.openapi.util.Pair;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
@@ -225,7 +227,7 @@ public abstract class ColorAndFontDescription extends TextAttributes implements
}
@Nullable
public AttributesDescriptor getBaseAttributeDescriptor() {
public Pair<ColorSettingsPage,AttributesDescriptor> getBaseAttributeDescriptor() {
return null;
}
}
@@ -18,6 +18,7 @@ package com.intellij.application.options.colors;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.options.colors.AttributesDescriptor;
import com.intellij.openapi.options.colors.ColorSettingsPage;
import com.intellij.openapi.util.Pair;
import com.intellij.ui.ListCellRendererWrapper;
import com.intellij.openapi.application.ApplicationBundle;
import com.intellij.openapi.diagnostic.Logger;
@@ -397,12 +398,12 @@ public class ColorAndFontDescriptionPanel extends JPanel {
if (description.isInherited()) {
myInheritanceLabel.setIcon(INHERITED_ICON);
AttributesDescriptor baseDescriptor = description.getBaseAttributeDescriptor();
Pair<ColorSettingsPage,AttributesDescriptor> baseDescriptor = description.getBaseAttributeDescriptor();
String attrName = "?";
String pageName = "?";
if (baseDescriptor != null && baseDescriptor.getDisplayName() != null) {
attrName = baseDescriptor.getDisplayName();
ColorSettingsPage settingsPage = baseDescriptor.getSettingsPage();
if (baseDescriptor != null && baseDescriptor.second.getDisplayName() != null) {
attrName = baseDescriptor.second.getDisplayName();
ColorSettingsPage settingsPage = baseDescriptor.first;
if (settingsPage != null) {
pageName = settingsPage.getDisplayName();
}
@@ -760,7 +760,7 @@ public class ColorAndFontOptions extends SearchableConfigurable.Parent.Abstract
private final TextAttributes myAttributesToApply;
private final TextAttributesKey key;
private TextAttributes myFallbackAttributes;
private AttributesDescriptor myBaseAttributeDescriptor;
private Pair<ColorSettingsPage,AttributesDescriptor> myBaseAttributeDescriptor;
private SchemeTextAttributesDescription(String name, String group, TextAttributesKey key, MyColorScheme scheme, Icon icon,
String toolTip) {
@@ -774,7 +774,8 @@ public class ColorAndFontOptions extends SearchableConfigurable.Parent.Abstract
myFallbackAttributes = scheme.getAttributes(fallbackKey);
myBaseAttributeDescriptor = ColorSettingsPages.getInstance().getAttributeDescriptor(fallbackKey);
if (myBaseAttributeDescriptor == null) {
myBaseAttributeDescriptor = new AttributesDescriptor(fallbackKey.getExternalName(), fallbackKey);
myBaseAttributeDescriptor =
new Pair<ColorSettingsPage, AttributesDescriptor>(null, new AttributesDescriptor(fallbackKey.getExternalName(), fallbackKey));
}
}
initCheckedStatus();
@@ -819,7 +820,7 @@ public class ColorAndFontOptions extends SearchableConfigurable.Parent.Abstract
@Nullable
@Override
public AttributesDescriptor getBaseAttributeDescriptor() {
public Pair<ColorSettingsPage,AttributesDescriptor> getBaseAttributeDescriptor() {
return myBaseAttributeDescriptor;
}
}
@@ -20,6 +20,7 @@ import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.options.colors.AttributesDescriptor;
import com.intellij.openapi.options.colors.ColorSettingsPage;
import com.intellij.openapi.options.colors.ColorSettingsPages;
import com.intellij.openapi.util.Pair;
import org.jetbrains.annotations.Nullable;
import java.util.*;
@@ -27,7 +28,8 @@ import java.util.*;
public class ColorSettingsPagesImpl extends ColorSettingsPages {
private final List<ColorSettingsPage> myPages = new ArrayList<ColorSettingsPage>();
private boolean myExtensionsLoaded = false;
private Map<TextAttributesKey, AttributesDescriptor> myKeyToDescriptorMap = new HashMap<TextAttributesKey,AttributesDescriptor>();
private Map<TextAttributesKey, Pair<ColorSettingsPage, AttributesDescriptor>> myKeyToDescriptorMap =
new HashMap<TextAttributesKey, Pair<ColorSettingsPage, AttributesDescriptor>>();
@Override
public void registerPage(ColorSettingsPage page) {
@@ -45,7 +47,7 @@ public class ColorSettingsPagesImpl extends ColorSettingsPages {
@Override
@Nullable
public AttributesDescriptor getAttributeDescriptor(TextAttributesKey key) {
public Pair<ColorSettingsPage,AttributesDescriptor> getAttributeDescriptor(TextAttributesKey key) {
if (myKeyToDescriptorMap.containsKey(key)) {
return myKeyToDescriptorMap.get(key);
}
@@ -53,8 +55,9 @@ public class ColorSettingsPagesImpl extends ColorSettingsPages {
for (ColorSettingsPage page : getRegisteredPages()) {
for (AttributesDescriptor descriptor : page.getAttributeDescriptors()) {
if (descriptor.getKey() == key) {
myKeyToDescriptorMap.put(key, descriptor);
return descriptor;
Pair<ColorSettingsPage,AttributesDescriptor> result = new Pair<ColorSettingsPage, AttributesDescriptor>(page, descriptor);
myKeyToDescriptorMap.put(key, result);
return result;
}
}
}
@@ -68,36 +68,32 @@ public class DefaultLanguageColorsPage implements ColorSettingsPage, DisplayPrio
TAG_HIGHLIGHTING_MAP.put("static_field", DefaultLanguageHighlighterColors.STATIC_FIELD);
}
private final AttributesDescriptor[] myAttributesDescriptors;
public DefaultLanguageColorsPage() {
myAttributesDescriptors = new AttributesDescriptor[]{
new AttributesDescriptor(this, "Keyword", DefaultLanguageHighlighterColors.KEYWORD),
new AttributesDescriptor(this, "Identifier", DefaultLanguageHighlighterColors.IDENTIFIER),
new AttributesDescriptor(this, "String", DefaultLanguageHighlighterColors.STRING),
new AttributesDescriptor(this, "Number", DefaultLanguageHighlighterColors.NUMBER),
new AttributesDescriptor(this, "Operation sign", DefaultLanguageHighlighterColors.OPERATION_SIGN),
new AttributesDescriptor(this, "Braces", DefaultLanguageHighlighterColors.BRACES),
new AttributesDescriptor(this, "Parentheses", DefaultLanguageHighlighterColors.PARENTHESES),
new AttributesDescriptor(this, "Brackets", DefaultLanguageHighlighterColors.BRACKETS),
new AttributesDescriptor(this, "Dot", DefaultLanguageHighlighterColors.DOT),
new AttributesDescriptor(this, "Comma", DefaultLanguageHighlighterColors.COMMA),
new AttributesDescriptor(this, "Semicolon", DefaultLanguageHighlighterColors.SEMICOLON),
new AttributesDescriptor(this, "Line comment", DefaultLanguageHighlighterColors.LINE_COMMENT),
new AttributesDescriptor(this, "Block comment", DefaultLanguageHighlighterColors.BLOCk_COMMENT),
new AttributesDescriptor(this, "Doc comment", DefaultLanguageHighlighterColors.DOC_COMMENT),
new AttributesDescriptor(this, "Function declaration", DefaultLanguageHighlighterColors.FUNCTION_DECLARATION),
new AttributesDescriptor(this, "Function call", DefaultLanguageHighlighterColors.FUNCTION_CALL),
new AttributesDescriptor(this, "Parameter", DefaultLanguageHighlighterColors.PARAMETER),
new AttributesDescriptor(this, "Class name", DefaultLanguageHighlighterColors.CLASS_NAME),
new AttributesDescriptor(this, "Class reference", DefaultLanguageHighlighterColors.CLASS_REFERENCE),
new AttributesDescriptor(this, "Instance method", DefaultLanguageHighlighterColors.INSTANCE_METHOD),
new AttributesDescriptor(this, "Instance field", DefaultLanguageHighlighterColors.INSTANCE_FIELD),
new AttributesDescriptor(this, "Static method", DefaultLanguageHighlighterColors.STATIC_METHOD),
new AttributesDescriptor(this, "Static field", DefaultLanguageHighlighterColors.STATIC_FIELD),
new AttributesDescriptor(this, "Template language", DefaultLanguageHighlighterColors.TEMPLATE_LANGUAGE_COLOR),
};
}
private final static AttributesDescriptor[] ATTRIBUTES_DESCRIPTORS = {
new AttributesDescriptor("Keyword", DefaultLanguageHighlighterColors.KEYWORD),
new AttributesDescriptor("Identifier", DefaultLanguageHighlighterColors.IDENTIFIER),
new AttributesDescriptor("String", DefaultLanguageHighlighterColors.STRING),
new AttributesDescriptor("Number", DefaultLanguageHighlighterColors.NUMBER),
new AttributesDescriptor("Operation sign", DefaultLanguageHighlighterColors.OPERATION_SIGN),
new AttributesDescriptor("Braces", DefaultLanguageHighlighterColors.BRACES),
new AttributesDescriptor("Parentheses", DefaultLanguageHighlighterColors.PARENTHESES),
new AttributesDescriptor("Brackets", DefaultLanguageHighlighterColors.BRACKETS),
new AttributesDescriptor("Dot", DefaultLanguageHighlighterColors.DOT),
new AttributesDescriptor("Comma", DefaultLanguageHighlighterColors.COMMA),
new AttributesDescriptor("Semicolon", DefaultLanguageHighlighterColors.SEMICOLON),
new AttributesDescriptor("Line comment", DefaultLanguageHighlighterColors.LINE_COMMENT),
new AttributesDescriptor("Block comment", DefaultLanguageHighlighterColors.BLOCk_COMMENT),
new AttributesDescriptor("Doc comment", DefaultLanguageHighlighterColors.DOC_COMMENT),
new AttributesDescriptor("Function declaration", DefaultLanguageHighlighterColors.FUNCTION_DECLARATION),
new AttributesDescriptor("Function call", DefaultLanguageHighlighterColors.FUNCTION_CALL),
new AttributesDescriptor("Parameter", DefaultLanguageHighlighterColors.PARAMETER),
new AttributesDescriptor("Class name", DefaultLanguageHighlighterColors.CLASS_NAME),
new AttributesDescriptor("Class reference", DefaultLanguageHighlighterColors.CLASS_REFERENCE),
new AttributesDescriptor("Instance method", DefaultLanguageHighlighterColors.INSTANCE_METHOD),
new AttributesDescriptor("Instance field", DefaultLanguageHighlighterColors.INSTANCE_FIELD),
new AttributesDescriptor("Static method", DefaultLanguageHighlighterColors.STATIC_METHOD),
new AttributesDescriptor("Static field", DefaultLanguageHighlighterColors.STATIC_FIELD),
new AttributesDescriptor("Template language", DefaultLanguageHighlighterColors.TEMPLATE_LANGUAGE_COLOR),
};
@Nullable
@Override
@@ -146,7 +142,7 @@ public class DefaultLanguageColorsPage implements ColorSettingsPage, DisplayPrio
@NotNull
@Override
public AttributesDescriptor[] getAttributeDescriptors() {
return myAttributesDescriptors;
return ATTRIBUTES_DESCRIPTORS;
}
@NotNull