diff options
author | Raphael Moll <ralf@android.com> | 2010-07-22 11:09:27 -0400 |
---|---|---|
committer | Raphael Moll <ralf@android.com> | 2010-07-22 11:09:27 -0400 |
commit | 3af3a210c0cb8e92404b18874774d695a3733b5e (patch) | |
tree | 249157ef0fcd1a2bed25cef7c435bd503b44616d /eclipse/plugins/com.android.ide.eclipse.adt/gscripts | |
parent | d784a5000d432260f9efe0ce5f62177f38dba6be (diff) | |
download | sdk-3af3a210c0cb8e92404b18874774d695a3733b5e.zip sdk-3af3a210c0cb8e92404b18874774d695a3733b5e.tar.gz sdk-3af3a210c0cb8e92404b18874774d695a3733b5e.tar.bz2 |
ADT GLE2: implementation paste operation.
Change-Id: Ifc7b150eefd810a7c615fd9d3f26904e59c6c4aa
Diffstat (limited to 'eclipse/plugins/com.android.ide.eclipse.adt/gscripts')
3 files changed, 81 insertions, 15 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/gscripts/BaseLayout.groovy b/eclipse/plugins/com.android.ide.eclipse.adt/gscripts/BaseLayout.groovy index 98e0b0f..ab380cb 100755 --- a/eclipse/plugins/com.android.ide.eclipse.adt/gscripts/BaseLayout.groovy +++ b/eclipse/plugins/com.android.ide.eclipse.adt/gscripts/BaseLayout.groovy @@ -26,6 +26,58 @@ public class BaseLayout extends BaseView { super.onDispose(); } + + // ==== Paste support ==== + + /** + * The default behavior for pasting in a layout is to simulate + * a drop in the top-left corner of the view. + * <p/> + * Note that we explicitely do not call super() here -- the BasView.onPaste + * will call onPasteBeforeChild() instead. + * <p/> + * Derived layouts should override this behavior if not appropriate. + */ + public void onPaste(INode targetNode, IDragElement[] elements) { + + DropFeedback feedback = onDropEnter(targetNode, elements); + if (feedback != null) { + Point p = targetNode.getBounds().getTopLeft(); + feedback = onDropMove(targetNode, elements, feedback, p); + if (feedback != null) { + onDropLeave(targetNode, elements, feedback); + onDropped(targetNode, elements, feedback, p); + } + } + } + + /** + * The default behavior for pasting in a layout with a specific child target + * is to simulate a drop right above the top left of the given child target. + * <p/> + * This method is invoked by BaseView.groovy when onPaste() is called -- views + * don't generally accept children and instead use the target node as a hint + * to paste "before" it. + */ + public void onPasteBeforeChild(INode parentNode, INode targetNode, IDragElement[] elements) { + + DropFeedback feedback = onDropEnter(parentNode, elements); + if (feedback != null) { + Point parentP = parentNode.getBounds().getTopLeft(); + Point targetP = targetNode.getBounds().getTopLeft(); + if (parentP.y < targetP.y) { + targetP.y -= 1; + } + + feedback = onDropMove(parentNode, elements, feedback, targetP); + if (feedback != null) { + onDropLeave(parentNode, elements, feedback); + onDropped(parentNode, elements, feedback, targetP); + } + } + } + + // ==== Utility methods used by derived layouts ==== // TODO revisit. diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/gscripts/BaseView.groovy b/eclipse/plugins/com.android.ide.eclipse.adt/gscripts/BaseView.groovy index 95c2d73..fa81ec8 100755 --- a/eclipse/plugins/com.android.ide.eclipse.adt/gscripts/BaseView.groovy +++ b/eclipse/plugins/com.android.ide.eclipse.adt/gscripts/BaseView.groovy @@ -18,8 +18,6 @@ package com.android.adt.gscripts; public class BaseView implements IViewRule { - private String mFqcn; - // Some common Android layout attribute names used by the view rules. // All these belong to the attribute namespace ANDROID_URI. public static String ATTR_ID = "id"; @@ -40,12 +38,14 @@ public class BaseView implements IViewRule { public static String ANDROID_URI = "http://schemas.android.com/apk/res/android"; public boolean onInitialize(String fqcn) { - // This base rule can handle any class. - mFqcn = fqcn + // This base rule can handle any class so we don't need to filter on FQCN. + // Derived classes should do so if they can handle some subclasses. // For debugging and as an example of how to use the injected _rules_engine property. _rules_engine.debugPrintf("Initialize() of %s", _rules_engine.getFqcn()); + // If onInitialize returns false, it means it can't handle the given FQCN and + // will be unloaded. return true; } @@ -63,13 +63,9 @@ public class BaseView implements IViewRule { return null; } - public String getFqcn() { - return mFqcn; - } - // ==== Selection ==== - void onSelected(IGraphics gc, INode selectedNode, + public void onSelected(IGraphics gc, INode selectedNode, String displayName, boolean isMultipleSelection) { Rect r = selectedNode.getBounds(); @@ -93,7 +89,7 @@ public class BaseView implements IViewRule { gc.drawString(displayName, xs, ys); } - void onChildSelected(IGraphics gc, INode parentNode, INode childNode) { + public void onChildSelected(IGraphics gc, INode parentNode, INode childNode) { Rect rp = parentNode.getBounds(); Rect rc = childNode.getBounds(); @@ -118,21 +114,39 @@ public class BaseView implements IViewRule { // ==== Drag'n'drop support ==== // By default Views do not accept drag'n'drop. - DropFeedback onDropEnter(INode targetNode, IDragElement[] elements) { + public DropFeedback onDropEnter(INode targetNode, IDragElement[] elements) { return null; } - DropFeedback onDropMove(INode targetNode, IDragElement[] elements, + public DropFeedback onDropMove(INode targetNode, IDragElement[] elements, DropFeedback feedback, Point p) { return null; } - void onDropLeave(INode targetNode, IDragElement[] elements, DropFeedback feedback) { + public void onDropLeave(INode targetNode, IDragElement[] elements, DropFeedback feedback) { // ignore } - void onDropped(INode targetNode, IDragElement[] elements, DropFeedback feedback, Point p) { + public void onDropped(INode targetNode, IDragElement[] elements, DropFeedback feedback, Point p) { // ignore } + // ==== Paste support ==== + + /** + * Most views can't accept children so there's nothing to paste on them. + * In this case, defer the call to the parent layout and use the target node as + * an indication of where to paste. + */ + public void onPaste(INode targetNode, IDragElement[] elements) { + // + def parent = targetNode.getParent(); + def parentFqcn = parent?.getFqcn(); + def parentRule = _rules_engine.loadRule(parentFqcn); + + if (parentRule instanceof BaseLayout) { + parentRule.onPasteBeforeChild(parent, targetNode, elements); + } + } + } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/gscripts/android.widget.RelativeLayout.groovy b/eclipse/plugins/com.android.ide.eclipse.adt/gscripts/android.widget.RelativeLayout.groovy index 4bac2d8..508d3b4 100755 --- a/eclipse/plugins/com.android.ide.eclipse.adt/gscripts/android.widget.RelativeLayout.groovy +++ b/eclipse/plugins/com.android.ide.eclipse.adt/gscripts/android.widget.RelativeLayout.groovy @@ -325,7 +325,7 @@ public class AndroidWidgetRelativeLayoutRule extends BaseLayout { return null; } - return [ "rect": r, "attr": [ attr ], "mark": r.center() ]; + return [ "rect": r, "attr": [ attr ], "mark": r.getCenter() ]; } |