History log of /sdk/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java
Revision Date Author Comments
fe51dba2aa25e559786e5da315d4db714ffe7559 12-Sep-2012 Tor Norbye <tnorbye@google.com> Support separate layout editors for a single layout resource

This changeset changes the "reuse" behavior of the layout editor to no
longer reuse the same layout editor when you are switching between
alternate layout files for the same layout resource, such as
layout/foo.xml and layout-land/foo.xml. This lets you more quickly
switch back and forth and inspect differences between the layouts,
etc. There is also an option in the Android > Editors panel to turn on
single editor sharing again.

The biggest part of the changeset, by far, is a cleanup of the
ConfigurationComposite class and associated code. This was necessary
not just to support the above feature (where we need to "back out" UI
changes when you've made a configuration edit which results in a
different file getting opened), but it's also an important preparation
for multi configuration editing, where we need to be able to switch
configuration settings in and out of a single configuration editor,
etc.

The configuration data itself is now in a separate Configuration
class; the UI is in ConfigurationChooser, and the configuration
matching code is in ConfigurationMatcher. There's also a new Locale
class to track language/region pairs instead of using 2-element
ResourceQualifier arrays. The various menu listeners are also in
separate UI classes now. While there are new classes, most of the
configuration matching algorithm is unchanged, just moved to a new
class and the UI syncing and configuration data lookup replaced.

Bitmasks are used to handle configuration changes, such that updating
multiple related attributes (e.g. a rendering target change also
causes a theme change if say Holo isn't available) can now be processed
just once with a single change call.

(Various other cleanup too.)

Change-Id: I04ac969f46824321be3db0c487ef077c03cc6012
12d4581faa6438941e65a9dc83213be34c6ca970 13-Sep-2012 Tor Norbye <tnorbye@google.com> Constants refactoring.

This changeset moves most constants into the SdkConstants
class, and gets rid of AndroidConstants and LintConstants.
It also migrates all non-ADT specific constants from
AdtConstants into SdkConstants. It furthermore moves various
other constants (such as those in XmlUtils and ValuesDescriptors)
into the constants class. It also fixes the modifier order
to be the canonical modifier order (JLS 8.x).

Finally, it removes redundancy and combines various constant
aliases such that we don't have both NAME_ATTR and ATTR_NAME
pointing to "name", etc.

Change-Id: Ifd1755016f62ce2dd80e5c76130d6de4b0e32161
f25890ca71100673ba58c343a211fc838cc59706 31-May-2012 Tor Norbye <tnorbye@google.com> Default action for view rules.

For now, text-oriented widgets declare their default action to
be to set the text attribute. Also hook up the default rename
keybinding to setting the id.

Change-Id: I14e8e06d0842759b1ac05e7e9494deb30b3cc40f
81cefe2a26dd6db8a878e30874d12cdcbff0e83b 11-Aug-2012 Xavier Ducrohet <xav@android.com> More refactoring.

Move stuff out of sdklib into common and ide_common.
Remove androidprefs and move the one class into common.

Change-Id: I71d126a13cf2ba413692e29616f4968a37d7b33a
85e4a1a9dd133abb879ec211ce8dd385004edf22 08-Aug-2012 Xavier Ducrohet <xav@android.com> Refactor common.jar

Move resources and com.android.util.Pair into layoutlib_api
where they belong since layoutlib depends on them and we need
to control the API.

Made a copy of Pair to stay in common.jar but moved it to
com.android.utils.Pair (the one in com.android.util.Pair is
marked as deprecated to prevent usage where applicable).

Also moved XmlUtil and PositionXmlParser to com.android.utils
to match Pair.

Change-Id: I21d7057d3f2ce604f86a3bb1fa3c130948c93b89
68d4aa68f412049e12c644b32f12f4219b9f49d5 30-Jul-2012 Tor Norbye <tnorbye@google.com> Drop shadows in the layout editor

Change-Id: I83f699da2a9d494938ee73fb2c274c5f8d5ac647
eb1fb3f6b660d0acc17c1d9117acbcba809c8041 20-Jul-2012 Tor Norbye <tnorbye@google.com> Handle window events across multiple workbench events

ADT uses a "window coordinator" which listens for various window
related events (such as part activation, editors getting maximized
etc) to implement its various layout editor handling (to dock property
sheets within the layout editor unless it's shown in the surrounding
frame), to activate/deactivate editors for keybinding handling, etc.

This did not take into account the possibility of multiple workbench
windows getting opened. This CL adds proper support for this. The
window coordinator is no longer a singleton; there is one instance per
workbench window, and AdtStartup listens for workbench events and
creates or disposes these on demand.

Change-Id: I298d9d82c7aefd684bcb1ace3bee0267e1f94a60
93d6d74f60b1e3b674b376b65d66fb79704966b0 09-Jul-2012 Tor Norbye <tnorbye@google.com> Add code completion and API checks for theme references (?attr)

This checkin improves the handling of ?attr and ?android:attr theme
references, such that

(1) The API check considers theme references, and for example flags
usage of ?android:attr/dividerHorizontal if your minSdkVersion is
lower than 11

(2) Adds theme reference completion to the XML code completion.

Change-Id: I2049b828e413802ac81579294f515fb0a4faccdf
47412b5c2252df2624e5ff4ad2f9054af86c5065 13-Jun-2012 Tor Norbye <tnorbye@google.com> Misc bugfixes

This changeset fixes a number of unrelated minor issues:
- Fix to the config composite such that changing the activity
associated with the layout is sticky
- Fix to the icon generator such that you can't select shape=none for
notification icons
- For the brief activity labels in the config composite, strip the
outer class names for inner classes, e.g. from
SessionLivestreamActivity$SessionLiveCaptionsFragment to
SessionLiveCaptionsFragment. Also strip out "Activity" or
"Fragment" from the suffix of the name if the name is long.
- When creating a blank project and you're *not* creating an activity,
don't create a dummy layout either.
- Fix metadata for fragment and include such that you can convert
one into the other using the Change Widget refactoring.
- Fix bug where pulling up a hovering a lint tooltip, and then
switching to the Java editor with the keyboard would leave the
tooltip on the screen.
- Only show lint tooltips and overlay icons if lint-on-save is enabled
- Workaround Eclipse 4.x issue where switching between maximized
layout editors would cause the structure view to be hidden

Change-Id: I68aee8967e5fe5deb0f30c071f4c395966aa6304
df255c6a90a00b90121d74f9f91b605f14473cf5 09-Jun-2012 Tor Norbye <tnorbye@google.com> Run lint in the layout editor after undo/redo

Lint already runs automatically after each edit in the layout editor.
However, the undo and redo actions in the layout editor are mapped
directly through to the XML editor's undo/redo actions (and when run
their edits trigger a model refresh). This meant that after an undo or
redo, lint would not run to update. If you for example delete a button
that has a lint error on it, then undo that edit, the button comes
back without the lint error.

This CL fixes this: it now wraps the Undo/Redo actions with an action
wrapper which first runs the delegated action, and then runs the edit
hooks (e.g. lint) afterwards.

Change-Id: I66431fd7989e1f3c0776563d159ca7b89fef8431
511e3c11cb13c6d83c727d1df63f928ad2a7a3fc 08-Jun-2012 Tor Norbye <tnorbye@google.com> Prevent zoom flicker

The layout editor preserves the zoom level of a file when you close
and reopen it later. However, when a layout is opened for the first
time, there is a brief flicker as the layout is first shown at zoom
level 100%, and then briefly thereafter rezoomed to fit the available
canvas space.

The reason for this is that when the editor is first created, the size
of the layout editor is not known (SWT reports it as 0,0), so it can't
compute a correct zoom level. The earlier solution was to do a
Display.asyncExec() to rezoom soon.

This changeset improves upon this by observing that we don't need the
zoom to be recomputed until the canvas image is actually painted, so
the delayed zoom is queried lazily both by the paint routine as well
as the delayed setup runnable. This makes new layouts come up without
any zoom flicker.

Change-Id: I72a3a30fe40f26255951de50dcb8dcaeff44cbf7
7b4c80f986586d7cb52876949e0a299ff4d5ef61 08-Jun-2012 Tor Norbye <tnorbye@google.com> Fix layout window coordinator for Eclipse 4.2

Eclipse 4.x does not fire change events when the main editor window is
maximized or un-maximized:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=382120

This CL works around that by using the layout editor's controlResized
listener to query the state flags of the IEditorPart and update the
maximized state as necessary. This fixes ADT issue
http://code.google.com/p/android/issues/detail?id=32866

Change-Id: Icb13e7191b12959c7a7038c6bc6099666985fec5
86b00e87888bfce42b1d05dbf7cdec8295144fd8 31-May-2012 Tor Norbye <tnorbye@google.com> Fix cut & paste in XML editors for Eclipse 4.x

Change-Id: Ie30c362c71eff0d62e177e06687c362802d416b1
99e631c489877affbf11ecfba441844cfcd0299e 25-May-2012 Tor Norbye <tnorbye@google.com> Fix misc minor issues

Fixes some NPEs and avoid logging a common issue
(which is already listed inline in the layout editor
error display).

Change-Id: I6a62f37ec845ca081e1dc7fc8ad857a7ec4e9a29
5ae903bf8670f40e9eb40ebbd0a25c15eaac5962 23-May-2012 Tor Norbye <tnorbye@google.com> Improved lint integration in the layout editor

This changeset improves the lint integration in the layout editor in
the following ways:

- The outline now shows error or warning indicators in the bottom left
corners of the icons for any specific views that have one or more
lint warnings associated with them. There is a tooltip if you hover
over the icon which displays the lint message.

- The layout editor canvas displays little warning indicators in the
bottom right corner of the views (provided the views are larger than
the icons; e.g. empty layouts, as well as views that are zoomed out
very far will not show lint indicators).

- There is a tooltip hover in the canvas as well. In order to avoid
obscuring content, it shows up at the bottom of the view. It might
also show multiple lines: one for each lint warning in a view near
the cursor. (This is important if you for example have a warning
both on a layout and a widget inside that layout.)

- The error indicator in the upper right corner, which used to be a
(too small) warning icon is instead an issue count now. Clicking on
the issue count opens up the lint file dialog.

- The lint file dialog now contains a button to suppress issues by
attributes (and fixed some other minor bugs related to keeping
expanded categories expanded across refreshes and setting an initial
selection).

- Lint is run automatically when the layout is opened up (3 seconds
after the first successful render). This makes the error indicators
show up (until now, it would only run single-file-lint after the
first edit operation).

Change-Id: I306aca390d70bf025f5e86fc21ae7b6bc0036d8d
4d1b0e863e9cb12bb3978059339b217193abebb2 20-May-2012 Tor Norbye <tnorbye@google.com> Fix file permissions

Remove the execute permission on some source files in
the repository.

Change-Id: Ic33ee9b20fd4fa9824487c2d8741f5668a0ffcfb
a881b0b34678ad76c9f5eba62fac7a00a22ac606 20-May-2012 Tor Norbye <tnorbye@google.com> Move XML code to the common library

The ManifestMerger library needs to look up the prefix to use for the
Android namespace, and the Document.lookupPrefix method is not
implemented by the Eclipse DOM implementation (which throws an
exception). However, we have an implementation of this in the ADT
plugin.

This changeset creates a new XmlUtils class in the common/ library
(which is accessible by both ADT and the manifest merger, and the
anttasks where the manifest merger is used), and moves the namespace
prefix lookup code in there. It also moves the XML escape methods
into that class. It also adds a new method to the ManifestMerger for
merging directly from documents (rather than files), and makes sure
that all the merging code goes via the prefix utility method rather
than calling the document.lookupPrefix method.

Finally, it moves the various string constants associated with XML
namespaces into the single XmlUtils class, since these were spread
across several different classes before (and many of them are needed
in the XmlUtils class).

The vast majority of the diffs in this changeset are related to simple
import statement changes to reflect the new locations of these
constants.

Change-Id: Ib8f3d0e5c89e47e61ea509a23925af7b6580abee
bc5879056fba2eb616dea06e6191bdc218b594c0 27-Apr-2012 Tor Norbye <tnorbye@google.com> New Configuration Chooser

This changeset replaces the configuration chooser with a new UI.

First, the two lines of comboboxes have been replaced by a toolbar,
which will wrap to two lines if it cannot fit on a single
line. However, it tries hard to avoid this scenario by using icons and
brief labels. For example, the rendering target is displayed as an
Android icon along with just "4.0" instead of "Android
4.0". Similarly, the "Other" locale is just shown as a globe icon, and
for example in the Device list "4.65in 720p (Galaxy Nexus)" is display
as just "Galaxy Nexus".

Second, the "current configuration" label is now a dropdown instead.
The text of the label displays the current configuration as before
(though using the brief name, e.g. "layout-land" instead of "Landscape
Configuration". In addition, it's a dropdown, and opening the menu
will display all other available configurations for this file. Thus,
if you have a special landscape version and a special tablet version
of a particular layout, the menu will contain default, landscape and
tablet (where the menu items display the full configuration names such
as "Landscape Orientation"). In addition, the configuration menu also
contains "Create New...", which is the new location for the Create
button which used to be in the toolbar itself.

Third, there is a new "Activity" dropdown. This displays the current
activity associated with this layout, next to an Eclipse "class" icon.
It is initially populated with our best guess of what the activity
is. The chosen activity determines which theme is initially assigned
to a layout (for example when there is a Manifest registration of a
theme to an activity). In the future we will use this facility to
drive other features as well, such as preview rendering the action bar
(where we need to know the associated activity) or assisting with
creating click handlers. The Activity dropdown menu also contains a
"Open <Activity class>..." action for jumping to the associated Java
code. The chosen activity is persisted as an XML attribute in the
layout so it should be preserved across IDE sessions and shared among
developers.

Fourth, all the dropdown menus are now native SWT menus rather than
dropdown menus, which means we can use icons, proper separators, and
nesting. The locale menu now shows flag icons next to each region (and
when a locale is chosen the corresponding icon is shown in the
configuration toolbar). In the Theme menu we no longer need to use
"-------" ASCII separators, we can use proper native menu separators
instead. And the Theme menu is now nested; rather than a really long
list of options, the menu is grouped into related sections:

* Currently selected theme
* Project Themes >
* Manifest Themes >
* Holo Themes >
* Holo.Light Themes >
* DeviceDefault Themes >
...
* All >
* Open "<current theme>" Declaration...

Fifth, the device configuration combobox has been replaced by three
inline icon radiobuttons, showing portrait, landscape and (if enabled)
square. This makes it easy to switch orientation through a single
click.

Sixth, the UI mode (Normal/Car/Dock) and Night mode (Day/Night) are no
longer directly shown in the configuration chooser since they are not
used frequently enough to warrant persistent space in the always
visible toolbar. Instead, there is an "Edit Configuration" icon on the
left you can click which brings up a full editor dialog where all the
previous combo boxes appear, along with the generic configuration
qualifier selection dialog. Here you can make more specific edits to
the current configuration state.

There are various fixes as well. For example the whole toolbar is
hidden during platform data loading and made visible at the end. When
creating a new configuration file, that new configuration file is
opened after creation. We now track whether the current theme (stored
in the IDE persistent property) is a project theme or a framework theme.

Change-Id: Ic8d9817c7bc4dbcae4535b6b9222393fb49cfde9
5cae1eabc82d4fcd106897abb9acbd482ad2f849 16-Apr-2012 Tor Norbye <tnorbye@google.com> Improved layout window management

This changeset improves the way the layout editor handles windows. In
particular, it attempts to make the property sheet and the outline
more visible.

Specifically:
* It adds the WindowBuilder docking support, which offers several
new features:

(1) You can collapse and expand the palette and structure views. If
you hover over a collapsed palette (for example) it temporarily
opens, and when you drag from it over to the canvas it collapses
again.

(2) The initial size is pixel based rather than percentage based, so
the default palette size is more reasonable on large displays
(it used to always take 20%, which was fine on a small screen
but a waste on larger screens).

(3) You can drag & drop to reconfigure the layout a bit. (This is
fairly limited though; in particular, you cannot drag these
views out of the editor area and mix them with Eclipse views.)

* When the property sheet view is not shown anywhere else, it is shown
as part of the outline instead (sharing the vertical space). This
works better for the new property sheet implementation since it
works better as a vertical window than a horizontal window.

* When the outline is not shown anywhere else, it is shown in a new
composite window *inside* the editor area. This mode is also entered
when you temporarily maximize the layout editor window.

* The layout canvas is auto-fit-zoomed when you enter and exit
maximized mode, as well as when you open or close docked windows
within the editor.

The goal is for these changes to offer a good layout editing
experience with the outline views and property sheets *without* using
a new perspective for layout editing. Note that this is not identical
to what WindowBuilder does; they always embed both the palette and the
structure views within the editor area, which means the structure view
is typically redundant with the outline view on the right unless you
maximize the view. With the approach above hopefully we'll avoid that
case and you'll always see the views without redundancy (and therefore
with more available space for the layouts).

Change-Id: I0d338b2781b9732e992f088fcc4e1ba46ff0954f
b9317238c40c76f9a31647021f232adba6da0979 15-Mar-2012 Tor Norbye <tnorbye@google.com> Use XML outline in the layout editor when editing text

This changeset adds an XML outline in the layout XML editor when
editing text, and the graphical outline when the graphical layout
editor tab is shown. This is complicated because it's not really
supported in Eclipse:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=1917

See the long comment in LayoutEditorDelegate.delegateGetAdapter for an
explanation of the two tricks involved:
- Using a multiplexing outline implementation to switch outlines,
triggered by editor page switch notifications
- Using a selection listener to anticipate when the XML outline is
attempting to react to editor selection events and return the
non-multiplexing outline from getAdapter in that specific scenario

While I was at it I also made the outline customized to handle our
icons, similar to how the quick outline already handles it, and fixed
the quick outline to work with the new delegated editors.

Change-Id: I0b7ea8c8d8c09d2ecc1500689f9dda4b5db2b492
f14914e59366377316c70f068347d3e34a1dea3c 29-Feb-2012 Tor Norbye <tnorbye@google.com> Make XML editors work with non-workspace files

This changeset makes the AndroidXmlEditor handle other editor inputs
than just FileEditorInput. In particular, it now handles
IURIEditorInput as well. This makes the "Go To Declaration" facility
for @android resources work properly again, and unlike before, you can
now use our editors in those files as well, so you can use Go To
Declaration to jump to other @android resources within the same
platform.

This changeset adds checks after all the getInputFile() calls on the
editor, which ensures that features which assume a file exists (such
as the quickfix and visual refactoring operations) do not do anything
in these files.

The layout editor has a lot of file requirements, so that editor is
deliberately skipped and you get a plain editor instead if you try to
open layout files outside of the workspace.

See
http://code.google.com/p/android/issues/detail?id=26164

Change-Id: I7457494ec0bfc2eb4e6eba2e059025142c21d3ce
ecd69dd768fc25aeb12791a477c44e04f007d5f4 21-Feb-2012 Raphael <raphael@google.com> ADT fix save on layout configuration change.

When a layout is opened and its configuration is changed,
the new delegate layout wasn't properly saving the layout
before changing files.

This is due to another instance of the delegate code calling
a method on the delegate whereas it should have called a method
with the same exact name on the editor.
To reduce this confusion, this CL adds a 'delegate' prefix to
methods which are common in the CommonXmlEditor and the delegates.
At the expense of being a bit more verbose it makes it clearer
which method is being invoked.

Change-Id: I34e620a9d25272fe75dab54279161b04a961a598
91069c28195ca0ed5e64f36714cf359f63743710 18-Jan-2012 Raphael <raphael@google.com> ADT: adjust default-editor id for existing legacy editors.

Note that this changes the "default editor" id associated
by a file but not actually close an existing editor (trying
to do so from the editor fails.) Also, unless the editor
is put in focus, it is not initialized and thus will not
change.

To compensate, when opening a project we'll visit all the
XML files from the /res folder and associate them to our
new editor ID.
On top of that, we'll try to find existing open editors
using a legacy id and close/reopen them using the new
common editor id. We only do that when upgrading a project
via fixEditorAssiociations, which means if the user then
manually forces a file to open using a legacy editor
by using the Open With > Other, it will keep using the
old editor id and we won't open/close it a second time.

Change-Id: Ia5f7e960515500a0ad07d401124578477ed70859
7642068d0e5b29e520b1e42106d638efa477466a 20-Jan-2012 Tor Norbye <tnorbye@google.com> Add Export Screenshot action to the layout editor

Change-Id: I1b6c95b0e51d3af288d919973c46923b3d60b670
e50549f54810c29bffc681e39d33158ab2a8f26e 10-Jan-2012 Raphael <raphael@google.com> ADT: Change LayoutEditor to use new editor delegates.

Change-Id: I5624d8f5c393a74a808d98e465f0ebc6db91d741
ab36f4e7488358dea4ab6b54ee2b7bef3da0232b 21-Dec-2011 Tor Norbye <tnorbye@google.com> Update SDK codebase to JDK 6

This changeset makes the SDK codebase compile with source=1.6 (which
means it also requires JDK 6). This means that methods implementing an
interface requires @Override's. It also means we can start using APIs
like the ArrayDeque class and methods like String#isEmpty().

