Red color for wrong resources.

This commit is contained in:
Alexander Lobas
2012-07-16 18:14:29 +04:00
parent 21bce9d240
commit 8896f248fc
2 changed files with 35 additions and 5 deletions
@@ -16,6 +16,7 @@
package com.intellij.android.designer.propertyTable;
import com.intellij.android.designer.propertyTable.renderers.ResourceRenderer;
import com.intellij.designer.model.RadComponent;
import com.intellij.designer.propertyTable.PropertyRenderer;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.ui.SimpleTextAttributes;
@@ -30,7 +31,7 @@ import java.util.EnumSet;
public class CompoundDimensionProperty extends CompoundProperty {
private ResourceRenderer myRenderer = new ResourceRenderer(EnumSet.of(AttributeFormat.Dimension)) {
@Override
protected void formatValue(String value) {
protected void formatValue(RadComponent component, String value) {
myColoredComponent.append("[");
if (!StringUtil.isEmpty(value)) {
int index = 0;
@@ -44,7 +45,7 @@ public class CompoundDimensionProperty extends CompoundProperty {
myColoredComponent.append("?", SimpleTextAttributes.EXCLUDED_ATTRIBUTES);
}
else {
super.formatValue(childValue);
super.formatValue(component, childValue);
}
}
}
@@ -15,6 +15,8 @@
*/
package com.intellij.android.designer.propertyTable.renderers;
import com.intellij.android.designer.model.ModelParser;
import com.intellij.designer.ModuleProvider;
import com.intellij.designer.model.RadComponent;
import com.intellij.designer.propertyTable.PropertyRenderer;
import com.intellij.designer.propertyTable.PropertyTable;
@@ -25,6 +27,9 @@ import com.intellij.ui.SimpleTextAttributes;
import com.intellij.util.ArrayUtil;
import com.intellij.util.ui.EmptyIcon;
import org.jetbrains.android.dom.attrs.AttributeFormat;
import org.jetbrains.android.facet.AndroidFacet;
import org.jetbrains.android.resourceManagers.ResourceManager;
import org.jetbrains.android.util.AndroidUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -65,26 +70,28 @@ public class ResourceRenderer implements PropertyRenderer {
myColoredComponent.clear();
PropertyTable.updateRenderer(myColoredComponent, selected);
formatValue(value);
formatValue(component, value);
return myColoredComponent;
}
protected void formatValue(String value) {
protected void formatValue(RadComponent component, String value) {
if (!StringUtil.isEmpty(value)) {
boolean system = false;
int prefix = -1;
if (value.startsWith("#")) {
prefix = 1;
}
else if (value.startsWith(ANDROID_PREFIX)) {
prefix = ANDROID_PREFIX.length();
system = true;
}
else if (value.startsWith("@")) {
prefix = 1;
}
if (prefix != -1) {
myColoredComponent.append(value.substring(0, prefix), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
myColoredComponent.append(value.substring(prefix));
myColoredComponent.append(value.substring(prefix), textStyle(component, value, system));
}
else if (myFormats.contains(AttributeFormat.Dimension) && value.length() > 2) {
int index = value.length() - 2;
@@ -114,6 +121,28 @@ public class ResourceRenderer implements PropertyRenderer {
}
}
private static SimpleTextAttributes textStyle(RadComponent component, String value, boolean system) {
if (value.startsWith("@") && !value.startsWith("@id/") && !value.startsWith("@+id/") && !value.startsWith("@android:id/")) {
try {
int start = system ? ANDROID_PREFIX.length() : 1;
int index = value.indexOf('/', start + 1);
String type = value.substring(start, index);
String name = value.substring(index + 1);
ModuleProvider moduleProvider = component.getRoot().getClientProperty(ModelParser.MODULE_KEY);
AndroidFacet facet = AndroidFacet.getInstance(moduleProvider.getModule());
ResourceManager manager = facet.getResourceManager(system ? AndroidUtils.SYSTEM_RESOURCE_PACKAGE : null);
if (manager.findValueResources(type, name, false).isEmpty() && manager.findResourceFiles(type, name, false).isEmpty()) {
return SimpleTextAttributes.ERROR_ATTRIBUTES;
}
}
catch (Throwable e) {
}
}
return SimpleTextAttributes.REGULAR_ATTRIBUTES;
}
@Nullable
public static Color parseColor(String value) {
if (value == null || !value.startsWith("#")) {