OSDN Git Service

Avoid repeating manifest element names.
authorRaphael Moll <ralf@android.com>
Fri, 11 Mar 2011 00:40:19 +0000 (16:40 -0800)
committerRaphael Moll <ralf@android.com>
Fri, 11 Mar 2011 02:55:43 +0000 (18:55 -0800)
In the manifest form tree, avoid repeating element names
in the tree labels. E.g. "MyActivity (Activity)" can just
be "MyActivity".

Change-Id: I8de481aabcbc33e830e18c528cb10a0b2a14138a

eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/model/UiManifestElementNode.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiElementNode.java

index 0b78a22..a4f701f 100644 (file)
@@ -56,7 +56,7 @@ public final class UiManifestElementNode extends UiElementNode {
     /**
      * Computes a short string describing the UI node suitable for tree views.
      * Uses the element's attribute "android:name" if present, or the "android:label" one
-     * followed by the element's name.
+     * followed by the element's name if not repeated.
      *
      * @return A short string describing the UI node suitable for tree views.
      */
@@ -68,12 +68,13 @@ public final class UiManifestElementNode extends UiElementNode {
             manifestDescriptors = target.getManifestDescriptors();
         }
 
+        String name = getDescriptor().getUiName();
+
         if (manifestDescriptors != null &&
                 getXmlNode() != null &&
                 getXmlNode() instanceof Element &&
                 getXmlNode().hasAttributes()) {
 
-
             // Application and Manifest nodes have a special treatment: they are unique nodes
             // so we don't bother trying to differentiate their strings and we fall back to
             // just using the UI name below.
@@ -90,12 +91,18 @@ public final class UiManifestElementNode extends UiElementNode {
                                     AndroidManifestDescriptors.ANDROID_LABEL_ATTR);
                 }
                 if (attr != null && attr.length() > 0) {
-                    return String.format("%1$s (%2$s)", attr, getDescriptor().getUiName());
+                    // If the ui name is repeated in the attribute value, don't use it.
+                    // Typical case is to avoid ".pkg.MyActivity (Activity)".
+                    if (attr.contains(name)) {
+                        return attr;
+                    } else {
+                        return String.format("%1$s (%2$s)", attr, name);
+                    }
                 }
             }
         }
 
-        return String.format("%1$s", getDescriptor().getUiName());
+        return String.format("%1$s", name);
     }
 
     /**
index 1a66cdb..b969d30 100644 (file)
@@ -211,17 +211,24 @@ public class UiElementNode implements IPropertySource {
     /**
      * Computes a short string describing the UI node suitable for tree views.
      * Uses the element's attribute "android:name" if present, or the "android:label" one
-     * followed by the element's name.
+     * followed by the element's name if not repeated.
      *
      * @return A short string describing the UI node suitable for tree views.
      */
     public String getShortDescription() {
+        String name = mDescriptor.getUiName();
         String attr = getDescAttribute();
         if (attr != null) {
-            return String.format("%1$s (%2$s)", attr, mDescriptor.getUiName());
+            // If the ui name is repeated in the attribute value, don't use it.
+            // Typical case is to avoid ".pkg.MyActivity (Activity)".
+            if (attr.contains(name)) {
+                return attr;
+            } else {
+                return String.format("%1$s (%2$s)", attr, name);
+            }
         }
 
-        return mDescriptor.getUiName();
+        return name;
     }
 
     /** Returns the key attribute that can be used to describe this node, or null */