diff options
author | Tor Norbye <tnorbye@google.com> | 2011-02-15 13:59:30 -0800 |
---|---|---|
committer | Android Code Review <code-review@android.com> | 2011-02-15 13:59:30 -0800 |
commit | d69b701bf92fd531f23ce8ee9b6869c2a6008a44 (patch) | |
tree | e8cd4a92b5def54e8f260c62c2c7ff472a7f1358 /eclipse | |
parent | 0dc7e89946f4475e97c3e95614ce93fb7a322849 (diff) | |
parent | 8af8ae67319032957c24b9f006d64cdc215f86c2 (diff) | |
download | sdk-d69b701bf92fd531f23ce8ee9b6869c2a6008a44.zip sdk-d69b701bf92fd531f23ce8ee9b6869c2a6008a44.tar.gz sdk-d69b701bf92fd531f23ce8ee9b6869c2a6008a44.tar.bz2 |
Merge "XML editing: add ="" for attributes and change icons"
Diffstat (limited to 'eclipse')
6 files changed, 63 insertions, 28 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/icons/attribute.png b/eclipse/plugins/com.android.ide.eclipse.adt/icons/attribute.png Binary files differnew file mode 100644 index 0000000..04508ea --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.adt/icons/attribute.png diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/icons/element.png b/eclipse/plugins/com.android.ide.eclipse.adt/icons/element.png Binary files differnew file mode 100644 index 0000000..e5cd0ca --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.adt/icons/element.png diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidContentAssist.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidContentAssist.java index 4c542b1..93acb4f 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidContentAssist.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidContentAssist.java @@ -61,6 +61,8 @@ import java.util.regex.Pattern; */ public abstract class AndroidContentAssist implements IContentAssistProcessor { + private static final String ATTRIBUTE_ICON_FILENAME = "attribute"; + /** Regexp to detect a full attribute after an element tag. * <pre>Syntax: * name = "..." quoted string with all but < and " @@ -494,7 +496,26 @@ public abstract class AndroidContentAssist implements IContentAssistProcessor { } } } - CompletionProposal proposal = new CompletionProposal( + + final CompletionProposal proposal; + + // For attributes, automatically insert ns:attribute="" and place the cursor + // inside the quotes. + if (choice instanceof AttributeDescriptor) { + // Special case for attributes: insert ="" stuff and locate caret inside "" + String suffix = "=\"\""; //$NON-NLS-1$ + proposal = new CompletionProposal( + keyword + suffix , // String replacementString + offset - wordPrefix.length(), // int replacementOffset + wordPrefix.length() + selectionLength, // int replacementLength + keyword.length() + suffix.length() - 1, // cursorPosition + icon, // Image image + keyword, // displayString - don't include ="" + null, // IContextInformation contextInformation + tooltip // String additionalProposalInfo + ); + } else { + proposal = new CompletionProposal( keyword + end_tag, // String replacementString offset - wordPrefix.length(), // int replacementOffset wordPrefix.length() + selectionLength, // int replacementLength @@ -504,7 +525,7 @@ public abstract class AndroidContentAssist implements IContentAssistProcessor { null, // IContextInformation contextInformation tooltip // String additionalProposalInfo ); - + } proposals.add(proposal); } } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/AttributeDescriptor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/AttributeDescriptor.java index 222684d..b46f261 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/AttributeDescriptor.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/AttributeDescriptor.java @@ -17,7 +17,6 @@ package com.android.ide.eclipse.adt.internal.editors.descriptors; import com.android.ide.common.api.IAttributeInfo; -import com.android.ide.eclipse.adt.AdtPlugin; import com.android.ide.eclipse.adt.internal.editors.IconFactory; import com.android.ide.eclipse.adt.internal.editors.uimodel.UiAttributeNode; import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; @@ -36,6 +35,8 @@ import org.eclipse.swt.graphics.Image; * the correct UiAttributeNode-derived class. */ public abstract class AttributeDescriptor { + private static final String ATTRIBUTE_ICON_FILENAME = "attribute"; //$NON-NLS-1$ + private final String mXmlLocalName; private final String mNsUri; private final IAttributeInfo mAttrInfo; @@ -95,18 +96,11 @@ public abstract class AttributeDescriptor { /** * Returns an optional icon for the attribute. - * <p/> - * By default this tries to return an icon based on the XML name of the attribute. - * If this fails, it tries to return the default Android logo as defined in the - * plugin. If all fails, it returns null. * * @return An icon for this element or null. */ public Image getIcon() { - IconFactory factory = IconFactory.getInstance(); - Image icon; - icon = factory.getIcon(getXmlLocalName(), IconFactory.COLOR_RED, IconFactory.SHAPE_CIRCLE); - return icon != null ? icon : AdtPlugin.getAndroidLogo(); + return IconFactory.getInstance().getIcon(ATTRIBUTE_ICON_FILENAME); } /** diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/ElementDescriptor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/ElementDescriptor.java index 316f020..f4cb251 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/ElementDescriptor.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/descriptors/ElementDescriptor.java @@ -39,8 +39,10 @@ import java.util.Set; * and it will cease to exist when the XML node ceases to exist. */ public class ElementDescriptor implements Comparable<ElementDescriptor> { + private static final String ELEMENT_ICON_FILENAME = "element"; //$NON-NLS-1$ + /** The XML element node name. Case sensitive. */ - private final String mXmlName; + protected final String mXmlName; /** The XML element name for the user interface, typically capitalized. */ private final String mUiName; /** The list of allowed attributes. */ @@ -223,26 +225,11 @@ public class ElementDescriptor implements Comparable<ElementDescriptor> { /** * Returns an optional icon for the element. - * <p/> - * By default this tries to return an icon based on the XML name of the element. - * If this fails, it tries to return the default Android logo as defined in the - * plugin. If all fails, it returns null. * * @return An icon for this element or null. */ public Image getIcon() { - IconFactory factory = IconFactory.getInstance(); - int color = hasChildren() ? IconFactory.COLOR_BLUE : IconFactory.COLOR_GREEN; - int shape = hasChildren() ? IconFactory.SHAPE_RECT : IconFactory.SHAPE_CIRCLE; - String name = mXmlName; - if (name.indexOf('.') != -1) { - // If the user uses a fully qualified name, such as - // "android.gesture.GestureOverlayView" in their XML, we need to look up - // only by basename - name = name.substring(name.lastIndexOf('.') + 1); - } - Image icon = factory.getIcon(name, color, shape); - return icon != null ? icon : AdtPlugin.getAndroidLogo(); + return IconFactory.getInstance().getIcon(ELEMENT_ICON_FILENAME); } /** diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/descriptors/ViewElementDescriptor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/descriptors/ViewElementDescriptor.java index ca07b7a..b1b7754 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/descriptors/ViewElementDescriptor.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/descriptors/ViewElementDescriptor.java @@ -16,11 +16,15 @@ package com.android.ide.eclipse.adt.internal.editors.layout.descriptors; +import com.android.ide.eclipse.adt.AdtPlugin; +import com.android.ide.eclipse.adt.internal.editors.IconFactory; import com.android.ide.eclipse.adt.internal.editors.descriptors.AttributeDescriptor; import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor; import com.android.ide.eclipse.adt.internal.editors.layout.uimodel.UiViewElementNode; import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; +import org.eclipse.swt.graphics.Image; + /** * {@link ViewElementDescriptor} describes the properties expected for a given XML element node * representing a class in an XML Layout file. @@ -134,4 +138,33 @@ public final class ViewElementDescriptor extends ElementDescriptor { public void setSuperClass(ViewElementDescriptor superClassDesc) { mSuperClassDesc = superClassDesc; } + + /** + * Returns an optional icon for the element. + * <p/> + * By default this tries to return an icon based on the XML name of the element. + * If this fails, it tries to return the default element icon as defined in the + * plugin. If all fails, it returns null. + * + * @return An icon for this element or null. + */ + @Override + public Image getIcon() { + IconFactory factory = IconFactory.getInstance(); + String name = mXmlName; + if (name.indexOf('.') != -1) { + // If the user uses a fully qualified name, such as + // "android.gesture.GestureOverlayView" in their XML, we need to look up + // only by basename + name = name.substring(name.lastIndexOf('.') + 1); + } + + Image icon = factory.getIcon(name); + if (icon == null) { + icon = AdtPlugin.getAndroidLogo(); + } + + return icon; + } + } |