Ticket #67 (closed enhancement: fixed)

Opened 10 months ago

Last modified 9 months ago

controls as buttons and menu items

Reported by: elemoine Assigned to:
Priority: major Milestone: 0.5
Component: widgets Version:
Keywords: Cc:
State: Commit

Description

Add some adapter to be able to add controls as buttons in an Ext.Toolbar and as items in an Ext.menu.Menu.

Attachments

patch-67-r830-A0.diff (29.5 kB) - added by elemoine on 05/20/09 08:37:23.
patch-67-r875-A1.diff (30.0 kB) - added by elemoine on 05/28/09 05:52:10.
67.patch (29.9 kB) - added by tschaub on 05/29/09 20:52:49.
create GeoExt actions with OL controls and (optionally) a map

Change History

05/20/09 08:37:23 changed by elemoine

  • attachment patch-67-r830-A0.diff added.

05/20/09 08:50:41 changed by elemoine

  • state changed from None to Review.
  • milestone set to 0.1.

patch-67-r830-A0.diff provides:

  • the GeoExt.Action class implementing the actual functionality
  • the GeoExt.Action.fromControl method for creating a GeoExt.Action from an OpenLayers control
  • unit tests
  • an example showing how to insert controls in buttons and menu items

The example works in FF3, IE6 and IE7. The unit tests pass in FF3, IE6 and IE7.

I've been hoping that this patch could go in 0.1. Release Manager, tell me if this patch comes to late for being included in 0.1.

Note: we can think of introducing GeoExt.Toolbar in the future, this toolbar would overload the "add" method so it accepts controls as its arguments, and wraps them in GeoExt.Action instances.

05/28/09 05:52:10 changed by elemoine

  • attachment patch-67-r875-A1.diff added.

05/28/09 05:54:23 changed by elemoine

patch-67-r875-A1.diff adds some css to the toolbar.html example to work around an Ext rendering bug in IE (the checkboxes in the menu items were not correctly placed).

05/29/09 20:52:49 changed by tschaub

  • attachment 67.patch added.

create GeoExt actions with OL controls and (optionally) a map

05/29/09 21:10:57 changed by tschaub

  • state changed from Review to Commit.

Eric, this is really nice work. Thanks for putting it all together.

I'm hoping you'll be amenable to one small change in the code that changes the pattern for app developers. In the constructor, I added these lines in the if(ctrl) condition:

// If map is provided in config, add control to map.
if(config.map) {
    config.map.addControl(ctrl);
}

Your example was using syntax like the following:

var ctrl = new OpenLayers.Control();
map.addControl(ctrl);
var action = GeoExt.Action.fromControl(ctrl, {
    text: "my action"
});

With the change in the constructor, this can be written as:

var action = new GeoExt.Action({
    text: "my action",
    control: new OpenLayers.Control(),
    map: map
});

The latter feels more like Ext to me.

With this change, the only reason I can see for GeoExt.Action.fromControl is to use the initialConfig from an existing action. As an alternative, someone could write something like:

var action2 = new GeoExt.Action(Ext.applyIf({control: ctrl}, action1));

The benefit of using this syntax instead of the fromControl method is that you can also add the control to a new map in the same call:

var action2 = new GeoExt.Action(Ext.applyIf({control: ctrl, map: map}, action1));

Anyway, I'm not opposed to the fromControl method, but think we should copy Ext patterns where we can.

So, if you like putting the map.addControl(ctrl) step in the action constructor, please commit (tests pass in FF3 and IE7). If you don't like it, I'm interested to hear why.

Thanks.

05/29/09 21:30:21 changed by tschaub

And, I see that if you want the scope and handler from the original action, you'd have to use action1.initialConfig in the applyIf above.

This raises a question for me though. Because of the way you are using uScope etc, it looks like you can't use GeoExt.Action.fromControl to create an action that uses scope/handler from another GeoExt.Action.

Out of curiosity, what is the use for having one action "extend" another in this way?

I've created new UI components (e.g. button) that share an action but have different properties (e.g. text), but I can't immediately see why you'd want two actions that shared things like scope and handler.

Thanks for any insight.

06/02/09 00:18:21 changed by tschaub

Based on http://www.geoext.org/pipermail/dev/2009-May/000169.html, I think we're on the same page. Thanks again for this great work. It will be good to have in the release.

06/02/09 06:53:14 changed by elemoine

  • status changed from new to closed.
  • resolution set to fixed.

(In [941]) make it easy to have controls as buttons and menu items, r=tschaub (closes #67)