From c4f75630aa293ec4027216ae0bfd2d9e6782e209 Mon Sep 17 00:00:00 2001 From: Tor Norbye Date: Mon, 22 Nov 2010 09:58:06 -0800 Subject: [PATCH] Fix live manipulation of elements This changeset fixes bugs related to dragging included views around in the canvas: First, the tag would get rewritten to . This happened because the layout editor treats the FQCN and the XML node name as equivalent, but in the case of the include tag the FQCN was set to null instead of "include". Second, the "layout" attribute would not get copied because it is NOT in the Android namespace, and the code to copy attributes ended up with an empty-string namespace which was not handled correctly. Third, when copied the "layout" attribute would end up with the namespace "ns:" because the code to create attribute nodes always created namespaced attribute nodes rather than a plain attribute node when the namespace is null. Change-Id: Ibd34212517615aa8ec79abe14bca765cdca525f6 --- .../layout/descriptors/LayoutDescriptors.java | 2 +- .../internal/editors/uimodel/UiElementNode.java | 26 ++++++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/descriptors/LayoutDescriptors.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/descriptors/LayoutDescriptors.java index 500c8ba8c..202153314 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/descriptors/LayoutDescriptors.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/descriptors/LayoutDescriptors.java @@ -314,7 +314,7 @@ public final class LayoutDescriptors implements IDescriptorProvider { // Create the include descriptor ViewElementDescriptor desc = new ViewElementDescriptor(xml_name, // xml_name xml_name, // ui_name - null, // canonical class name, we don't have one + VIEW_INCLUDE, // "class name"; the GLE only treats this as an element tag "Lets you statically include XML layouts inside other XML layouts.", // tooltip null, // sdk_url attributes.toArray(new AttributeDescriptor[attributes.size()]), diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiElementNode.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiElementNode.java index a78da12ab..b57901f05 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiElementNode.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiElementNode.java @@ -1370,10 +1370,16 @@ public class UiElementNode implements IPropertySource { // Add or replace an attribute Document doc = element.getOwnerDocument(); if (doc != null) { - Attr attr = doc.createAttributeNS(attrNsUri, attrLocalName); + Attr attr; + if (attrNsUri != null && attrNsUri.length() > 0) { + attr = doc.createAttributeNS(attrNsUri, attrLocalName); + attr.setPrefix(lookupNamespacePrefix(element, attrNsUri)); + attrMap.setNamedItemNS(attr); + } else { + attr = doc.createAttribute(attrLocalName); + attrMap.setNamedItem(attr); + } attr.setValue(newValue); - attr.setPrefix(lookupNamespacePrefix(element, attrNsUri)); - attrMap.setNamedItemNS(attr); return true; } } @@ -1529,8 +1535,11 @@ public class UiElementNode implements IPropertySource { // Try with all internal attributes UiAttributeNode uiAttr = setInternalAttrValue( getInternalUiAttributes().values(), attrXmlName, attrNsUri, value, override); + if (uiAttr != null) { + return uiAttr; + } - // Look at existing unknown (aka custom) attributes + // Look at existing unknown (a.k.a. custom) attributes uiAttr = setInternalAttrValue( getUnknownUiAttributes(), attrXmlName, attrNsUri, value, override); @@ -1539,6 +1548,7 @@ public class UiElementNode implements IPropertySource { // in which case we just create a new custom one. uiAttr = addUnknownAttribute(attrXmlName, attrXmlName, attrNsUri); + // FIXME: The will create the attribute, but not actually set the value on it... } return uiAttr; @@ -1550,6 +1560,14 @@ public class UiElementNode implements IPropertySource { String attrNsUri, String value, boolean override) { + + // For namespace less attributes (like the "layout" attribute of an tag + // we may be passed "" as the namespace (during an attribute copy), and it + // should really be null instead. + if (attrNsUri != null && attrNsUri.length() == 0) { + attrNsUri = null; + } + for (UiAttributeNode uiAttr : attributes) { AttributeDescriptor uiDesc = uiAttr.getDescriptor(); -- 2.11.0