OSDN Git Service

On ImageView or ImageButton drop, ask user for drawable
authorTor Norbye <tnorbye@google.com>
Sat, 19 Mar 2011 23:22:58 +0000 (16:22 -0700)
committerTor Norbye <tnorbye@google.com>
Sat, 19 Mar 2011 23:22:58 +0000 (16:22 -0700)
Similar to the <include> tag handling, when you drop an image a
resource chooser inputting @drawable resources pops up and lets you
pick the drawable to be shown in the image. If you cancel, then the
default image will be set instead.

Change-Id: Id09801a877acbeb437f518cefe60062ac92e7e7c

eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/ImageButtonRule.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/ImageViewRule.java

index fe2e346..a65a0df 100644 (file)
@@ -24,7 +24,7 @@ import com.android.ide.common.api.IViewRule;
 import com.android.ide.common.api.InsertType;
 
 /**
- * An {@link IViewRule} for android.widget.ImageButtonRule.
+ * An {@link IViewRule} for android.widget.ImageButton.
  */
 public class ImageButtonRule extends BaseViewRule {
 
@@ -32,6 +32,17 @@ public class ImageButtonRule extends BaseViewRule {
     public void onCreate(INode node, INode parent, InsertType insertType) {
         super.onCreate(node, parent, insertType);
 
+        // When dropping an include tag, ask the user which layout to include.
+        if (insertType == InsertType.CREATE) { // NOT InsertType.CREATE_PREVIEW
+            String src = mRulesEngine.displayResourceInput("drawable", ""); //$NON-NLS-1$ //$NON-NLS-2$
+            if (src != null) {
+                node.editXml("Set Image",
+                    new PropertySettingNodeHandler(ANDROID_URI, ATTR_SRC, src));
+                return;
+            }
+        }
+
+        // Fallback if dismissed or during previews etc
         if (insertType.isCreate()) {
             node.setAttribute(ANDROID_URI, ATTR_SRC, getSampleImageSrc());
         }
index d0f4da7..7ebf13d 100644 (file)
@@ -32,6 +32,17 @@ public class ImageViewRule extends BaseViewRule {
     public void onCreate(INode node, INode parent, InsertType insertType) {
         super.onCreate(node, parent, insertType);
 
+        // When dropping an include tag, ask the user which layout to include.
+        if (insertType == InsertType.CREATE) { // NOT InsertType.CREATE_PREVIEW
+            String src = mRulesEngine.displayResourceInput("drawable", ""); //$NON-NLS-1$ //$NON-NLS-2$
+            if (src != null) {
+                node.editXml("Set Image",
+                    new PropertySettingNodeHandler(ANDROID_URI, ATTR_SRC, src));
+                return;
+            }
+        }
+
+        // Fallback if dismissed or during previews etc
         if (insertType.isCreate()) {
             node.setAttribute(ANDROID_URI, ATTR_SRC, getSampleImageSrc());
         }