Commit 335d4ea5 authored by kevers@chromium.org's avatar kevers@chromium.org

Auto-reselect device on a refresh of the Bluetooth device list.

BUG=chromium-os:32124


Review URL: https://chromiumcodereview.appspot.com/10834132

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149714 0039d316-1c4b-4281-b951-d872f2087c98
parent ea628e38
...@@ -137,6 +137,7 @@ cr.define('options.system.bluetooth', function() { ...@@ -137,6 +137,7 @@ cr.define('options.system.bluetooth', function() {
* @return {boolean} True if the devies was successfully added or updated. * @return {boolean} True if the devies was successfully added or updated.
*/ */
appendDevice: function(device) { appendDevice: function(device) {
var selectedDevice = this.getSelectedDevice_();
var index = this.find(device.address); var index = this.find(device.address);
if (index == undefined) { if (index == undefined) {
this.dataModel.push(device); this.dataModel.push(device);
...@@ -146,6 +147,8 @@ cr.define('options.system.bluetooth', function() { ...@@ -146,6 +147,8 @@ cr.define('options.system.bluetooth', function() {
this.redrawItem(index); this.redrawItem(index);
} }
this.updateListVisibility_(); this.updateListVisibility_();
if (selectedDevice)
this.setSelectedDevice_(selectedDevice);
return true; return true;
}, },
...@@ -154,12 +157,42 @@ cr.define('options.system.bluetooth', function() { ...@@ -154,12 +157,42 @@ cr.define('options.system.bluetooth', function() {
* is hidden is not properly rendered when the list becomes visible. In * is hidden is not properly rendered when the list becomes visible. In
* addition, deleting a single item from the list results in a stale cache * addition, deleting a single item from the list results in a stale cache
* requiring an invalidation. * requiring an invalidation.
* @param {String=} opt_selection Optional address of device to select
* after refreshing the list.
*/ */
refresh: function() { refresh: function(opt_selection) {
// TODO(kevers): Investigate if the root source of the problems can be // TODO(kevers): Investigate if the root source of the problems can be
// fixed in cr.ui.list. // fixed in cr.ui.list.
var selectedDevice = opt_selection ? opt_selection :
this.getSelectedDevice_();
this.invalidate(); this.invalidate();
this.redraw(); this.redraw();
if (selectedDevice)
this.setSelectedDevice_(selectedDevice);
},
/**
* Retrieves the address of the selected device, or null if no device is
* selected.
* @return {?String} Address of selected device or null.
* @private
*/
getSelectedDevice_: function() {
var selection = this.selectedItem;
if (selection)
return selection.address;
return null;
},
/**
* Selects the device with the matching address.
* @param {String} address The unique address of the device.
* @private
*/
setSelectedDevice_: function(address) {
var index = this.find(address);
if (index != undefined)
this.selectionModel.selectRange(index, index);
}, },
/** /**
...@@ -267,8 +300,9 @@ cr.define('options.system.bluetooth', function() { ...@@ -267,8 +300,9 @@ cr.define('options.system.bluetooth', function() {
/** @inheritDoc */ /** @inheritDoc */
deleteItemAtIndex: function(index) { deleteItemAtIndex: function(index) {
var selectedDevice = this.getSelectedDevice_();
this.dataModel.splice(index, 1); this.dataModel.splice(index, 1);
this.refresh(); this.refresh(selectedDevice);
this.updateListVisibility_(); this.updateListVisibility_();
}, },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment