aboutsummaryrefslogtreecommitdiffstats
path: root/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/api/MenuAction.java
Commit message (Collapse)AuthorAgeFilesLines
* Action API improvementsTor Norbye2011-08-151-669/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Layout Actions bar fixesTor Norbye2011-02-081-2/+23
| | | | | | | | | | | | | | | | | | | This changeset fixes a couple of layout actions bar issues: (1) Refresh the actions bar after running one of the layout actions. This for example fixes the issue that if you click to toggle the layout orientation then the baseline button will appear for horizontal layouts. (2) Fix an issue with the lazy-initialization of dropdown menus; they weren't actually initialized lazily because the code to determine whether a choice list should be a dropdown or a radio group would cause initialization. (3) Fix layout gravity on RelativeLayouts; it was reading/writing the attribute "layout_gravity" instead of "gravity". Change-Id: Ic41158257b3938a2e6daa8714dcd15d6bf21fa2f
* Add Layout Actions toolbarTor Norbye2011-02-071-2/+234
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Move Pair and annoatations into resources.jar now renamed as common.jarXavier Ducrohet2011-01-281-1/+1
| | | | | | | Move all the resource query methods that returned an array of 2 Strings to return a pair of ResourceType and String. Change-Id: I6b8447aa27005de786e2defef81ad88a72363523
* Add per-view custom initialization logicTor Norbye2010-11-191-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This changeset adds support for adding custom-logic to initialize views, both to add children and default attributes and to customize layout attributes when added to a new parent. First, there is a new "onCreate" hook which is called to notify a view rule that an instance of its corresponding view has been created. This lets the ViewRule perform custom initialization of the object. The ViewRule is told what type of insertion occurred, such that it can distinguish between a newly created view, a view that is the result of a copy/paste, and a view that is part of a move operation. The changeset adds a number of new ViewRules which take advantage of this: - A TabHost rule creates the various skeleton children that are required, such as a TabWidget child with id @android:id/tabs and a FrameLayout child with id @android:id/tabcontent - A DialerFilter rule creates the mandatory EditText children ("hint" and "primary") - The HorizontalScrollView rule creates a horizontal LinearLayout child - The ImageButton and ImageViewButtons initialize the "src" attribute to a sample image - The MapViewRule initializes the apiKey attribute In addition, views are also notified when a new view is added as a child, such that they can perform additional customizations, in the form of an "onInsert" event. The most important application of this is LinearLayoutRule, which uses this to set reasonable defaults for the layout_width and layout_height parameters. It uses metadata (which is currently built into ADT but would ideally migrate into our XML config files) to determine whether a given child prefers to grow horizontally, grow vertically, both, or neither, depending on the surrounding parent context. For example, an EditText will default to filling the parent width if it is in a vertical LinearLayout, but it will not grow vertically in a horizontal linear layout. And so on. Various other rules also use the onInsert event to tweak children attributes. A ScrollView will for example always initialize its single child to match parent. Views can now also add plain menu items into the context menu, and the TableViewRule adds one such action: "Add Row", which appends a new row into the table. The Palette Preview code also invokes these creation hooks, such that if you for example drag a DialerFilter it can properly render since the mandatory children are created up front. This required various changes to the preview code to be able to handle XML edits by the rules. Finally, this changeset includes various other misc changes that I performed at the same time: - Removed SWT dependency from the ViewRule classes (SWT Rectangle use in Rect) - Fixed AbsoluteLayout unit test (issue 3203560) - Fixed positioning of the preview outline in LinearLayout when only one of the dimensions are clipped due to a smaller target layout Change-Id: I5956fe4e7a31a20b8dd2f9d9b0c1f90e2f75d68a
* Port layout rules to JavaTor Norbye2010-10-221-0/+416
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