OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 cr.define('options.system.bluetooth', function() { | 5 cr.define('options.system.bluetooth', function() { |
6 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; | 6 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; |
7 /** @const */ var DeletableItem = options.DeletableItem; | 7 /** @const */ var DeletableItem = options.DeletableItem; |
8 /** @const */ var DeletableItemList = options.DeletableItemList; | 8 /** @const */ var DeletableItemList = options.DeletableItemList; |
9 | 9 |
10 /** | 10 /** |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 * paired: boolean, | 130 * paired: boolean, |
131 * bonded: boolean, | 131 * bonded: boolean, |
132 * connected: boolean, | 132 * connected: boolean, |
133 * pairing: string|undefined, | 133 * pairing: string|undefined, |
134 * passkey: number|undefined, | 134 * passkey: number|undefined, |
135 * entered: number|undefined}} device | 135 * entered: number|undefined}} device |
136 * Description of the bluetooth device. | 136 * Description of the bluetooth device. |
137 * @return {boolean} True if the devies was successfully added or updated. | 137 * @return {boolean} True if the devies was successfully added or updated. |
138 */ | 138 */ |
139 appendDevice: function(device) { | 139 appendDevice: function(device) { |
| 140 var selectedDevice = this.getSelectedDevice_(); |
140 var index = this.find(device.address); | 141 var index = this.find(device.address); |
141 if (index == undefined) { | 142 if (index == undefined) { |
142 this.dataModel.push(device); | 143 this.dataModel.push(device); |
143 this.redraw(); | 144 this.redraw(); |
144 } else { | 145 } else { |
145 this.dataModel.splice(index, 1, device); | 146 this.dataModel.splice(index, 1, device); |
146 this.redrawItem(index); | 147 this.redrawItem(index); |
147 } | 148 } |
148 this.updateListVisibility_(); | 149 this.updateListVisibility_(); |
| 150 if (selectedDevice) |
| 151 this.setSelectedDevice_(selectedDevice); |
149 return true; | 152 return true; |
150 }, | 153 }, |
151 | 154 |
152 /** | 155 /** |
153 * Forces a revailidation of the list content. Content added while the list | 156 * Forces a revailidation of the list content. Content added while the list |
154 * is hidden is not properly rendered when the list becomes visible. In | 157 * is hidden is not properly rendered when the list becomes visible. In |
155 * addition, deleting a single item from the list results in a stale cache | 158 * addition, deleting a single item from the list results in a stale cache |
156 * requiring an invalidation. | 159 * requiring an invalidation. |
| 160 * @param {String=} opt_selection Optional address of device to select |
| 161 * after refreshing the list. |
157 */ | 162 */ |
158 refresh: function() { | 163 refresh: function(opt_selection) { |
159 // TODO(kevers): Investigate if the root source of the problems can be | 164 // TODO(kevers): Investigate if the root source of the problems can be |
160 // fixed in cr.ui.list. | 165 // fixed in cr.ui.list. |
| 166 var selectedDevice = opt_selection ? opt_selection : |
| 167 this.getSelectedDevice_(); |
161 this.invalidate(); | 168 this.invalidate(); |
162 this.redraw(); | 169 this.redraw(); |
| 170 if (selectedDevice) |
| 171 this.setSelectedDevice_(selectedDevice); |
163 }, | 172 }, |
164 | 173 |
165 /** | 174 /** |
| 175 * Retrieves the address of the selected device, or null if no device is |
| 176 * selected. |
| 177 * @return {?String} Address of selected device or null. |
| 178 * @private |
| 179 */ |
| 180 getSelectedDevice_: function() { |
| 181 var selection = this.selectedItem; |
| 182 if (selection) |
| 183 return selection.address; |
| 184 return null; |
| 185 }, |
| 186 |
| 187 /** |
| 188 * Selects the device with the matching address. |
| 189 * @param {String} address The unique address of the device. |
| 190 * @private |
| 191 */ |
| 192 setSelectedDevice_: function(address) { |
| 193 var index = this.find(address); |
| 194 if (index != undefined) |
| 195 this.selectionModel.selectRange(index, index); |
| 196 }, |
| 197 |
| 198 /** |
166 * Perges all devices from the list. | 199 * Perges all devices from the list. |
167 */ | 200 */ |
168 clear: function() { | 201 clear: function() { |
169 this.dataModel = new ArrayDataModel([]); | 202 this.dataModel = new ArrayDataModel([]); |
170 this.redraw(); | 203 this.redraw(); |
171 this.updateListVisibility_(); | 204 this.updateListVisibility_(); |
172 }, | 205 }, |
173 | 206 |
174 /** | 207 /** |
175 * Returns the index of the list entry with the matching address. | 208 * Returns the index of the list entry with the matching address. |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 // Inform the bluetooth adapter that we are disconnecting or | 293 // Inform the bluetooth adapter that we are disconnecting or |
261 // forgetting the device. | 294 // forgetting the device. |
262 chrome.send('updateBluetoothDevice', | 295 chrome.send('updateBluetoothDevice', |
263 [item.data.address, item.connected ? 'disconnect' : 'forget']); | 296 [item.data.address, item.connected ? 'disconnect' : 'forget']); |
264 } | 297 } |
265 } | 298 } |
266 }, | 299 }, |
267 | 300 |
268 /** @inheritDoc */ | 301 /** @inheritDoc */ |
269 deleteItemAtIndex: function(index) { | 302 deleteItemAtIndex: function(index) { |
| 303 var selectedDevice = this.getSelectedDevice_(); |
270 this.dataModel.splice(index, 1); | 304 this.dataModel.splice(index, 1); |
271 this.refresh(); | 305 this.refresh(selectedDevice); |
272 this.updateListVisibility_(); | 306 this.updateListVisibility_(); |
273 }, | 307 }, |
274 | 308 |
275 /** | 309 /** |
276 * If the list has an associated empty list placholder then update the | 310 * If the list has an associated empty list placholder then update the |
277 * visibility of the list and placeholder. | 311 * visibility of the list and placeholder. |
278 * @private | 312 * @private |
279 */ | 313 */ |
280 updateListVisibility_: function() { | 314 updateListVisibility_: function() { |
281 var empty = this.dataModel.length == 0; | 315 var empty = this.dataModel.length == 0; |
(...skipping 13 matching lines...) Expand all Loading... |
295 cr.defineProperty(BluetoothListItem, 'paired', cr.PropertyKind.BOOL_ATTR); | 329 cr.defineProperty(BluetoothListItem, 'paired', cr.PropertyKind.BOOL_ATTR); |
296 | 330 |
297 cr.defineProperty(BluetoothListItem, 'connecting', cr.PropertyKind.BOOL_ATTR); | 331 cr.defineProperty(BluetoothListItem, 'connecting', cr.PropertyKind.BOOL_ATTR); |
298 | 332 |
299 return { | 333 return { |
300 BluetoothListItem: BluetoothListItem, | 334 BluetoothListItem: BluetoothListItem, |
301 BluetoothDeviceList: BluetoothDeviceList, | 335 BluetoothDeviceList: BluetoothDeviceList, |
302 Constants: Constants | 336 Constants: Constants |
303 }; | 337 }; |
304 }); | 338 }); |
OLD | NEW |