OSDN Git Service

Fix and turn on the auto-format XML option
authorTor Norbye <tnorbye@google.com>
Fri, 12 Aug 2011 21:55:31 +0000 (14:55 -0700)
committerTor Norbye <tnorbye@google.com>
Fri, 19 Aug 2011 23:32:18 +0000 (16:32 -0700)
commiteb9180e92c97624d7d78607d61bcb0343a4db129
tree032878617884ded153c70a3f4077d6f077743b63
parenta5c9c6e9726b9fea72a7487fcdc588cac1ec29d4
Fix and turn on the auto-format XML option

This changeset turns on the option to "Automatically format the XML
edited by the visual layout editor" by default.

It also fixes several issues related to it:

- First, the auto-format code was previously hooked up to synchronous
  insert and delete node events, which meant during a larger edit it
  would apply formatting repeatedly and before the edit was complete
  (which made the DOM model keep reparsing to update document based
  back into its internal model).

- Another problem was that the auto format only applied to added and
  removed nodes; attribute edits were not considered (which made sense
  given that the old formatter did not support reordering of
  attributes, but now that it does attribute changes requires
  reformatting as well.)

- The old reformatter was trying to work with the Eclipse XML
  formatter, which does not handle partial document formats well
  (there were a bunch of workarounds, and even with those there were
  some problems). The new formatter does not, so I've changed the
  option to be tied to the custom formatter; the automatic formatting
  of layout editor changes is now enabled only when the custom editor
  is enabled.

  This also takes advantage of the new formatter's ability to only
  format the attributes section of a document, so if you just tweak
  the attribute of a node, the children's formatting is not affected.

- The formatter would apply to more than just the layout editor; any
  UI editor which used UiElementNodes would be affected. I've added a
  method, by default false, where each UI editor can opt into this.
  I'd like to get Raphael's feedback on the manifest editor before
  possibly adding it for that editor as well (and updating the option
  name to something more generic).

- The mechanism for ignoring XML document changes (already used for
  refactoring) is now also connected to reformatting, so when the
  formatter runs it sets an "ignore" flag such that there is no
  second XML model loading when the changes are just as a result
  of a formatting option.

This changeset also tweaks the formatting behavior of comments;
instead of -always- adding a blank line before line comments (other
than suffix comments), it now considers the previous document and
preserves the spacing used there (though it will collapse multiple
lines into one).

Change-Id: I04c2b80836c4d9874dca789c2f2cbc8c8c7cfa76
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidXmlEditor.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/formatting/AndroidXmlFormattingStrategy.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/formatting/XmlFormatPreferences.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/formatting/XmlPrettyPrinter.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutEditor.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/DomUtilities.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiElementNode.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/preferences/AdtPrefs.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/preferences/EditorsPage.java
eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/formatting/XmlPrettyPrinterTest.java