[Commits] r2522 - in core/trunk/geoext: lib/GeoExt/widgets tests/lib/GeoExt/widgets
commits at geoext.org
commits at geoext.org
Thu Dec 9 22:15:19 CET 2010
Author: ahocevar
Date: 2010-12-09 22:15:19 +0100 (Thu, 09 Dec 2010)
New Revision: 2522
Modified:
core/trunk/geoext/lib/GeoExt/widgets/Action.js
core/trunk/geoext/tests/lib/GeoExt/widgets/Action.html
Log:
Allowing actions to activate controls when enabled. r=tschaub (closes #386)
Modified: core/trunk/geoext/lib/GeoExt/widgets/Action.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/Action.js 2010-12-09 19:17:10 UTC (rev 2521)
+++ core/trunk/geoext/lib/GeoExt/widgets/Action.js 2010-12-09 21:15:19 UTC (rev 2522)
@@ -42,10 +42,24 @@
*/
control: null,
+ /** api: config[activateOnEnable]
+ * ``Boolean`` Activate the action's control when the action is enabled.
+ * Default is ``false``.
+ */
+
+ /** api: property[activateOnEnable]
+ * ``Boolean`` Activate the action's control when the action is enabled.
+ */
+ activateOnEnable: false,
+
/** api: config[deactivateOnDisable]
* ``Boolean`` Deactivate the action's control when the action is disabled.
* Default is ``false``.
*/
+
+ /** api: property[deactivateOnDisable]
+ * ``Boolean`` Deactivate the action's control when the action is disabled.
+ */
deactivateOnDisable: false,
/** api: config[map]
@@ -98,6 +112,8 @@
var ctrl = this.control = config.control;
delete config.control;
+ this.activateOnEnable = !!config.activateOnEnable;
+ delete config.activateOnEnable;
this.deactivateOnDisable = !!config.deactivateOnDisable;
delete config.deactivateOnDisable;
@@ -240,6 +256,9 @@
* Override method on super to optionally deactivate controls on disable.
*/
setDisabled : function(v) {
+ if (!v && this.activateOnEnable && this.control && !this.control.active) {
+ this.control.activate();
+ }
if (v && this.deactivateOnDisable && this.control && this.control.active) {
this.control.deactivate();
}
Modified: core/trunk/geoext/tests/lib/GeoExt/widgets/Action.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/widgets/Action.html 2010-12-09 19:17:10 UTC (rev 2521)
+++ core/trunk/geoext/tests/lib/GeoExt/widgets/Action.html 2010-12-09 21:15:19 UTC (rev 2522)
@@ -459,6 +459,31 @@
t.eq(act2.control.active, false, "enabling action does not activate control");
}
+ function test_activateOnEnable(t) {
+ t.plan(7);
+
+ var act1 = new GeoExt.Action({
+ control: new OpenLayers.Control(),
+ map: new OpenLayers.Map()
+ });
+ t.eq(act1.activateOnEnable, false, "false by default");
+
+ var act2 = new GeoExt.Action({
+ control: new OpenLayers.Control({active: false}),
+ map: new OpenLayers.Map(),
+ disabled: true,
+ activateOnEnable: true
+ });
+ t.eq(act2.activateOnEnable, true, "set to true");
+ t.eq(act2.control.active, false, "control not active");
+ t.ok(act2.isDisabled(), "action not yet enabled");
+
+ act2.enable();
+ t.ok(!act2.isDisabled(), "action enabled");
+ t.eq(act2.control.active, true, "control activated on enable");
+ act2.disable();
+ t.eq(act2.control.active, true, "disabling action does not deactivate control");
+ }
</script>
<body>
<div id="toolbar"></div>
More information about the Commits
mailing list