This changeset looks big but the change is trivial: it's basically
adding @Override in all the places that need it, along with some other
automatic Eclipse cleanup in certain files (such as reordering imports
where they were incorrectly ordered (because older versions of Eclipse
didn't always handle inner classes right)), as well as cleaning up
trailing whitespace and removing some $NON-NLS-1$ markers on lines
where there aren't any string literals anymore.

This changeset also sets the source and target JDK level to 6 in the
Eclipse compiler .settings file, and synchronizes this file to all the
other Eclipse SDK projects.

Change-Id: I6a9585aa44c3dee9a5c00739ab22fbdbcb9f8275
e632293a36d9a334d8e87c8baa1f4196f6fb917e 07-Oct-2011 Tor Norbye <tnorbye@google.com> More GridLayout Fixes

This changeset fixes various issues in the GridLayout support:

(1) Add custom Paste support for GridLayout. The default copy/paste
handler just treats a paste as a drag into (0,0) followed by a
drop. That doesn't work well for GridLayout since it ends up
writing the dragged elements into row/column 0,0. This changeset
adds a custom override of the paste handler such that it adds the
pasted elements into successive table cells instead. It still
needs to adjust the column spans to avoid changing the current
table structure; that will be done in a followup CL.

(2) Clean up the Layout Actions Bar a bit for GridLayout. Separate out
the "Show Structure" and "Grid Mode" actions, and make
grid-operations (Add/Remove Row/Column) only show up in Grid Mode,
and similarly only show Snap to Grid in Free Mode.

(3) The hidden <Space> widgets should also be hidden when selected via
Select All. Also fix a remaining issue with the action enablement
of Select All.

(4) Fix a bug where the preview bounding rectangle was drawn at the
wrong place when showing a center-horizontal proposal.

(5) Remove an assertion encountered during GridLayout conversion which
is not always true.

Change-Id: I8c4c0cac5052e59c5943e535b2f790f420303f9d
9b7e541269f70b07ee8c9ab4bd84003651487913 06-Oct-2011 Tor Norbye <tnorbye@google.com> Fix Copy/Paste enablement

This changeset fixes a couple of cases where the Copy/Paste actions
would not be enabled:

* When switching active tabs
* After running some other actions

Change-Id: I03df6fa91641ce722cb7bac615fc73342c77f586
94986e745141118cace0391da1b4dc8533408751 10-Aug-2011 Tor Norbye <tnorbye@google.com> Action API improvements

This changeset changes the Actions mechanism for view rules to add
support for the following:

* Delayed computation of submenu contents. Before this, a view rule
would have to produce the full tree of actions to be shown in menus
and submenus - for example including all the properties, and in turn
all the enumerated values for those properties and so on. Now
there's a Provider interface which can be used to compute these menu
items only when the menu is actually opened. The properties menu now
takes advantage of this.

This was also necessary to implement the following new feature:

* The layout editor context menu now also lists not just the
properties for the currently selected views, but also the
properties for the parents. For example, if you open the context
menu, you'll see the properties for the button you just right
clicked on, but there will also be a "frameLayout1" submenu
containing the actions for the <FrameLayout> parent of the button,
and a "linearLayout1" submenu for the parent linear layout. This
is useful when a parent layout doesn't have blank space on its own
so it is difficult to target.

A future CL will use the lazy initialization to add more options to
the properties menu.

* Support for arbitrary nesting. Submenus can contain submenus can
contain other submenus etc.

* Custom ordering. This changeset moves the "sort priority" concept
(which was already used for layout actions) up to all actions, which
makes it easier for rules to cooperate on ordering because instead
of appending or prepending to the superclass' context menu result,
actions can now just be initialized with a sorting priority value
which makes it trivial to interleave actions regardless of who adds
them. This also makes it a lot easier to use custom ordering in
choice menus where the ordering used to be alphabetically sorting on
keys.

* Improved support for multiselection. The callback interface now
takes a list of nodes to apply the callback to, and actions can
indicate whether they support multiple nodes. This makes it possible
for actions to more directly support the case where you apply an
action to multiple nodes. As before, the available actions in the
context menu is limited such that it only shows the actions common
to all. But now those actions can do something specific. For
example, if you select "Edit Text..." on many nodes, you will get
the input-string dialog once, and then the value is applied to
all. Similarly, if you select "Edit Id..." it will ask for a
separate id for each value (and you can cancel out of this loop).

There are various API changes too. Since the Choices action (which had
a map-based set of values) was removed, the OrderedChoices is now
renamed Choices. The Actions subclass of MenuAction which all actions
also extended has simply been moved up to the top level MenuAction.
And MenuAction has been renamed to RuleActions since they are used
not just for menus but for toolbars etc and the key thing about this
interface is that they are intended for use by rules.
Change-Id: If49f75213f2041ebfef7e84254d70d219bb766ab
8925febd3beb31e4c5e1a3329ed1e73291dd3936 07-Jul-2011 Tor Norbye <tnorbye@google.com> Add support for hidden views

There are some views which should hide in the UI to avoid clutter,
such as <Space> widgets. This changeset adds support for hidden views,
such that they don't show up in the outline, don't show up for hovers,
aren't included in drag selections and so on.

Change-Id: Icb18f4530b8aff584e72280f5bd09e776af9204c
0595b4123048f53179b5c2c65cf88968ac488ad3 07-Jul-2011 Tor Norbye <tnorbye@google.com> Simple insets support

This changeset adds the basic plumbing for supporting insets, such
that selection handles can reflect the true bounds of a widget, and
such that guidelines which show adjacent matches can show and measure
the correct visual distance between the widgets.

The actual insets data is not available (though there are some
commented out measurements for some of the most important widgets,
like buttons), so the purpose of this changeset is to put the APIs in
place such that the various view rules can correctly account for these
deltas when they become available.

Change-Id: I326bfa22f0d239d76685b371d38bb8eac594a53b
80d9301c2e874b29889c41adb0623666cf534fa0 10-Apr-2011 Tor Norbye <tnorbye@google.com> Resize & Guideline Support

RelativeLayout now has both drop/move and resize guidelines, and
existing constraints are visualized for the selection.

LinearLayout resizing now uses weights to change the size of nodes
rather than setting width/height.

All resize operations offer guidelines to snap to their "wrap_content"
size.

Various bug fixes in related areas as well.

Change-Id: I817e34c6e67ce61cfb137eb067076d91f69f99e9
429ae88878cf781753d8261d350ad89fe5864169 07-Apr-2011 Tor Norbye <tnorbye@google.com> Add Resize Support to the Layout Editor

This changeset adds "resizing" support to the layout editor.

First, the normal selection overlay is replaced with a selection
rectangle which also has "selection handles" in the corners and in the
middle of each edge. Moving the cursor over one of the selection
handle will show a directional resize cursor, and dragging the handle
will initiate a new resizing gesture. (This also made it possible to
remove the selection fill we've used until now, so the layout editor
will "interfere" less with the visual look of the layout.)

During the resizing operation, the current size is displayed in the
Eclipse status bar.

The resizability of widgets is determined by metadata, so for example
a ZoomControls widget is not resizable, a rating bar is only
horizontally resizable, a TableRow is only vertically resizable, and
most widgets are resizable in any direction.

The parent layout is involved in the resizing operation. Currently,
the resizing gestures will only update the width and height properties
(except for absolute layout, which will also set the x and y
properties if you are dragging a left or top edge). In a follow up
changeset this will be extended to for example make RelativeLayout
allow resize dragging to snap to new edges and the resize will be
applied as a set of new constraints on the "resized" widget. Thus,
you'll be able to drag the right hand side of a widget and drag it
over to attach to some other widget or edge, independent of what the
left edge or vertical edges are bound to.

This changeset also adds the ability for ViewRules to provide a
message or error message back to the IDE during a drag or resize
operation. For resizing this is used to display the new size. However,
it is now also used to display more useful messages in a couple of
older scenarios:
* Attempting to drag anything into a ListView will display a message
that AdapterViews much be configured via Java code
* Attempting to drag anything into or within an AbsoluteLayout will
warn that AbsoluteLayouts are deprecated.

Note that resizing will currently set the size to specific pixel (dip)
sizes. In the next changeset I will add guidelines which (in addition
to those described for RelativeLayout above) will add guidelines for
significant sizes such as the parent size, the preferred
(wrap_content) size of the widget, and possibly other hardcoded sizes
in the same layout.

Change-Id: Ie4f3367e81b24259a106c649c944008f4a3d31ec
74e6dd111f5e037e4ecda1f9cd7ab9cc37ebdff8 17-May-2011 Tor Norbye <tnorbye@google.com> Fix bug in editor open utility

The code to open a file (called by Go To Declaration, Show Include
etc) handles two scenarios:

(1) The file is in the workspace - open using Eclipse IFile mechanism
(2) The file is outside the workspace - open using the fallback
external storage (which means you get a plain XML editor)

There's a third scenario: the file is not in the workspace, but is
part of a project in the workspace so it does have a valid IFile.
(This can happen if you import a project but choose not to copy the
contents into the workspace). This changeset adjusts the code to open
up an editor such that it handles this third scenario and we get our
own XML editors for these types of files.

Change-Id: I040e1b899cd38bbda3fcf3475cc4dfb541d10016
d5d648c12a073375e60ee9dfd8cbd982f51a44a0 17-May-2011 Tor Norbye <tnorbye@google.com> Fix bug in editor open utility

The code to open a file (called by Go To Declaration, Show Include
etc) handles two scenarios:

(1) The file is in the workspace - open using Eclipse IFile mechanism
(2) The file is outside the workspace - open using the fallback
external storage (which means you get a plain XML editor)

There's a third scenario: the file is not in the workspace, but is
part of a project in the workspace so it does have a valid IFile.
(This can happen if you import a project but choose not to copy the
contents into the workspace). This changeset adjusts the code to open
up an editor such that it handles this third scenario and we get our
own XML editors for these types of files.

Change-Id: I0fc89316e4625fcf66dd61060cd9b00054bc5464
77dfbea08c32e7ff9639230b6660def0620844cf 02-May-2011 Tor Norbye <tnorbye@google.com> Merge "Misc fixes"

This changeset fixes a couple of misc problems I ran into:

(1) Save the current file when double clicking on an included view.
When double clicking on an included view, the included view is
opened in a "Show Included" context where the including file is
surrounding the include. This will read the surrounding file from
disk, and if we don't save the file when opening the file then
it's possible to see a stale view (best case) or it won't work at
all if the include tag itself isn't in the saved version of the
file.

(2) Fix a bug in the "Select Same Type" context menu action where the
list was cleared before reading out the item to be selected.

(3) Filter out a few more properties from the Extract Style
refactoring dialog, and include margin attributes

(cherry picked from commit 2047b3b061e179faf6d613540a34cc7e6d492176)

Change-Id: I3c1c9d3094b7488ddf45abe6df4d686949eb8fd0
2047b3b061e179faf6d613540a34cc7e6d492176 02-May-2011 Tor Norbye <tnorbye@google.com> Misc fixes

This changeset fixes a couple of misc problems I ran into:

(1) Save the current file when double clicking on an included view.
When double clicking on an included view, the included view is
opened in a "Show Included" context where the including file is
surrounding the include. This will read the surrounding file from
disk, and if we don't save the file when opening the file then
it's possible to see a stale view (best case) or it won't work at
all if the include tag itself isn't in the saved version of the
file.

(2) Fix a bug in the "Select Same Type" context menu action where the
list was cleared before reading out the item to be selected.

(3) Filter out a few more properties from the Extract Style
refactoring dialog, and include margin attributes

Change-Id: I207cc5b736aacd3f067d6d36727ffcd7104a87c1
40c1413a861cefb3bfb2cd200c89ffdf84fdc308 12-Apr-2011 Tor Norbye <tnorbye@google.com> Custom listview layouts

This changeset adds support for user-configured layouts in ListViews
and ExpandableListViews.

There is a new "Preview List Content" pullright menu when you right
click on a ListView in the layout canvas. The menu contains links to
configure
- the layout to use for list view items
- the layout to use as a header
- the layout to use as a footer
- as well as a number of pre-configured framework layouts for common
arrangements like 2-item list, 1-item list, checked list, etc.

The selected layout is persisted as an inline comment in the layout
XML. (Current bug: When you drag elements around in the layout,
comment nodes are not preserved, meaning you will lose your list view
render type as well.)

This changeset also adds "Clear" to the resource chooser, which makes
it possible to clear a previously set value (until this, choosing
nothing would simply abort the selection.) This makes it possible to
remove a chosen header/footer.

Change-Id: I611b00f627c5773f3fe2443a6e16c29388687b36
2b8d60c26180f6e637ce998c1941f34a07ed88fe 15-Apr-2011 Tor Norbye <tnorbye@google.com> Ensure that canvas zoom is non-zero

Ensure that the canvas zoom is always greater than zero. This is a
safeguard against a scenario where the "compute best fit" code runs
too early where the SWT window bounds are 0 and the wrong value gets
computed.

Change-Id: I1519270f42c5a848fa0756f2f40cf6af69bb1865
50c6e4e3a17a7a562f45c71f826abca2a4b8740f 02-Apr-2011 Tor Norbye <tnorbye@google.com> Improve painting of combined selection and hover

When the mouse is over a rectangle, we highlight this "hover"
rectangle by painting a semitranslucent white rectangle on top of it.

When a view is selected, we highlight it by painting a semitranslucent
blue rectangle over it.

This means that if you move the mouse over the selection, you get both
of these effects added together, which dilutes the underlying selected
widget too much.

This changeset tries to improve this situation by defining a different
visual style to be used for the combination of hover and selection,
where the opacity is much lower for the hover in this case.

This changeset also reduces the existing hover by about 30% opacity.

Change-Id: I63ffe8a9d756dcae29b2009a1a1cd6b9ffb6fbe7
2fa8370664b25f391eb15dc22a3daa2d55d2b883 30-Mar-2011 Tor Norbye <tnorbye@google.com> Improve view cookie handling

The layout editor is passed a ViewInfo hierarchy by the layout
library. For older versions of the layout library, it can be handed
hierarchies where the view cookies (which point back to XML model
objects corresponding to the rendered views) that are missing or
ambiguous. For that reason, it has various algorithms to try to piece
things back together, and for example handle <merge> scenarios as best
it can.

This isn't necessary with layout lib version 5 and higher, since as of
version 5 these scenarios are handled on the layout lib side and the
layout editor is passed back special cookies like the MergeCookie to
properly handle the various scenarios.

This fix makes the layout editor look up the layoutlib version, and if
dealing with version 5 or higher, it takes a simpler path to build up
the hierarchy.

This is also necessary to deal with the latest version of layoutlib
which passes a new type of view cookie which the older algorithm
couldn't handle.

Change-Id: I98c3ba5d17ad9d639eb118e4709c0b6bbf815b0a
ab4f7f50b0659d83565733cf60e38863af2b8825 30-Mar-2011 Tor Norbye <tnorbye@google.com> Auto-zoom views the first time they are opened

Now that we default to the tablet screen size, creating a new layout
usually opens up a view which only shows the top left part of the
design view, and horizontal and vertical scrollbars.

This changeset adds auto-zoom such that the first time a view is
opened, the view also auto-zooms. Note that the type of zooming
performed is zoom-out-only; it never zooms in, so a small phone layout
will continue to be shown at 100%. We already perform auto-zoom in
several other scenarios (such as changing orientation).

Change-Id: I1e9a9e8357c952f84b541ea799c529d5dc4b3239
4563c4e2f168df1d6c97206a4ac6444dfa2264ba 17-Mar-2011 Tor Norbye <tnorbye@google.com> Add custom views and third party views to the palette

This changeset adds a new category to the palette, "Custom & Third
Party Views", which is populated with android.view.View subclasses
found in the current project (or any of its libraries), and in any
jars included by the project. They can be dragged directly to the
canvas, and control clicking on the palette entries will jump to the
source.

There are a bunch of adjustments in various places to make working
with custom views better - from ensuring that we don't use fully
qualified class names in default ids, to showing the Java class icon
for custom views in outline and elsewhere, to making zero-sized view
highlight and expand when selected like we do for laoyuts - since with
custom views it's quite easy to end up with an "invisible" view that
you can't see after dropping it.

There are also some fixes to the code which looks up third party and
custom views (which was already used by the Wrap In refactoring) - to
handle inner classes, to filter out non public or abstract classes,
and most importantly to only include views reachable from the current
project (since the view search necessarily is workspace wide.)

Change-Id: If1d8c7e5c7dd907a68d8d0962e85c5144e911503
e7abbed2fe84c25bcd6d68cef4140963c10a1e5d 31-Jan-2011 Tor Norbye <tnorbye@google.com> Add palette variations of widgets

This changeset adds new items to the palette which are just variations
of an existing widget but with different initial attributes. In
particular:

* Instead of just LinearLayout there are two versions of it:
LinearLayout (Vertical) and LinearLayout (Horizontal)

* The ProgressBar has 3 variations: Large, Small, and Horizontal. The
horizontal ProgressBar looks like the SeekBar, without at thumb, so
the SeekBar is moved next to the progress bar.

* There is a new palette category, "Text Fields", which contains a
number of different initializations of the EditText's "inputType"
attribute - for textual and numeric passwords, for names and e-mail
and postal addresses, for phone numbers, for negative and decimal
numbers, etc.

* Since LinearLayout is so common, the outline handles it specially to
ensure that we show a horizontal or a vertical icon depending on the
orientation attribute of the specific element rather than the
generic descriptor icon.

There are various changes to the palette icon preview and drag preview
etc to handle these changes. In particular, the category
initialization code had to be rewritten to be able to handle
variations (since for example the text field appears in multiple
categories, so the old assumption that each view had an assigned
category was no longer true.)

This changeset also extracts a constant for the "android:" literal
used in many places in the code, and renames the existing "android"
namespace constant.

Change-Id: Ibbc3dbd34c551594421c3de034cdccea6a66eba0
8dc4366bbaad39d56e1c2ded4046c86a95a17666 14-Feb-2011 Tor Norbye <tnorbye@google.com> Refactoring: Wrap in Container, Change Layout Type, Extract

This changeset adds refactoring support for 3 visual refactoring
operations:

(1) Wrap in Container. This can be invoked on one or more sibling
views (or the root view) to add a new layout container into the
hierarchy which "wraps" the views. The refactoring can also update
the layout attributes (such as RelativeLayout attachments) such
that they refer to the new container instead. If invoked on the
root element, the namespace declarations are migrated from the old
root to the new root.

(2) Change Layout. This can be invoked on a layout view to change the
type of layout. In addition to editing the XML type declaration,
it also removes layout parameters that no longer apply, and
depending on which layout you are converting from and converting
to, it may attempt to perform some translation to preserve the
layout characteristics. In particular, if you convert from a
LinearLayout to a RelativeLayout, then it will use RelativeLayout
params to emulate the old LinearLayout by attaching items below
(for vertical layouts) or to the right of (for horizontal layout)
the previous sibling, and if the baseline property was set on the
LinearLayout it will also add baseline constraints on the
RelativeLayout. (It also adds default ids on any elements that
need it.)

There is a LOT more we can do to support layout transformations;
this is just a beginning.

(3) Extract as Include. We already had this feature, but it performed
its own XML document manipulation. This code has been rewritten
to use the Eclipse refactoring support (which the other two
refactorings are implemented to use as well), which among other
things means that you get Preview support - you can press Preview
from the refactoring dialog to see the edits before they are
made. This rewrite is also necessary to support an upcoming
feature: the ability to replace occurrences in other
configuration-variations of this layout; for that we need to
ability to do multi-file changes which the refactoring support is
ideal for.

Change-Id: I50b142645f14c29c798fc02df6df69bad5b9426c
fd2f4f57c489071a57bac694c38c0a627b2f65c9 11-Feb-2011 Tor Norbye <tnorbye@google.com> Perform auto-zoom-to-fit on device changes

When you change the device in the configuration chooser (e.g. either
the screen type or the orientation), the layout editor will now
automatically apply a special version of the "Zoom to Fit" scaling
operation: Zoom to fit but at most 100%.

In practice this means that if you have zoomed out a lot (for example
to accomodate a tablet in portrait mode) and you switch to landscape,
it will zoom back in a bit further such that the landscape orientation
fits better without leaving a lot of unused screen space. Similarly,
if you go from a low resolution screen to a higher resolution screen,
it will zoom out if necessary to keep the picture in view. It will
however never zoom to more than 100%, so if you go to a lower
resolution screen will not show blurry pixels, you will see the
natural size of the image.

This changeset also contains a fix for the fit-to-zoom code such that
the margin handling works properly for zoom factors greater than one.

Change-Id: I14a6061e0492c6a116eb6d4fcedd0b5c108caabe
18e332d589e783bcbd8e73c7b39a745a7fef4040 11-Feb-2011 Tor Norbye <tnorbye@google.com> Improvements to Selection - New Actions & Sync Fix

This changeset adds a new "Select" context menu. In addition to Select
All and Select None, there are new actions to select the parent of the
currently selected item, an action to select all its siblings, and an
action to select all widgets in the layout of the same type. For
example, invoking this on a button will select all buttons in the
layout. Select Parent is bound to Escape and is particularly useful
when you want to target a layout widget that has children and no free
space, since any mouse click will target one of its children. With
Select Parent you click on the child and hit Escape to reach the
container.

In addition, this changeset fixes selection synchronization for
context menus. Until now, you had to FIRST select an item, THEN right
click on it to see its context menu items. The root cause for this is
an SWT bug (eclipse issue 26605), but we can work around it with a
MenuDetectListener, which is run when the menu is posted and gives us
a chance to sync the selection.

Change-Id: If3e15c335c372a6ee8a3c8c357b48bb80fbbb40c
eb526121bdb1bdda56100a27c05af1033cf4e378 08-Feb-2011 Tor Norbye <tnorbye@google.com> Make layout editor margins compress when necessary

If there isn't enough room to show the margins, make the margins
smaller. This gives more useful layout room when you are dealing with
large screens.

Change-Id: I6f967dbe6b18ca5ee85cc04db88d903cb976e851
3fe0fe2645bc79b991c5696f2d236e3326bca83e 08-Feb-2011 Tor Norbye <tnorbye@google.com> Make zoom level persistent

Make the zoom level of the layout editor persistent across IDE
sessions. This is particularly useful now that we are dealing with
larger screens, such as WXGA, where you typically need to zoom out
(zoom to fit) in order to see the whole layout, and it's annoying to
have to do this every time you open the IDE.

Change-Id: Ib062a6a9f9291445978b3cfae03c120e4f2bf386
a7da09b74d5f41667823ddf36c0cd7f145f54a2d 01-Feb-2011 Tor Norbye <tnorbye@google.com> Add Layout Actions toolbar

Add a new toolbar above the layout canvas (and to the right of the
palette). This toolbar shows various layout-related actions on its
left, and the canvas zoom controls on the right. The zoom controls
have been moved from the configuration panel, which has also been
reorganized a little with three of the dropdowns moved up to make more
horizontal width and take the place of the old zoom controls.

The toolbar items vary based on which layout is "active". The active
layout is the parent layout of the selection, or the root layout in
the canvas if there is no selection.

Some examples:

- In a LinearLayout, there are radio-button icons for switching
between horizontal and vertical orientation, and for toggling
baseline alignment

- There are toggle buttons for toggling between wrap_content and
match_parent (or fill_parent) for the layout_width and layout_height
properties

- There is a dropdown menu in LinearLayout and RelativeLayout which
lets you set the layout_gravity to one of the dozen gravity settings

- There is an action button which brings up a margin chooser dialog
where you can configure the margin settings for the currently
selected elements for layouts that support margins

There will be additional actions here in the future.

This changeset also adds a few new MenuAction subclasses and factories
to make it possible to do ordered lists of choices. It also adds
sorting keys to make it easier for parents and children to interleave
their actions with simple sorting keys rather than having to append,
prepend or merge their respective result lists. In a follow-up
changeset I will replace the context menu code to use these, as well
as attempt to make all actions stateless such that they can be cached
and reapplied for different targets.

Some misc cleanup.

Change-Id: I6a87144fcfd1d359e5561829bd5d63c852f16970
6685d3a8cb5fe1374e36358c1436a70c6bca1659 27-Jan-2011 Xavier Ducrohet <xav@android.com> Update the Layoutlib API to contain part of the current config.

Right now only the screen size is needed. We can add more to Params
as needed.

Since we should use the existing enum classes for this, I moved
all the current enum from sdklib into a new jar file called
resources.jar.

ADT, sdklib, layoutlib_api all depend on it.

Changes to resources should always be API compatible and the result
should be copied into the in-dev platform branch in prebuilt, similar
to layoutlib_api. See the README.txt files in layoutlib_api/ and
resources/

Change-Id: I877ba3cad555ec497954bb0866639e51e7751020
6aeb047ea010de8f3e820dab6625aef762418de6 27-Jan-2011 Xavier Ducrohet <xav@android.com> Properly convert the rendered layout images if alpha is needed.

The layoutlib can specify if the image is rendered as a floating
window, and needs alpha.
If it doesn't needed it we do a faster convert discarding the
alpha which will be better when playing animations in the normal
case.

Change-Id: I2dbd2d1ae9190207b51978e4a8d77cdff25f3e45
d54ec58b34097854e27027a70dd88af6535a413b 15-Jan-2011 Tor Norbye <tnorbye@google.com> Adjust hint feedback location

When you select items in the relative layout, the layout attachments
are displayed below the canvas.

This changeset tweaks the positioning of these hints: they are
displayed to the right of the window (instead of below it) if the
canvas is taller than it is wide.

Change-Id: I7e12ed2f1749d4d3e529bab1a765b6a3279ca084
106c1ead81b9d429f2f403b5bafe1b5569a228cb 14-Jan-2011 Tor Norbye <tnorbye@google.com> Zoom Improvements

First, add a new "Zoom to Fit" toolbar action. This will look at the
size of the rendered image, as well as the size of the canvas area,
and compute the largest possible scale factor that will zoom the
rendered image while showing everything.

This is particularly useful when working with larger devices, such as
WXGA, where typically the rendering comes up showing only the top left
portion of the image, and the Zoom Out function often zooms out too
much since it does not have fine granularity.

Second, add icons to the various zooming functions. The zoom in/out
icons are from Eclipse WTP; the other three are minor derivations from
these icons (using = for emulate real size, 1 for 100% and an outline
for zoom to fit).

Third hook up zoom in, zoom out, zoom to 100% and zoom to fit to
keyboard shortcuts (applicable to the canvas only).

Finally, tweak some labels.

(Also updated the ddms screencapture icon, since there was a screen
capture icon in the same Eclipse WTP icon folder)

Change-Id: Idc118a58f418daeefb5835f40dc1fd518b0f99d1
55554e7b43ec0b1a5ceacc789ad5631a8754640e 10-Jan-2011 Tor Norbye <tnorbye@google.com> Make the error text participate in select all and copy

When there are rendering errors, the error messages are listed in a
StyledText widget which opens up at the bottom of the layout editor.

This changeset makes it possible to copy & paste the error message. It
does this by:

- Making the global Select All action operate on the error label when
the error label has focus

- Make the global Copy action operate on the error label if the error
label has selected text (which could have been made selected either
by the Select All action above, or by a manual mouse selection)

Change-Id: Ia7f267737a0d43a54dce8cf6b5f5802aef038881
9003290cc259ee2a85ef952dcda779d4b500aa59 10-Jan-2011 Tor Norbye <tnorbye@google.com> Add "Play Animation" menu

Adds a new dynamically populated context menu named "Play Animation", which
contains 4 sections:

- First, the most recently played animation name. This is initially
empty, but once you've played an animation, the most recently one is
listed there.

- "Create...". This is a shortcut which opens the "New Android XML
File" wizard, pre-configured to point at the current project and
with the Animation category selected.

- "Android Builtin >". This is a submenu (also lazily populated) which
lists all the builtin Android framework animations alphabetically.

- The animations in the current project, if any, listed
alphabetically.

Selecting any of the project or framework animation names will cause
the animation to be played once. During the animation, selection and
hover overlays are temporarily hidden.

This is just a start; we should play/rewind/stop buttons, maybe a loop
toggle button, etc somewhere on the screen when you've selected an
aniation. We should also try to filter out animations (especially
framework ones) that have no effect on the current selection.
Finally, error messages need to be handled better since we are reusing
the render session from the editor.

Change-Id: If113b02d458972b5cc2cb253dd9e6c312b8302a9
16b42ddc372125748c50d94998a355fcb8dbc93d 05-Jan-2011 Tor Norbye <tnorbye@google.com> Move the "Show Included In" menu item

The "Show Included In" context menu was grouped as part of the
view-specific actions (setting width, height, orientation,
etc). That's not really a good place since this option is really about
the view as a whole. This changeset moves the item down to the bottom
of the context menu, next to the "Show In" action (which lets you show
the content in another Eclipse view.)

The code was tweaked a bit to be computed lazily (e.g. the contents of
the include list is not computed until the actual Show Included menu
is opened.)

Change-Id: Ic18997271e9ffde491a1a63e337ff015d762a20a
db6bf7972148e38434bccc283464de9272a1977e 07-Jan-2011 Tor Norbye <tnorbye@google.com> Replace Sdk.makeRelativeTo()

IPath#makeRelativeTo(IPath) was not supported on Eclipse 3.4, so we
had a local version of it in our sourcebase, as
Sdk#makeRelativeTo(IPath,IPath). However, our version only works
correctly for directories, not plain files, but I had been using it
for files as well.

Now that we no longer need to support Eclipse 3.4, remove our local
version and use the builtin path conversion method.

(Fixed some invalid javadoc too)

Change-Id: I233875e1ecc758eb1ed333686b319b138eb47c4a
a18a523fa3e21c78320fadd031716963b3a1c501 04-Jan-2011 Tor Norbye <tnorbye@google.com> Add "Extract As Include" refactoring

Add an "Extract As Include" action to the context menu which lets you
extract a set of selected views and move them into a separate layout
file of their own, and insert an <include> reference to the new view
in place.

You can select multiple items as well (provided they are adjacent
siblings) and in that case the newly extracted layout will use the
<merge> tag as the root element.

This changeset also adds a name validator for resource names, used
both in the new-name entry field for extracted include layouts, as
well as in the New XML File wizard. It enforces that the name (except
for the .xml suffix) is a valid Java identifier name (since otherwise
the R file will have compilation errors.)

This changeset also extracts various inlined String constants like
"xmlns", "android" (as used in namespace prefixes), "@id/" etc and
replaces them with constants.

Change-Id: I3eca8b6afd23f22ca9299ff22c614b4ffd3299bf
a5d2bf173d15b74a6bcf57220c4e73b971bd09ab 17-Dec-2010 Tor Norbye <tnorbye@google.com> Rewrite Outline drag & drop handler

Rewrite the drag source and drop target listeners for the Outline. The
drop target listener now uses the SWT Tree support for drag & drop
(such that you for example get drop position feedback lines between
siblings). You can now drag items within the outline to do precise
reordering, as well as target particular positions during drops,
either within the outline or from the canvas or the palette.

This changeset also fixes a number of other issues I ran into at the same time:

- Fix keyboard shortcuts such that they map to the same context as the
canvas (e.g. when you activate the outline it shows the same undo
context as if you click in the associated canvas)

- Fix a bug with context menu code when none of the options are
selected in the XML

- Fix selection dispatch. If you had two side by side canvases,
selecting items in the Outline would show highlights in both
canvases; it now only causes selection syncing with the associated
canvas.

Change-Id: I00c3c38fabf3711c826a3bc527356cbc77ad4a7e
95b17a5e62eeeb7b38ef668508df43a1ee9e0880 16-Dec-2010 Xavier Ducrohet <xav@android.com> LayoutLib API refactoring

Change-Id: I40abba4c4f786755c2a1c0e70df4d7bc08e2bcde
9d834f72299d90522f3b5b94b1cd192f8adff6fe 18-Dec-2010 Tor Norbye <tnorbye@google.com> Reenable Show Included In, and handle target compatibility

Hook up the Show Included In menu item to the layout library's
Capability.EMBEDDED_LAYOUT which tracks whether nested parsers are
handled by the layout library. Also handle this properly in the some
related scenarios: If you switch rendering targets on a page that is
already in an included context, remove that included context (since
otherwise you'll be editing the including file rather than the
included file_), and when you jump from an including file to an
included file, only set inclusion context if the target file is either
not open or its rendering target supports inclusion.

Also fix a bug in the initialization of capabilities; it was passing
the project target rather than the rendering target back from the
onXmlLoaded() method, which meant the clipping support flag was not
set correctly.

Change-Id: I2c1ae55d44fc627c56ecbcb76a7f163e8094f975
f6d27b7c5e8a94afadfdcf438b0b8bf838fb72c2 17-Dec-2010 Tor Norbye <tnorbye@google.com> Fix keyboard shortcut bug

13231: Keyboard shortcuts often don't work in the layout editor

We've had this bug where intermittently the keyboard shortcuts for
cut, copy, paste, undo, etc. haven't worked. Turns out it's not
intermittent at all: Our keybinding registration was wrong, which
meant that only the last opened editor would actually work; the global
actions would ALWAYS map to that one editor. I discovered this when I
happened to have two editors side by side!

The global action registration mechanism we were using assumes that
each view has its own IActionBar. That's generally true, but NOT for
editors! That means we have to re-register the action bindings
ourselves when the active editor changes. To do that, we register our
own IEditorActionBarContributor, which will notify us when the actions
need to be updated for editor activation.

Change-Id: Ia49246a1f0fd14a717efe591b04b1b6529b23922
0b53692921647bb943dd858dfb339851379f6233 15-Dec-2010 Tor Norbye <tnorbye@google.com> Fix canvas scrolling bug

Fix the bug where zooming in, then panning, then zooming out could
result in lost scrollbars or the canvas no longer being in the visible
viewport.

Also handle the page increment setting code more cleanly.

Change-Id: I5c8e6580259a3a925e74d700771e740eaa5eb95e
abb73f93a76b5bba7f179e313e6c4a174fdd796c 14-Dec-2010 Tor Norbye <tnorbye@google.com> Remove some actions before milestone

The Show Include facility doesn't work properly until we backport
layoutlib to all the 2.x SDK layoutlibs. The Play Animation test
isn't yet productized.

Change-Id: Ib4cd0f0cff029fe23ffaca72a96561a0d748f86f
4334bd632c12d4723c79594fc23b5c7df9ed84bd 15-Dec-2010 Tor Norbye <tnorbye@google.com> Only allow drag images for canvas drags

The outline view "reuses" the drag source listener for the canvas,
doing some tricks with mouse events to make it look like the drag is
originating within the canvas. However, the image previews of drags do
not work well in this case. Therefore, stash data on the drag souce
such that the drag source handler can only do image previews when the
drag source is really the canvas instead of the outline page.

Change-Id: I919264f001fa232053a0b9831ebc32ee22beb877
709cc4a34cd4bb02fad353d0baffab063f880a79 15-Dec-2010 Tor Norbye <tnorbye@google.com> Set layout editor scrollbar increments

Fix 13097: Gingerbread Layout Editor scroll bar bugs, part 1:
Set the layout editor scrollbar increments to 20 (they were 1, meaning
that each click on the scrollbar down button would scroll the view by
one pixel rather than a "chunk" like 20).

Set the scrollbar page increment to the visual height of the
canvas. This means that if you click below the visible range in the
scrollbar it will jump a full scrollbar increment, as expected.

(This is the first half of 13097. The second half deals with something
unrelated.)

Change-Id: I80c544b749d08d1fdc127d682ef8a75aed9aa8e7
1714fd536b42f9963c00e171a9d04319832564f2 09-Dec-2010 Tor Norbye <tnorbye@google.com> Add support for including within specific configurations

The current support for includes are limited to including a view
within the "base" layouts (defined in layouts/). This changeset
generalizes this to track ALL include-sources (such as an include from
the landscape version) and offers to let you view and edit the current
view within each of those specific configurations. The configuration
will be switched to one that is compatible with the outer, including
view. It is possible that this will switch to a different inner view;
that seems better than trying to force editing an inner view in an
outer view that won't actually be shown at runtime.

We should enhance the configuration chooser such that it will only
offer options in its various combo boxes that are compatible with the
inner view as well. That is not addressed by this changeset.

Change-Id: Id5171d367cf65e2403bbac1640a179de4b420bd6
4517a1f5f4f9fd21b6a611d8a40ac8b81a7bb9c5 29-Nov-2010 Tor Norbye <tnorbye@google.com> Include View Support

Add improved support for includes. You can now view and edit a layout
within another containing layout. On a page with includes, you can
double click to warp into the included layout, and it will be shown
within the container layout (but with a semi-translucent mask to make
it obvious that you are editing only the included content, not the
container.)

You can also right click on a view and choose "Show Included In",
which is a pull-right which lists all the other layouts that are
including this view. (If there are no such views, the menu item will
be empty).

In addition, this changeset adds code to detect if there are cycles in
the includes, and if so adds a problem marker in the Problems view
listing the offending chain of includes.

This is all managed by a new "IncludeFinder" class, which listens for
resource file edits (so it only kicks in when you save an XML file,
not after each XML edit). It scans layout XML files for includes and
maintains a map of file includes. This is done such that it can very
quickly provide a list of all files that are including a given target
file. This list is also persisted across IDE sessions via a project
property.

Also fixes outline-expansion to ensure that the outline always shows
the top level children.

Note: The include-relationships are based on the base layouts (the
ones in layouts/, not in customized versions in layout-land,
layout-port, etc.)

Change-Id: I710560f03f7e214219669af8ffba91874d9881b9
258742f83960f087b1a20fc34bac08dcbdd4100e 02-Dec-2010 Xavier Ducrohet <xav@android.com> Layoutlib API: updated API for insert/move/remove child.

Also added some new SceneStatus enums.

Change-Id: I225c58201d81cb1109d1d533fea48b6eacb2e286
8dcbdc76135c8cc6a48cfa9b3e05c183522aff41 30-Nov-2010 Xavier Ducrohet <xav@android.com> ADT: The image given to layoutlib now shares data with ImageData

We now create a custom BufferedImage that also includes a reusable
ImageData to generate SWT images. While there is still the AWT to
SWT conversion, at least most buffers aren't re-allocated every
time during animation. The only new allocation is the one done
in the Image constructor to pass the ImageData content to the native
image object.

This also fixes the tearing issue introduced in the previous
commit by calling ImageOverlay.setImage from the animation
listener callback. This should not be done in the UI thread
runnable as each rendering reuse the same bitmap.
When the animation listener callback returns, the image
will be reused for a new rendering so it's content will
change.

Also fixes the windows rendering by computing the proper
band offset based on the SWT palette Data.

Change-Id: Id57a3696bd92441271f6bee9681edefd12140b02
645b8a905ad70a7d0623dfbbfe6da720da038de9 30-Nov-2010 Xavier Ducrohet <xav@android.com> ADT/Layoutlib: New API to let the caller instantiate the bitmap.

This allows us to use a bitmap more compatible with SWT.

In ADT's case, because the bitmap needs to be converted to SWT
before being displayed, we create a BufferedImage using a byte[]
instead of a int[] so that we can simply do an array copy.

Also, we reuse the generated BufferedImage unless the size changed,
which lets us see less GC during animation playback.

Change-Id: I0062a4f4442ff6469cf0ad4f501c1fbe8c719400
668e2e80ca60a02afd98276aa1e989c0d939bdc5 30-Nov-2010 Tor Norbye <tnorbye@google.com> Replace reflection with Sdk.makeRelativeTo

Replace reflection-based invocation of IPath.makeRelativeTo
(which is not available in Eclipse 3.4) with usage of
Sdk.makeRelativeTo, our own copy of the equivalent code.

Change-Id: If67d985b96b845d85cf7fc13d47e9adeee49e8a8
e80f4d4d2ac48db8d94b6071e296a8acba32a09a 29-Nov-2010 Xavier Ducrohet <xav@android.com> ADT: more animation stuff.

Change-Id: I020342a4fe205161328f22e9dabb0b03343677b5
dc040487da0fed1b5f366c5435bdff3638bc37b6 30-Nov-2010 Tor Norbye <tnorbye@google.com> Rename some layout editor classes

This changeset contains only renaming of some classes (and a couple
of >100 column adjustments), no semantic changes.

The name changes are:

BaseView => BaseViewRule
BaseLayout => BaseLayoutRule
ScaleInfo => CanvasTransform
CanvasSelection => SelectionItem
PropertySheetPage2 => PropertySheetPage
OutlinePage2 => OutlinePage

Change-Id: I14d8c711b12154f4fcb2169129fd553e31fdab84
d9881e4b0ed00c7f7fd529f482cfd08b7d9ec396 25-Nov-2010 Xavier Ducrohet <xav@android.com> ADT: Animation preparation.

Update layoutlib API to work better with the new scene
locking mechanism (for concurrent renderings), new error
types in SceneResult, and updated Animation listener.

ADT changes to record the view object in CanvasViewInfo,
and the current LayoutScene in ViewHierarchy.

Added a test menu item to start an animation. This
is temporary and will be fixed later.

Change-Id: I67df2d116afdfd23c093e4645d4a0f99695c5d95
6d7a354cc1ad968a2bd17cc4b8db5814490a0f1d 19-Nov-2010 Tor Norbye <tnorbye@google.com> Show images during canvas drags

When you drag in the canvas, show a drag image for the view being
dragged. The drag image is using 30% translucency such that it does
not obscure the drag feedback below it.

We're grabbing the image data right out of the rendered scene and just
copying out the rectangles for the bounds of each selected item. This
has to take the canvas zoom into effect too.

While in the zoom code I modified the Zoom In and Zoom Out buttons to
only zoom by a factor of 20% rather than 100%.

I cleaned up the Pair class slightly; in an earlier version of this
fix I was using it to pass back two results from the rectangle
painting function; I don't do that anymore but the Pair might as well
be cleaned up.

(By the way, as suggested in review #19035 I rewrote the FIXME comment
related to resource lookup and put it in this CL rather than revising
the other one.)

Change-Id: Iabe6e29c4073252f5046e3c26b56f4e7674a3f3a
6678720fd8c27f10389efede23ee44a29b8fbd3d 24-Nov-2010 Tor Norbye <tnorbye@google.com> Replace IPath.makeRelativeTo call with reflection

I broke the build because on Eclipse 3.4 there is no makeRelativeTo
method on IPath. This replaces that call with reflection. This won't
work on 3.4, but it's a quick fix for the broken build.

Change-Id: Ia917cf5a745f76bbb96f59fae93e2a4fc4f5f900
99fd7eee15c89fd45b884842c44371326f851930 22-Nov-2010 Tor Norbye <tnorbye@google.com> Open included layout on double click

On double click, if the clicked area originates from an <include>'ed
XML file, open the included layout in the editor. Also opens
files in the @android: namespace if available, for example if you
inculde @android:layout/select_dialog_multichoice.

Change-Id: I215c411257717f7b97e7b0ee1d5498c318cdb04d
9672aa7c01849cbc4e11c1bd73c682fa4fc3241e 20-Nov-2010 Tor Norbye <tnorbye@google.com> Refactor selection painting to fix highlighting of included views

This changeset moves the painting of selection bounds and selection
hints out of the view rules and into the core IDE. The reason for this
is that the visual appearance of the selection shouldn't be up to each
rule; for one thing the selection highlight should be consistent and
not vary from view to view (and in fact there was only a single
implementation of the paint selection method among the view rules),
and for another the view rules are in theory sharable among IDEs
whereas the selection appearance is going to be IDE specific. There
was also painting of "hints" in the RelativeLayout; rather than having
the visual appearance of this dictated by the rule, this is also moved
into the IDE such that the rules only provide the hint text and the
hints are displayed by the IDE itself.

The above refactoring also fixes selection feedback for <include>'ed
views, which were not visually selectable because there was no
corresponding ViewRule, so nobody to paint selection. With these
changes selection painting is now independent of the rules.

Change-Id: I22dd926102128634a443b8bafb54d4764f1eda41
797aebac4aa55532cc42125e8f09e46e2b52879d 18-Nov-2010 Raphael Moll <ralf@android.com> Cleanup GRE preload.

GRE used to preload the groovy BaseView rule to improve
the first selection speed. We don't need that now that we
switched to a non-groovy engine.

Change-Id: Ib29272f28df6285137d62c45441cd9ac72efd10f
71f1ce4538caa9f7d0824c7f2090d95a6c6b7d71 12-Nov-2010 Xavier Ducrohet <xav@android.com> Update ViewInfo in the layoutlib API.

- support for View and LayoutParams
- support for default property value map.

Change-Id: I70028710b1f76329a8bd501428fbd68a14fafa1e
f29be828de51dbe2f55508cd620142e35cd19cbd 11-Nov-2010 Xavier Ducrohet <xav@android.com> Make ADT use the new layoutlib API.

ADT now exclusively use the new API.
The older platforms that still use the old API are
accessed through a compatibility layer provided by the class
LayoutBridgeWrapper that converts the old to the new API (both
input and output).

The wrapper and the loading code for the bridge have moved
to layoutlib_utils, but into the ide.common package.
Layoutlib_utils is to be renamed ide-common later.

.sdk.LoadStatus has moved into .ide.common too since
it's used by the bridge loading code. As we'll move
more code into ide-common it's ok to have it there anyway.

Also did some minor fix to the API:
- missing implementation of ViewInfo
- Made a singleton for SUCCESS state of SceneResult.

Change-Id: I5e7130ca03b92ad71dc9c293b2ffc40566df645c
23258d5ae21d164049eef14eebb2ef28a43a7b40 08-Nov-2010 Tor Norbye <tnorbye@google.com> Add transient visibility mode for empty containers

When you add a new container, such as a LinearLayout, it is usually
invisible. The reason for this is that an empty layout has 0 width and
0 height. There are two existing features in the layout editor to deal
with this: (1) Outline mode, which renders rectangles around all
views, and (2) Padding mode, which adds 10 pixels of padding to all
views. In combination, these two modes will create a rectangle for
empty layouts making them visible and user-manipulatable -- you can
for example select or drop into them.

This changeset attempts to make dealing with these types of containers
easier and more discoverable. It adds a new temporary mode where empty
containers (and only empty containers) are automatically padded and
have their outlines painted. And more importantly, this is only done
in some limited scenarios: When you drag into, or drag within, the
layout canvas. As soon as you finish the drag, empty containers
disappear again.

Unlike padding mode, we don't enlarge the design surface itself, since
this mode comes and goes easily and frequently.

In addition to this, there is special handling for selection. If you
select a zero-sized element (which for example is automatically done
when you drop a new layout, and which can also be done by clicking in
the outline), then the element is also revealed similar to the
show-empty mode, but in this case only the selected item and not any
other invisible containers are shown.

Change-Id: Ibf3ec6a080a50a8f0f55919c3d3e6c4d2890468d
83dba505e22985fd2f9414e7c6ef14ce29d31713 26-Oct-2010 Tor Norbye <tnorbye@google.com> Add gesture support, marquee selection, and refactoring

This checkin adds support for gestures and overlays. Gestures are
sessions of mouse/keyboard activity, and this is documented in the
javadoc for the new Gesture class. Overlays are units of graphics, and
these are documented in the Overlay javadoc. The gesture architecture
lets us isolate the logic for each different type of operation
(marquee, resize, move, etC), and with associated overlays we don't
attempt to for example paint drag feedback during a resize operation,
etc.

The checkin also adds marquee selection (as a second gesture, in
addition to the existing drag & drop based move gesture), along with
some associated changes in how the root view is treated.

As part of isolating the mouse handling and painting related to
gestures, painting etc., I also refactored the code quite a bit.
LayoutCanvas which used to be a large class has been split into a
number of new classes, one for each area of responsibility:

- The mouse listener and drag & drop code has been moved into a
GestureManager. (A lot of the drop handling code also came from the
CanvasDropListener class.)

- Code related to maintaining the set of rendered views, and
performing searches in the views, has been moved into a
ViewHierarchy class.

- Code related to selection has been moved into a SelectionManager.

- Various individual painting pieces (outline, hover, etc) have been
moved into individual Overlay classes such as OutlineOverlay,
HoverOverlay, SelectionOverlay, etc. This also moved associated
resource allocation and cleanup into the overlays.

- New coordinate classes, ControlPoint and LayoutPoint, are used
instead of ints and plain Points to make it really clear which
methods require coordinates in the layout (such as the
ViewHieararchy search methods) and which ones require coordinates in
the canvas control (such as paint methods). There are factory methods
to automatically construct the right kind of coordinate from
different types of mouse events, as well as methods to convert
between the two.

I also tweaked the visual appearance of selection a bit more, and
some other misc cleanup.

Change-Id: I666aabdcd36720bebe406b68237e8966d985fb8f
f544cb2a13c83bccfb03bf61109a570359dabc4d 28-Oct-2010 Tor Norbye <tnorbye@google.com> Select element surrounding caret when switching from editor

If you edit the XML, and then switch back to the visual editor, this
changeset will cause the element surrounding the caret (if any) to be
selected in the visual editor.

Change-Id: I1f03856b3b3946fe23d6e654773ee4318d0d56ed
76bbc57fcc07859cd1d7f1c9be102b1dc5218f27 27-Oct-2010 Tor Norbye <tnorbye@google.com> Warp to source editor on widget double click

Update mouse handler such that a double click will look up the
corresponding XML element, front the XML source editor and select the
text range (scrolling if necessary) to reveal the corresponding tag.

Change-Id: Iaa3d6f845c3fea190c304a07fab07314baa3f638
912d8df0ed1a06c559efeefb1a0958ba989178e3 25-Oct-2010 Tor Norbye <tnorbye@google.com> Support 3rd party layout rule loading, and rip out Groovy support

Add support for loading 3rd party .jars providing additional layout
rules. This can be configured by adding a property referencing the
jars to be loaded as part of your build.properties, like this:

default.properties:
...
layoutrules.jars=chart-rules.jar:graph-rules.jar
...

This will create a class loader referencing chart-rules.jar and
graph-rules.jar (as well as the visual editor's plugin class loader as
a fallback), and this class loader is used to load IViewRule
implementations.

In addition, this plugin rips out the various remaining Groovy hooks
and references that were earlier used to load Groovy scripts as layout
rules, and removes groovy from the load path and build symlinking
scripts.

Change-Id: Ia17a60259559ec86270726add258382a879117dc
63a966c7d8a08f175d1a8aee688c74d0090af888 25-Oct-2010 Tor Norbye <tnorbye@google.com> Add layout unit tests

Add layout unit tests, and some infrastructure for testing. Also fix
some formatting errors (>100 column lines) in the previous commit.

Change-Id: I3eabf30998ab7deb84df57e4d0c10cf57ee399d5
2be70bde5a6dcd6447c32ef55866020be372f96c 18-Oct-2010 Tor Norbye <tnorbye@google.com> Port layout rules to Java

We had a number of layout implementations in the tool written in
Groovy; these were hard to deal with because of lack of good tool
support (debugging didn't work, refactoring didn't work, code
completion didn't (always) work, go to declaration didn't work,
semantic checks like unused code didn't work, etc. etc.)

Since these layout helpers are only getting larger, replace them by
equivalent Java code to make development easier.

This checkin also moves the API classes formerly used by Groovy
scripts into a new package (next to the Java layout rules) under
com.android.ide.common (api and layout) since this code isn't Eclipse
specific and could be used by other IDE vendors.

These interfaces were left identical (only the package statements and
directory location changed), with two exceptions: I added a new method
called "in" to IAttributeInfo.java, and I added a parameter to
IViewRule's onInitialize method.

The Groovy code was kept as close to the original as possible; I
copied in the Groovy code, and then replaced the Groovy-specific
constructs (closure-iteration on collections, literal map syntax, etc)
with equivalent Java code. The only tricky part was ensuring that
Groovy's handling of the == and != operators were translated into
.equals calls.

Change-Id: Idf7660ddea3766eac0a4a65ce6524d3f5119f7b2
7181175ad101e53932d83ca7b6a794346e6e25e3 17-Oct-2010 snpe <snpe@snpe.rs> Integrate 3c36e33f into tools_r8. DO NOT MERGE.

Fixing Issue 11557: SWTError: No more handles exception on Eclipse

Change-Id: Ie5e7d8af8ef0376cd4d3e9afcfdd328c331a5d96
3c36e33fc67462c195e7ed198b8479af5aea1332 17-Oct-2010 snpe <snpe@snpe.rs> Fixing Issue 11557: SWTError: No more handles exception on Eclipse

Change-Id: I3eb6ddd0b11f8d16c6f441333ddd8c5a8e9dd477
ff438759bba6190a0ec162b3ea8d2cab41cf141f 18-Oct-2010 Tor Norbye <tnorbye@google.com> Set hover fill color

The code which paints the hover didn't actually set the hover fill color
on the graphics context so it was just blending with white. This happens
to be the color the fill was initialized to so the problem wasn't
noticeable.

Change-Id: I95f0eface23f2a772b687ba348997a3eac2d85a9
f955510e23524471d50874425ea64574b8067069 13-Oct-2010 Tor Norbye <tnorbye@google.com> Make drag and drop create a single undo operation

If you drag and drop a widget, you end up with two separate undo
operations: One which inserts the widget in its new location, and one
which deletes it from its former location. If you drag a widget
somewhere and then change your mind and press Undo, you will therefore
end up with *two* versions of the dragged widgets, since undoing just
once only undoes the source removal, not the target addition.

This changeset fixes this. It's not a very clean fix since drag and
drop is a protocol where the drag source and the drop handler are
deliberately not connected. We now create a single undo context before
calling the layout helper's drop handler, and when it has finished we
then remove the source, still within the current undo context. This is
done by having the drag source register a cleanup handler with the
global drag info object, and this handler is invoked from within the
drop target's undo operation.

This means that we end up creating the undo unit on the tool side
rather than in the layout helpers, where more specific undo labels
were assigned. To deal with this, there is a new function which
produces a suitable Undo name. It creates the name by considering
whether it's a move or copy, as well as the unqualified names of the
dragged element and the drop target. For example, when dragging from
the palette you may end up with "Drop Button in LinearLayout", and if
dragging a multiselection you may end up with "Move Widgets in
RelativeLayout", and so on.

Change-Id: I242b51e5a9c7cd9eae55aa4139c510cb26b0e8fb
d395f216757b7e16b4d0269df9f75b811b0934ad 14-Oct-2010 Tor Norbye <tnorbye@google.com> Select dropped elements

This changeset makes the drop handler select the set of elements that
were just manipulated. This means that if you drop a new element, it
is both more visible (useful if you drop it into a crowded layout) and
immediately available for customization via the property sheet. This
is also important when you drag & drop to move existing elements since
without this, dragging a selected element meant you would *lose*
selection.

There are some timing tricks involved similar to yesterday's focus
checkin because in multi-document drag & drop the view hiearchy (which
we must consult to find the visual objects corresponding to the XML
just added to the model) may not yet be ready.

Change-Id: Ifa2d492a03a02f24303dd7cc95ab653523fb1758
6b1b0c72b8efe92caa9b4c8531bccdc91f64e8ec 14-Oct-2010 Tor Norbye <tnorbye@google.com> Prevent accidental dragging of the root layout

The layout editor deliberately does not reset the selection if you
start dragging within the bounding rectangle of one (of possibly
multiple) selected widgets. However, since it's pretty easy to have
the root element selected, this sometimes means you end up trying to
drag an item only to realize you can't because everything fits within
the root bounding rectangle.

This changeset fixes this usability issue by making the root widget a
special case. If you are dragging *only* the root, things work as
before. But if you are trying to drag anything else, it will ignore
the root, which means that you can drag one or more items
independently of the root whether or not it is included in the
selection.

Change-Id: Ia7497659e57dcc6431c3760a53847268a8b90815
c99d904d53439c715e552d04304306a749e72a91 12-Oct-2010 Tor Norbye <tnorbye@google.com> Fix drag and drop of unselected item

If you have no selection and start dragging a view, nothing
happens. This fixes this such that when dragging begins, the item you
are dragging becomes selected. This also works where you have a
selection and you start dragging some other (non-selected) item.

Change-Id: I20fc400504f375b75c1ed17ec4850420a8500edd
c195f743486b4edd9064ac188efccfbb28cc8219 11-Oct-2010 Tor Norbye <tnorbye@google.com> Fix Issue 11735: The Delete key does not always work

Add Backspace as a key handler for the logical delete action.
Most Macs have a Delete key that actually corresponds to
a backspace action, so we must handle SWT.BS, not just
SWT.DEL. I didn't make this code Mac-specific since having
both backspace and delete work in the canvas editor to delete
the selection seems useful.

Change-Id: I8b0be10cb46ba8a16126bbc3cc59832414d7993a
1b7aa69940848edc01a44ec2c79a22c0f0b33259 07-Oct-2010 Tor Norbye <tnorbye@google.com> Visual adjustments to the layout feedback

This changeset makes a number of adjustments to the visual feedback
shown during layout dragging & dropping, selection, etc.

These are:

1. Render text on top of a translucent mask (white on a transparent
gray rectangle). This ensures that the text is readable regardless of
what content is under the text. We can't just use the background color
for the normal SWT drawString for two reasons: First, we need to
control the alpha of the background only (since we want the text to be
opaque and the background to be translucent), and second, we often
want to draw multiple lines of text, so we need to manually draw a
background rectangle which accommodates the maximum width of ALL the
lines such taht we don't have a ragged background.

2. Paint the outline mode lines using solid, translucent lines. And
adjust the bounding box computation in this case by 1 pixel such that
when you have adjacent boxes (such as in LinearLayout), you don't end
up with two thin lines next to each other creating a thick line.

3. Change the DrawingStyle internal API from "foreground" and
"background" colors to "stroke" (border) and "fill" (interior), with
individual alphas. This makes the color definitions simpler (for
example we don't need two separate styles, one for the selection
border and one for the selection interior).

4. Make the hover more subtle, using no border and just a light
translucent gray rectangle to only slightly draw attention to the view
under the mouse.

5. Change the appearance of selection to light blue and use a long
dashed border around it. The anchor lines are more faint and more
translucent to make them stand out less.

6. Change the appearance of the drop-preview to use a dash patterned
border identical to the selection border, but colored orange instead.
The matching border pattern will hopefully reinforce that the
drop-preview line is where the selection (also dashed) will go.

7. Use green to show available drop zones (the grid surrounding a
target in RelativeLayout, and the positions between elements in
LinearLayout).

8. For invalid drops, use a white X on a red background as the overlay
fill.

9. I replaced the oval+X pattern from the LayoutHelpers and replaced
them with the orange dashed insert-position lines. I also adjusted the
LinearLayout to draw the bounding boxes such that the middle of the
bounding box, rather than the top left edge, are aligned with the
insert position.

Change-Id: I85c77b9fa84b732a78aac635442f96e7ccfc3983
f7b9d60cd84559e14ffd39103c1e5c0875a5cbcc 02-Oct-2010 Tor Norbye <tnorbye@google.com> Add drawing styles to the layout helper API

Pull color constants out of the specific layout helper classes (groovy
scripts) and the canvas editor and use a generic style enum instead in
the interface, and associate the visual attributes (color, line style,
thickness, alpha) with a swt-specific enum on the editor side. There
is a single new API method which takes an enum parameter, which should
let us add drawing styles over time. By having the color definitions
on the tool side rather in the specific layout helpers it's not only
easier to change the colors but also easier to ensure that the
different helper all stay consistent as we change color schemes.

In the immediate term (next integration) I'll change some of the
colors; after that we should make the colors adapt to the chosen
theme, and eventually these should be provided via the SDK from the
themes themselves.

This changeset doesn't actually change the colors used for the various
types of visual feedback (selection, hover, drop-zone, etc) - I'll
investigate that next. For that reason I also didn't replace all the
various client-side color usage in the RelativeLayout.

Change-Id: Iddf4ace9006ec02d9907c3c37d539ab7414f1371
f925785d6911901547bcf4b6d7fc347c4fc6eef6 10-Sep-2010 Xavier Ducrohet <xav@android.com> New zoom controls in the layout editor.

New 100% and "real size" buttons. The real size
computes a scale value based on the dpi of the monitor
and the dpi of the layout device info.

Also cleaned-up the CustomToggle class to be a
CustomButton (toggle optional) as the 100% and
zoom in/out buttons are not toggles.

Migrated the clipping button to be set up through
a CustomButton.

Added groups of CustomButton, which are closer to
each others than normal.

Change-Id: Id4b6ed54b7f275f848333b04aeb42ef80e89ea9b
111e90374cf4a4945f0681176fae3495e77237e6 10-Sep-2010 Raphael Moll <ralf@android.com> ADT GLE2: adjust selection on right-click or drag.

Change-Id: I553e2d659f95d727e87df5d174d737a220a1685d
13bbd4f3631ee307bad27b0a6332997386dc9ba3 08-Sep-2010 Raphael Moll <ralf@android.com> GLE2: perform all context menu edits in the same undo session.

Change-Id: I9516066edaa1704725ab234f1a65664d5eabfb39
c5e3fb28271c347cdb1a54559213c26159c45439 07-Sep-2010 Raphael Moll <ralf@android.com> GLE2: fix executing actions on multi-selection

Change-Id: I057dca413d81c9ae3e00bc074eeb31b032f7e85e
c18e2262a9d0270e77b21d4ed24adff8e94c149a 07-Sep-2010 Raphael Moll <ralf@android.com> GLE2: Don't change the selection on right click > menu.

Change-Id: I94c4a1bc57287d250963456339aa24e6a10a92c0
56c41f2874aa80797670e165ee7377b6202702dd 03-Sep-2010 Raphael Moll <ralf@android.com> GLE2: Extract the dynamic context menu handling.

This is a pure refactoring that extracts the dynamic context
menu handling in a class outside of LayoutCanvas. The original
is long enough like this. It's used by the ouline view too.

Change-Id: I3a9e59bde2e9ceb69479490ca9179aab29cc13a6
4436a79853a8b2bd3f5e26e397d02cf4da804306 02-Sep-2010 Raphael Moll <ralf@android.com> GLE2: Context menu in Outline view.

Change-Id: I9e149310cd0b0ada5bb16262a2d6d833a54b3c93
315d4e3193144c3dd917b9a73bfcc91dfe931f02 02-Sep-2010 Raphael Moll <ralf@android.com> GLE2: Fix comments, refactor context menu code.

Simple refactor of the main method populating the dynamic context menu.
It was started to grow a bit too much.
Also added some comments to explain what's going on.

Change-Id: Id58779da5082bb454c1bcae914582e4471364a12
44a39167e3f9ee89e495716b7c3f0094ab91f2b1 02-Sep-2010 Raphael Moll <ralf@android.com> GLE2 context menu: Handle boolean properties as tri-state.

Also offer a clear option for enums and flags.

Change-Id: I682ba19d9f5a1c1d5da28909b02a90ec01f4fc62
eaba401355cb2258c4ccc0e2456fe1931f272c78 27-Aug-2010 Raphael Moll <ralf@android.com> GLE2 context menu support.

Context menu now shows some view properties:
- for all views, quick access to layout width/height.
- for LinearLayout, quick access to orientation.
- for all views, quick access to all boolean, enum or flag attributes.

Some follow up will be necessary in another CL, namely:
- booleans must be tri-states (true, false, cleared).
- need a way to clear enum and flags rather than just change the value.

Change-Id: Ie7451c21f0781f0efb0a1bbc676abef80027c4f7
2e43b58d4e4bf4a2dfbf2a605c8c309a0cfd01b6 27-Jul-2010 Raphael Moll <ralf@android.com> ADT GLE2: Remove (or disable) debug printfs.

Change-Id: I3d8a0f6b4731ee78af8da33c1749423ca7b13254
6ba96d00e4b6e91b53c7772eaf5b6a9b0f2894b3 22-Jul-2010 Raphael Moll <ralf@android.com> ADT GLE2: paste element in empty layout.

Change-Id: I792947e39d4b0ef7828f2df394bac81c0da37970
3af3a210c0cb8e92404b18874774d695a3733b5e 22-Jul-2010 Raphael Moll <ralf@android.com> ADT GLE2: implementation paste operation.

Change-Id: Ifc7b150eefd810a7c615fd9d3f26904e59c6c4aa
d784a5000d432260f9efe0ce5f62177f38dba6be 21-Jul-2010 Raphael Moll <ralf@android.com> ADT GLE2: Properly handle empty documents, including drag'n'drop.

This makes it possible to drop into empty documents.

Change-Id: I512d8ff5e8747e4d3f5e27900308157e75cacd57
2d4ab843366ad9959a783bea603e453b77923b47 20-Jul-2010 Raphael Moll <ralf@android.com> ADT GLE2: add 'Show In' submenu to canvas' context menu.

Change-Id: Ibad11e7872c529e3154b8f0abbfd02d26cac52cc
b0eb9343e26d7ff3cd03207edb32f4f6beb71f43 19-Jul-2010 Raphael Moll <ralf@android.com> ADT GLE2: delegate drop events from Outline to Canvas.

Change-Id: I19c108ec3f242a88e750522cf2acfdd017318937
a528d678b9a8b2d38030713281314c800e29a9ef 18-Jul-2010 Raphael Moll <ralf@android.com> ADT GLE2: drag from Outline view.

The drag source listener delegates the handling to the canvas.

Changed the OutlinePage2 to no longer listen to parts activations.
Instead there's one instance of OutlinePage2 per instance of
the GraphicalEditorPart and the link is provided in the constructor
directly.

Change-Id: I8bee65b2a7f75bd1436082c9a9753c561d8a6cab
5a890257d1dfd1289455963fd4d288b61c2b99d7 17-Jul-2010 Raphael Moll <ralf@android.com> ADT GLE2: Link outline's context menu to active canvas' menu.

Change-Id: I29712077a340276f0cde0c9c1ecf75f2e931e515
a8aa7f294fd280a5e27d3cabbb994f8336905e61 16-Jul-2010 Raphael Moll <ralf@android.com> ADT GLE2: cut/copy/delete/select-all global actions.

Also provides a linked context menu for the canvas.
Paste action is in the menu but will be implemented in a next CL.

Change-Id: Iccd3663b5e0db16f44ae2f9a0c2c9271926fe8c2
f3199b3448c9c80d68a3bce8b3166632d9b3e767 01-Jul-2010 Raphael Moll <ralf@android.com> ADT GLE2: synchronized selection between canvas, outline and properties.

This CL adds a LayoutCanvasViewer, a JFace viewer wrapping the
LayoutCanvas control. This allows the canvas to participate in the
workbench "site" selection.

To summarize:
- The workbench site selection service can be seen as "centralized"
service that registers selection providers and selection listeners.
- The editor part and the ouline are selection providers.
- The editor part, the outline and the property sheet are listener
which all listen to each others indirectly.
- Hilarity ensues.

I tried to add enough javadoc in the classes to explain what's
going on, so please tell me if more is needed. (Editor part also
has a link to the one web page article that brings some sense to
this stuff. I recommend reading the web page first.)

Change-Id: Ief83f9fe2fc1cb5c0c1fa9ae174a58c8daf17ac4
32adc869c620dc06b20bb73cc1b311f13fa277cb 29-Jun-2010 Raphael Moll <ralf@android.com> ADT GLE2: Synchronize selection outline->canvas

Change-Id: I21458fe649b2d62390edba5ea107afe888185d3f
c764c1322675deb7a659b32b534a5e8dc0bace18 25-Jun-2010 Raphael Moll <ralf@android.com> ADT GLE2: Outline Page, display root, preserve state.

- Correctly displays the root element of the layout.
- Preserve select and expanded state when reloading layout.

Change-Id: Ic5786d08fe4e36f02ff658f23e66c66f372f58f8
0f69215be7b5db49c7ac4eeddd13c9f53ffa1917 24-Jun-2010 Raphael Moll <ralf@android.com> ADT GLE2: Outline with selection synchronized from canvas.

Next CL will be selection synchro outline->canvas.

Change-Id: I0e395313f0365830db7eb96e33077844d68f301e
6eb888f5ea588b57ad6e4e1f01b1b015d71f9837 18-Jun-2010 Raphael Moll <ralf@android.com> ADT GLE2: drag'n'drop for LinearLayout

Change-Id: I64959e27f2c08c459e15323d7c8d2cdb041ba9dd
c4e3431fab6279bf4d7a2a0a9dac79a35d457c65 11-Jun-2010 Raphael Moll <ralf@android.com> ADT: Refactor AndroidEditor into AndroidXmlEditor.

Next we'll introduce a new AndroidTextEditor base class.

Change-Id: I2cdf4c7cb7a2eec03f7c523294a14f98bfd072f8
e14ec6a79ed9853ca088d8095fef9fb97bfb2819 05-Jun-2010 Raphael Moll <ralf@android.com> ADT GLE2: Restore relative position of elements in AbsoluteLayout drop.

Change the IDragElement to not carry the original INode, since
this is not available when crossing Eclipse instances. Instead
encode the info we need in the transfer.

Change-Id: I90a1e71171af61e51e8aaded31e05300fa85c014
4b12555c96a7f16773594a13760e50aa5f60473f 05-Jun-2010 Raphael Moll <ralf@android.com> ADT GLE2: remove source elements after a drag'n'drop MOVE operation.

Change-Id: Ic0560466a3ccfb3a5eeb077b1eae508828870629
f7ac8c8f101712a2a2a437ac7f77b5d3588cebca 04-Jun-2010 Raphael Moll <ralf@android.com> ADT GLE2: Generate items on drop in AbsoluteLayout.

Change-Id: Iaf943b476db553cd39f5c3ee4f9c47ad3cdc6246
c2b0492f49775b23072032d639879a77b41b1392 01-Jun-2010 Raphael Moll <ralf@android.com> ADT GLE2: Script for AbsoluteLayout for new canvas drag API.

Most of the changes concern the supporting API (INode and co)
to be able to recreate and mofiy the XML elements.

Change-Id: I9ab62b3fe125faed1b647f1735f8ff0afd33a5d9
671636a1a16dbe4fb73509b5e3cb92ca96a778c7 25-Mar-2010 Raphael <raphael@google.com> ADT GLE2: Drag from canvas

The groovy scripts need to be changed and will be
part of the next CL (only the base view one has been
adapted here.)

Change-Id: If91602b36a3b147f6a18c9c9538d6d9bec5ecea0
d6e63f09f2a1cb7dec396643bc692490b82a56a8 06-Mar-2010 Raphael <raphael@google.com> ADT GLE2: Fix drop coordinates, add FrameLayout.groovy

1- Fix computation of scrolled drop coordinates: margin constant
should not be used directly and is now private to the Scaling
helper class. The Drop class now defers to the Canvas to convert
display coordinates into canvas image coordinates.

2- Fixed a small bug when LinearLayout was computing the
insertion point when there were no children.

3- Added a basic FrameLayout for drop support.

Change-Id: Iaf1305bd3df16b62fe29568eb811d36704f86482
c938e18817f661db5734b72f37740295631d0fcf 27-Feb-2010 Raphael <raphael@google.com> ADT GLE2: Support for drop on RelativeLayout children.

Change-Id: I6ed9f1d89f61caf6141f23708854a01247ab5518
58fdbd459ca4aa6ec51b0cd54fbb3bf0851d8648 24-Feb-2010 Raphael <raphael@google.com> ADT GLE2: Support zoom and scrollbar in canvas.

Change-Id: I98442be1d01cff0227244c4e1d346b8642106a79
d4963dc4347c871be5faa76920709001490e1d2a 24-Feb-2010 The Android Open Source Project <initial-contribution@android.com> snapshot
3b4aa24f4e7907e349e8d023f2942cd66b98628b 23-Feb-2010 Raphael <raphael@google.com> ADT GLE: fix scrollbar in palette composite.

Change-Id: Ic9bd947b7b6b52f69f6eab9c4d38e63557b23c70
b00ece99b2cc8289816767f246143904ce10c56c 22-Feb-2010 Raphael <raphael@google.com> ADT GLE: Experiment with d'n'd in RelativeLayout.

Change-Id: Ic737d5273b55a4ec78c1d9789616e1e296b77b00
711b740554e21080f2ed5358d14027fddda3dc80 18-Feb-2010 Raphael <raphael@google.com> ADT GLE: new IViewRule interface for Drag'n'drop.

With implementation for AbsoluteLayout and LinearLayout.

Change-Id: If8d6301abcc848574b3ab5d8894396a0246b1275
9aefc33d152479079646809e1572541aab1ced10 09-Feb-2010 Raphael <raphael@google.com> ADT GLE2: Implement IViewRule.onChildSelected.

Revamp the IViewRule.on[Child]Selected to not return a closure.
There is no actual event at selection time.
Instead the callback is called directly to paint the canvas.

Change-Id: I2b50fbdff734b9c1a2c581ca5958bac43e5f325f
8d4922b07d0c4dff56e4d2fda919d7bc0418495d 09-Feb-2010 Raphael <raphael@google.com> ADT GLE2: support isMultipleSelection.

Problem is easily solved by making this a parameter
in the closure, so we don't need to ask rules to give
us a different closure, they just need to redraw.

Change-Id: I4445c826b03bbb978bf085905ccd67d5e03b0356
218e0a497a51f26a91c4f1c7bbfc9fc040b89644 05-Feb-2010 Raphael <raphael@google.com> GLE2: IViewRule callback for selection.

Details:
- This moves the selection drawing from the LayoutCanvas to
the groovy script.

- There's a single IViewRule "onSelected" method. The script
which implement it return a closure (aka an anonymous method)
that does the actual drawing.

- onSelected is called during the actualy selection or when
the canvas is refreshed. The rendering closure is actually called
later during the canvas onPaint.

Here I am mostly testing the logic of having a script callback
handle an event (the selection) and returning a closure that
does the drawing later (during onpaint).
The main rationale for separating them is that the GC needed to
draw isn't available during the actual selection event.

I plan to reuse this mechanism for drag'n'drop & co.

TODO: layout selection is broken and will be fixed in another CL.
TODO: onChildSelected will be next.
TODO: Originally I had plans for onSelected(isMultipleSelection),
which I'm not sure I'll actually add later anyway., I fail to
see the point in implementation.

Change-Id: Ibc5fecbd107429df1f53b2b8172aba55e6289795
1a9d30498bb489a8a7704a86eeb6effd92f35f3b 15-Jan-2010 Raphael <raphael@google.com> ADT GRE: Move gscripts package.

Moving the public API from com.android.ide.eclispse.adt.gscripts
to ...adt.editors.layout.gscripts.

Change-Id: Idf5b979d47dbbbe2514cce8cc3c688eb273bcce6
4e737d9e263fc883fc7d19c72cf7ee6cf4863ada 14-Jan-2010 Raphael <raphael@google.com> ADT GLE: pass RulesEngine to LayoutCanvas.

This fixes a corner case where the canvas might find
itself using a null RulesEngine.

Change-Id: I9c5f2ec7f3d4e98d35995d5529f00d15ebd76faa
e13151727c63786342cddc3ea355425582bd4e7a 13-Jan-2010 The Android Open Source Project <initial-contribution@android.com> android-2.1_r1 snapshot
85b71f0b039e7d100376126d4314d90fad578ce5 04-Jan-2010 Raphael <raphael@google.com> ADT GLE: defer drop to first parent view that accepts it.

Change-Id: I021539e26a1feb0f5a89d907142ed4532fae8320
8fbb33e21e7b6c0d13c9b368c4a24f6c13809027 02-Jan-2010 Raphael <raphael@google.com> ADT GRE (Groovy Rules Engine), drag'n'drop.

Start support for drag'n'drop. with visual feedback.

Change-Id: I27f896c2e954dec0cb43103417d888d8df5a288e
4b26e04436587890f9245eda631f643d21f28d0d 26-Dec-2009 Raphael <raphael@google.com> ADT GRE (Groovy Rules Engine), part 1.

This CL adds the new "Groovy Rules Engine" (GRE) to the GLE2.

The rules engine can load groovy files located in the ADT
namespace or the project associated with the current GLE2.
Each groovy file defines a class with callbacks invoked
by the LayoutCanvas.
Project rules are reloaded when they change.

Change-Id: I168234da739b2120374d3eb4552169f7dd36439d
eb6a30bc642ce3ea1ebf0e45ec6113ee94391be0 19-Dec-2009 Raphael <raphael@google.com> ADT: GLE toggle buttons in configuration composite.

New GLE2 toggles:
- explode view
- show borders

Change-Id: I638b1d4591bee4729be7b4dff753cb166b3eaa61
fe56e7727202f85b4a682b2dce6558607c8cf0df 19-Dec-2009 Raphael <raphael@google.com> ADT: Refactor GLE1 and GLE2 classes in their own package.

This means we have to change a couple classes to public
instead of package protected. However it makes it easier to
read the project and see what files we'll want to deprecate
with GLE1.

Change-Id: I2c1b68ce27773253473cbef5bcef085f9eecfafe