diff options
author | Tor Norbye <tnorbye@google.com> | 2011-07-15 18:12:34 -0700 |
---|---|---|
committer | Android Code Review <code-review@android.com> | 2011-07-15 18:12:34 -0700 |
commit | 87403b57ff17e42b7f3094c0b489bcc19e097fe9 (patch) | |
tree | ffc1a319486d9e1cb8b5ef5c2b6ca06180934bab /eclipse/plugins/com.android.ide.eclipse.adt | |
parent | 55ebbe1723a8dd0e904f385ff307ce175f339b8f (diff) | |
parent | 654dc86699080b7c7b9931ad35f823c848eb2e9c (diff) | |
download | sdk-87403b57ff17e42b7f3094c0b489bcc19e097fe9.zip sdk-87403b57ff17e42b7f3094c0b489bcc19e097fe9.tar.gz sdk-87403b57ff17e42b7f3094c0b489bcc19e097fe9.tar.bz2 |
Merge "Add new InsertType for widget moves within the same layout"
Diffstat (limited to 'eclipse/plugins/com.android.ide.eclipse.adt')
5 files changed, 52 insertions, 20 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/api/InsertType.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/api/InsertType.java index c5a4435..806b2bb 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/api/InsertType.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/api/InsertType.java @@ -30,8 +30,12 @@ public enum InsertType { */ CREATE_PREVIEW, - /** The view is being inserted here because it was moved from somewhere else */ - MOVE, + /** The view is being inserted here because it was moved from somewhere else within + * the same layout */ + MOVE_WITHIN, + + /** The view is being inserted here because it was moved from some other layout */ + MOVE_INTO, /** * The view is being inserted here as a result of a copy/paste from elsewhere diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LinearLayoutRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LinearLayoutRule.java index 13f06ad..bf1efb5 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LinearLayoutRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LinearLayoutRule.java @@ -565,6 +565,12 @@ public class LinearLayoutRule extends BaseLayoutRule { @Override public void onChildInserted(INode node, INode parent, InsertType insertType) { + if (insertType == InsertType.MOVE_WITHIN) { + // Don't adjust widths/heights/weights when just moving within a single + // LinearLayout + return; + } + // Attempt to set fill-properties on newly added views such that for example, // in a vertical layout, a text field defaults to filling horizontally, but not // vertically. @@ -580,6 +586,9 @@ public class LinearLayoutRule extends BaseLayoutRule { // In a horizontal layout, make views that would fill horizontally in a // vertical layout have a non-zero weight instead. This will make the item // fill but only enough to allow other views to be shown as well. + // (However, for drags within the same layout we do not touch + // the weight, since it might already have been tweaked to a particular + // value) node.setAttribute(ANDROID_URI, ATTR_LAYOUT_WEIGHT, VALUE_1); } if (fill.fillVertically(vertical)) { diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/MoveGesture.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/MoveGesture.java index c28d259..c8fab84 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/MoveGesture.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/MoveGesture.java @@ -355,14 +355,7 @@ public class MoveGesture extends DropGesture { String label = computeUndoLabel(mTargetNode, elements, event.detail); mCanvas.getLayoutEditor().wrapUndoEditXmlModel(label, new Runnable() { public void run() { - InsertType insertType; - if (event.detail == DND.DROP_MOVE) { - insertType = InsertType.MOVE; - } else if (GlobalCanvasDragInfo.getInstance().getSourceCanvas() != null) { - insertType = InsertType.PASTE; - } else { - insertType = InsertType.CREATE; - } + InsertType insertType = getInsertType(event, mTargetNode); mCanvas.getRulesEngine().callOnDropped(mTargetNode, elementsFinal, mFeedback, @@ -407,6 +400,35 @@ public class MoveGesture extends DropGesture { } /** + * Returns the right {@link InsertType} to use for the given drop target event and the + * given target node + * + * @param event the drop target event + * @param mTargetNode the node targeted by the drop + * @return the {link InsertType} to use for the drop + */ + public static InsertType getInsertType(DropTargetEvent event, NodeProxy mTargetNode) { + GlobalCanvasDragInfo dragInfo = GlobalCanvasDragInfo.getInstance(); + if (event.detail == DND.DROP_MOVE) { + SelectionItem[] selection = dragInfo.getCurrentSelection(); + if (selection != null) { + for (SelectionItem item : selection) { + if (item.getNode() != null + && item.getNode().getParent() == mTargetNode) { + return InsertType.MOVE_WITHIN; + } + } + } + + return InsertType.MOVE_INTO; + } else if (dragInfo.getSourceCanvas() != null) { + return InsertType.PASTE; + } else { + return InsertType.CREATE; + } + } + + /** * Computes a suitable Undo label to use for a drop operation, such as * "Drop Button in LinearLayout" and "Move Widgets in RelativeLayout". * diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/OutlineDropListener.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/OutlineDropListener.java index d1ca8a9..5f516d5 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/OutlineDropListener.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/OutlineDropListener.java @@ -124,17 +124,10 @@ import java.util.Set; final int indexFinal = index; canvas.getLayoutEditor().wrapUndoEditXmlModel(label, new Runnable() { public void run() { - Object sourceCanvas = GlobalCanvasDragInfo.getInstance().getSourceCanvas(); - InsertType insertType; - if (event.detail == DND.DROP_MOVE) { - insertType = InsertType.MOVE; - } else if (sourceCanvas != null) { - insertType = InsertType.PASTE; - } else { - insertType = InsertType.CREATE; - } + InsertType insertType = MoveGesture.getInsertType(event, targetNode); canvas.getRulesEngine().setInsertType(insertType); + Object sourceCanvas = GlobalCanvasDragInfo.getInstance().getSourceCanvas(); boolean createNew = event.detail == DND.DROP_COPY || sourceCanvas != canvas; BaseLayoutRule.insertAt(targetNode, elements, createNew, indexFinal); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/OutlinePage.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/OutlinePage.java index d29ee45..cafcc13 100755 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/OutlinePage.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/OutlinePage.java @@ -831,7 +831,11 @@ public class OutlinePage extends ContentOutlinePage elements, DND.DROP_MOVE); canvas.getLayoutEditor().wrapUndoEditXmlModel(label, new Runnable() { public void run() { - canvas.getRulesEngine().setInsertType(InsertType.MOVE); + InsertType insertType = InsertType.MOVE_INTO; + if (dragSelection.get(0).getNode().getParent() == targetNode) { + insertType = InsertType.MOVE_WITHIN; + } + canvas.getRulesEngine().setInsertType(insertType); int index = target.getSecond(); BaseLayoutRule.insertAt(targetNode, elements, false, index); canvas.getClipboardSupport().deleteSelection("Remove", dragSelection); |