Changeset 430
- Timestamp:
- 04/23/08 14:05:46 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/MapFish/client/mfbase/mapfish/widgets/toolbar/Toolbar.js
r415 r430 66 66 */ 67 67 configurable: false, 68 69 /** 70 * Property: buttons 71 * Array({<Ext.Toolbar.Button>}) 72 */ 73 buttons: [], 68 74 69 75 /** … … 89 95 * Parameters: 90 96 * control - {<OpenLayers.Control>} 91 * options - the config object 97 * options - the config object for the newly created Ext.Toolbar.Button 92 98 * 93 99 * Returns: 94 * An instance of Ext.Toolbar.Button100 * {<Ext.Toolbar.Button>} The added button instance 95 101 */ 96 102 addControl: function (control, options) { … … 100 106 var mb = new Ext.Toolbar.Button(options); 101 107 mb.tooltip = control.title; 102 mb.enableToggle = true;108 mb.enableToggle = (control.type == OpenLayers.Control.TYPE_TOGGLE); 103 109 if (control.isDefault) { 104 110 mb.pressed = true; … … 106 112 } 107 113 mb.scope = this; 108 mb.handler = function() { this.activateControl(control); } 114 mb.handler = function() { 115 this.activateControl(control); 116 }; 109 117 this.add(mb); 118 this.buttons.push(mb); 110 119 return mb; 111 120 }, … … 115 124 * Pass in the CLASS_NAME of a control as a string and return the control itself 116 125 * 117 * Param aters:126 * Parameters: 118 127 * className - string 128 * 129 * Returns: 130 * {<OpenLayers.Control>} The requested control. 119 131 */ 120 132 getControlByClassName: function(className) { … … 126 138 } 127 139 } 140 return null; 141 }, 142 143 /** 144 * Method: getButtonForControl 145 * Pass in a control and return the button attached to this control 146 * 147 * Parameters: 148 * control - {<OpenLayers.Control>} A control which was previously added to the toolbar 149 * 150 * Returns: 151 * {<Ext.Toolbar.Button>} The requested button. 152 */ 153 getButtonForControl: function(control) { 154 if (this.controls) { 155 for (var i = 0; i < this.controls.length; i++) { 156 if (this.controls[i] == control) { 157 return this.buttons[i]; 158 } 159 } 160 } 161 return null; 128 162 }, 129 163 130 164 /** 131 165 * Method: activate 166 * Activates the toolbar, either by restoring a given state (if configurable) or the default one. 132 167 */ 133 168 activate: function() { … … 138 173 mb.menu = new Ext.menu.Menu(); 139 174 for(var i = 0; i < this.controls.length; i++) { 140 mb.menu.add({'style': 'height:25px', 141 'text': '<div style="position: relative; left: 25px; top: -15px;" class="' + this.items.items[i].iconCls + '"/>', 142 checked: this.controls[i].visible, 143 scope: {toolbar: this, button: this.items.items[i], control: this.controls[i]}, 144 checkHandler: function(item, checked) { 145 if (checked) { 146 this.control.visible = true; 147 if (this.control == this.toolbar.defaultControl) { 148 this.toolbar.activateControl(this.control); 149 } this.button.show(); 150 } else { 151 this.control.visible = false; 152 this.control.deactivate(); 153 this.button.hide(); 154 } 155 this.toolbar.saveState(); 156 }}); 175 mb.menu.add({ 176 'style': 'height:25px', 177 'text': '<div style="position: relative; left: 25px; top: -15px;" class="' + this.buttons[i].iconCls + '"/>', 178 checked: this.controls[i].visible, 179 scope: { 180 toolbar: this, 181 button: this.buttons[i], 182 control: this.controls[i] 183 }, 184 checkHandler: function(item, checked) { 185 if (checked) { 186 this.control.visible = true; 187 if (this.control == this.toolbar.defaultControl) { 188 this.toolbar.activateControl(this.control); 189 } 190 this.button.show(); 191 } else { 192 this.control.visible = false; 193 this.control.deactivate(); 194 this.button.hide(); 195 } 196 this.toolbar.saveState(); 197 } 198 }); 157 199 } 158 200 this.add(mb); 159 } else {201 } else if (this.defaultControl) { 160 202 this.activateControl(this.defaultControl); 161 203 } … … 164 206 /** 165 207 * Method: deactivate 208 * Deactivates all controls in this toolbar. 166 209 */ 167 210 deactivate: function() { 168 211 for(var i = 0; i < this.controls.length; i++) { 169 212 this.controls[i].deactivate(); 213 if (this.controls[i].type != OpenLayers.Control.TYPE_BUTTON) { 214 this.buttons[i].toggle(false); 215 } 170 216 } 171 217 }, … … 191 237 c.visible = s.visible; 192 238 if (!c.visible) { 193 this. items.items[i].hide();239 this.buttons[i].hide(); 194 240 } 195 241 } … … 216 262 /** 217 263 * Method: activateControl 218 * Activate a control on the map264 * Activates a control on the map 219 265 * (Taken from OpenLayers.Panel) 220 266 * … … 223 269 */ 224 270 activateControl: function (control) { 271 var button = this.getButtonForControl(control); 272 if (!button) { 273 OpenLayers.Console.warn("Toolbar.activateControl : button was not found"); 274 return; 275 } 225 276 if (control.type == OpenLayers.Control.TYPE_BUTTON) { 226 277 control.trigger(); … … 230 281 if (control.active) { 231 282 control.deactivate(); 283 button.toggle(false); 232 284 } else { 233 285 control.activate(); 286 button.toggle(true); 234 287 } 235 288 return; … … 238 291 if (this.controls[i] == control && control.visible) { 239 292 control.activate(); 293 button.toggle(true); 240 294 } else { 241 295 if (this.controls[i].type != OpenLayers.Control.TYPE_TOGGLE) { 242 296 this.controls[i].deactivate(); 297 this.buttons[i].toggle(false); 243 298 } 244 299 }
