Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Unified Diff: chrome/browser/resources/options2/chromeos/bluetooth_device_list.js

Issue 10834132: Auto-reselect device on a refresh of the Bluetooth device list. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/options2/chromeos/bluetooth_device_list.js
diff --git a/chrome/browser/resources/options2/chromeos/bluetooth_device_list.js b/chrome/browser/resources/options2/chromeos/bluetooth_device_list.js
index 770c86babd9cff8377e6ab2b8646ed9667951d93..eb715d742a1f1e14a3c3e87a4b5c6fbc5ce4e62c 100644
--- a/chrome/browser/resources/options2/chromeos/bluetooth_device_list.js
+++ b/chrome/browser/resources/options2/chromeos/bluetooth_device_list.js
@@ -137,6 +137,7 @@ cr.define('options.system.bluetooth', function() {
* @return {boolean} True if the devies was successfully added or updated.
*/
appendDevice: function(device) {
+ var selectedDevice = this.getSelectedDevice_();
var index = this.find(device.address);
if (index == undefined) {
this.dataModel.push(device);
@@ -146,6 +147,8 @@ cr.define('options.system.bluetooth', function() {
this.redrawItem(index);
}
this.updateListVisibility_();
+ if (selectedDevice)
+ this.setSelectedDevice_(selectedDevice);
return true;
},
@@ -154,12 +157,42 @@ cr.define('options.system.bluetooth', function() {
* 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
* 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
// fixed in cr.ui.list.
+ var selectedDevice = opt_selection ? opt_selection :
+ this.getSelectedDevice_();
this.invalidate();
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() {
/** @inheritDoc */
deleteItemAtIndex: function(index) {
+ var selectedDevice = this.getSelectedDevice_();
this.dataModel.splice(index, 1);
- this.refresh();
+ this.refresh(selectedDevice);
this.updateListVisibility_();
},
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698