inject inspection colors dynamically into pages that implement InspectionColorSettingsPage

This commit is contained in:
Dmitry Jemerov
2010-01-13 22:32:06 +03:00
parent 1ef6f65bc8
commit 2acc5a54f5
4 changed files with 41 additions and 10 deletions
@@ -133,14 +133,6 @@ public class JavaColorSettingsPage implements ColorSettingsPage, InspectionColor
public AttributesDescriptor[] getAttributeDescriptors() {
List<AttributesDescriptor> descriptors = new ArrayList<AttributesDescriptor>();
descriptors.addAll(Arrays.asList(ourDescriptors));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.unknown.symbol"), CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.deprecated.symbol"), CodeInsightColors.DEPRECATED_ATTRIBUTES));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.unused.symbol"), CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.error"), CodeInsightColors.ERRORS_ATTRIBUTES));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.warning"), CodeInsightColors.WARNINGS_ATTRIBUTES));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.info"), CodeInsightColors.INFO_ATTRIBUTES));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.server.problems"), CodeInsightColors.GENERIC_SERVER_ERROR_OR_WARNING));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.server.duplicate"), CodeInsightColors.DUPLICATE_FROM_SERVER));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.color.descriptor.full.coverage"), CodeInsightColors.LINE_FULL_COVERAGE));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.color.descriptor.partial.coverage"), CodeInsightColors.LINE_PARTIAL_COVERAGE));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.color.descriptor.none.coverage"), CodeInsightColors.LINE_NONE_COVERAGE));
@@ -418,7 +418,7 @@ public class ColorAndFontOptions extends SearchableConfigurable.Parent.Abstract
ArrayList<EditorSchemeAttributeDescriptor> descriptions,
MyColorScheme scheme) {
String group = page.getDisplayName();
AttributesDescriptor[] attributeDescriptors = page.getAttributeDescriptors();
List<AttributesDescriptor> attributeDescriptors = ColorSettingsUtil.getAllAttributeDescriptors(page);
for (AttributesDescriptor descriptor : attributeDescriptors) {
addSchemedDescription(descriptions, descriptor.getDisplayName(), group, descriptor.getKey(), scheme, null, null);
}
@@ -16,14 +16,20 @@
package com.intellij.application.options.colors;
import com.intellij.openapi.editor.colors.CodeInsightColors;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.editor.colors.impl.EditorColorsManagerImpl;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.options.OptionsBundle;
import com.intellij.openapi.options.colors.AttributesDescriptor;
import com.intellij.openapi.options.colors.ColorSettingsPage;
import com.intellij.util.containers.HashMap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
@@ -34,7 +40,7 @@ public class ColorSettingsUtil {
}
public static Map<TextAttributesKey, String> keyToDisplayTextMap(final ColorSettingsPage page) {
final AttributesDescriptor[] attributeDescriptors = page.getAttributeDescriptors();
final List<AttributesDescriptor> attributeDescriptors = getAllAttributeDescriptors(page);
final Map<TextAttributesKey, String> displayText = new HashMap<TextAttributesKey, String>();
for (AttributesDescriptor attributeDescriptor : attributeDescriptors) {
final TextAttributesKey key = attributeDescriptor.getKey();
@@ -43,7 +49,38 @@ public class ColorSettingsUtil {
return displayText;
}
public static List<AttributesDescriptor> getAllAttributeDescriptors(ColorSettingsPage page) {
List<AttributesDescriptor> result = new ArrayList<AttributesDescriptor>();
Collections.addAll(result, page.getAttributeDescriptors());
if (isInspectionColorsPage(page)) {
addInspectionSeverityAttributes(result);
}
return result;
}
private static boolean isInspectionColorsPage(ColorSettingsPage page) {
// the first registered page implementing InspectionColorSettingsPage
// gets the inspection attribute descriptors added to its list
if (!(page instanceof InspectionColorSettingsPage)) return false;
for(ColorSettingsPage settingsPage: Extensions.getExtensions(ColorSettingsPage.EP_NAME)) {
if (settingsPage == page) break;
if (settingsPage instanceof InspectionColorSettingsPage) return false;
}
return true;
}
static boolean isSharedScheme(EditorColorsScheme selected) {
return ((EditorColorsManagerImpl) EditorColorsManager.getInstance()).getSchemesManager().isShared(selected);
}
private static void addInspectionSeverityAttributes(List<AttributesDescriptor> descriptors) {
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.unknown.symbol"), CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.deprecated.symbol"), CodeInsightColors.DEPRECATED_ATTRIBUTES));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.unused.symbol"), CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.error"), CodeInsightColors.ERRORS_ATTRIBUTES));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.warning"), CodeInsightColors.WARNINGS_ATTRIBUTES));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.info"), CodeInsightColors.INFO_ATTRIBUTES));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.server.problems"), CodeInsightColors.GENERIC_SERVER_ERROR_OR_WARNING));
descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.server.duplicate"), CodeInsightColors.DUPLICATE_FROM_SERVER));
}
}
@@ -18,6 +18,8 @@ package com.intellij.application.options.colors;
/**
* Marker interface for pages capable of editing the colors for inspection problems.
* The first page implementing this interface gets the inspection attribute descriptors
* added to its attribute descriptors list automatically.
*
* @author yole
*/