diff options
author | Tor Norbye <tnorbye@google.com> | 2011-07-14 15:35:14 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2011-07-14 16:53:15 -0700 |
commit | 271993a2368361fb1f67ea9c1388a352e9df43f5 (patch) | |
tree | 1bae0f8abda3625b9e63e0f099819b4b54681698 /eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/TestAttribute.java | |
parent | 654dc86699080b7c7b9931ad35f823c848eb2e9c (diff) | |
download | sdk-271993a2368361fb1f67ea9c1388a352e9df43f5.zip sdk-271993a2368361fb1f67ea9c1388a352e9df43f5.tar.gz sdk-271993a2368361fb1f67ea9c1388a352e9df43f5.tar.bz2 |
Sort XML attributes logically
This changeset modifies the layout editor such that it writes
attributes in a certain order:
* id
* style
* layout_width
* layout_height
* other layout_ attributes, sorted alphabetically
* other attributes, sorted alphabetically
The layout editor will produce attributes in this order when
- New widgets are dragged into the layout
- Widgets are moved in the layout
- It will also insert attributes in the right place when they are set
as the result of (for example) using the context menu actions.
Note that this ordering is applied unconditionally - there is no user
setting to turn it off. However, note that the current behavior is
random - moving a view for example will scramble the attributes (in an
order which is related to hashkeys in a map), so the option would be
"sort attributes logically" versus "sort attributes randomly"; if we
want an option to "leave attribute order alone" that will need to be
implemented.
Limitations:
- This does not yet modify the formatter to reorganize attributes.
Thus, Ctrl-Shift-F to reformat the XML will not change attribute
order.
- It does not fix the problem that the XML model updater does not
respect the formatting settings (such as one newline per attribute)
when manipulating attributes.
This will be addressed/worked around in subsequent CLs.
Implementation Note:
The Eclipse XML model updater will unconditionally *append* any new
attributes. We take advantage of this to perform attribute sorting by
ensuring that we always insert new attributes in the right order. We
also check for existing attributes and any which fall
lexicographically later than the new attributes are removed and
reinserted in the right sequence. In order to avoid performing these
removals and additions repeatedly on a node when we set multiple
attributes, and to avoid flushing attribute changes *immediately*
(which was the case until this), we now queue up all pending attribute
values in the nodes and apply them at the end when all attribute
changes for a given node are known.
Change-Id: If39f8c29f26e281f7c6622a31e11ba49724d274a
Diffstat (limited to 'eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/TestAttribute.java')
-rw-r--r-- | eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/TestAttribute.java | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/TestAttribute.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/TestAttribute.java index fc59ba8..7ff425f 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/TestAttribute.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/TestAttribute.java @@ -17,6 +17,7 @@ package com.android.ide.common.layout; import com.android.ide.common.api.IDragElement.IDragAttribute; import com.android.ide.common.api.INode.IAttribute; +import com.android.ide.eclipse.adt.internal.editors.uimodel.UiAttributeNode; /** Test/mock implementation of {@link IAttribute} and {@link IDragAttribute} */ public class TestAttribute implements IAttribute, IDragAttribute { @@ -50,5 +51,7 @@ public class TestAttribute implements IAttribute, IDragAttribute { return "TestAttribute [name=" + mName + ", uri=" + mUri + ", value=" + mValue + "]"; } - + public int compareTo(IDragAttribute o) { + return UiAttributeNode.compareAttributes(mName, o.getName()); + } }
\ No newline at end of file |