Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/ui/ListControl.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/ui/ListControl.js b/third_party/WebKit/Source/devtools/front_end/ui/ListControl.js |
| index b55c2034cdfbfaaa3619d0e399d2c49445532b4f..f3f0c42af3f390d7944132fe2cbd8a3881a1b729 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/ui/ListControl.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/ui/ListControl.js |
| @@ -123,6 +123,23 @@ UI.ListControl = class { |
| this.replaceItemsInRange(index, index, [item]); |
| } |
| + /** |
| + * @param {T} item |
| + * @param {function(T, T):number} comparator |
| + */ |
| + insertItemWithComparator(item, comparator) { |
| + var index = this._items.lowerBound(item, comparator); |
| + this.insertItemAtIndex(index, item); |
| + } |
| + |
| + /** |
| + * @param {T} item |
| + * @return {number} |
| + */ |
| + indexOfItem(item) { |
| + return this._items.indexOf(item); |
| + } |
| + |
| /** |
| * @param {number} index |
| * @return {T} |
| @@ -181,6 +198,22 @@ UI.ListControl = class { |
| this.replaceItemsInRange(0, this._items.length, items); |
| } |
| + refreshAllItems() { |
| + this.refreshItemsInRange(0, this._items.length); |
| + } |
| + |
| + /** |
| + * @param {number} from |
| + * @param {number} to |
| + */ |
| + refreshItemsInRange(from, to) { |
| + for (var i = from; i < to; i++) |
| + this._itemToElement.delete(this._items[i]); |
| + this.invalidateRange(from, to); |
| + if (this._selectedIndex !== -1) |
| + this._select(this._selectedIndex, null, null); |
| + } |
| + |
| /** |
| * @param {number} from |
| * @param {number} to |
| @@ -241,22 +274,34 @@ UI.ListControl = class { |
| return this._selectedIndex === -1 ? null : this._items[this._selectedIndex]; |
| } |
| + /** |
| + * @return {number} |
| + */ |
| + selectedIndex() { |
| + return this._selectedIndex; |
| + } |
| + |
| /** |
| * @param {?T} item |
| * @param {boolean=} center |
| + * @param {boolean=} dontScroll |
| */ |
| - selectItem(item, center) { |
| + selectItem(item, center, dontScroll) { |
| var index = -1; |
| if (item !== null) { |
| index = this._items.indexOf(item); |
| - if (index === -1) |
| - throw 'Attempt to select missing item'; |
| - if (!this._delegate.isItemSelectable(item)) |
| - throw 'Attempt to select non-selectable item'; |
| + if (index === -1) { |
| + console.error('Attempt to select missing item'); |
|
dgozman
2017/05/11 21:14:52
Let's change all of them to console.errors then.
einbinder
2017/05/11 21:47:22
I kept the throw on methods that need to return va
|
| + return; |
| + } |
| + if (!this._delegate.isItemSelectable(item)) { |
| + console.error('Attempt to select non-selectable item'); |
| + return; |
| + } |
| } |
| if (this._selectedIndex !== index) |
| this._select(index); |
| - if (index !== -1) |
| + if (index !== -1 && !dontScroll) |
| this._scrollIntoView(index, center); |
| } |