| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 Resources.StorageItemsView = class extends UI.VBox { |
| 6 /** |
| 7 * @param {string} title |
| 8 * @param {string} filterName |
| 9 */ |
| 10 constructor(title, filterName) { |
| 11 super(false); |
| 12 /** @type {?RegExp} */ |
| 13 this._filterRegex = null; |
| 14 |
| 15 this._filterBar = new UI.FilterBar(filterName, true); |
| 16 this._textFilterUI = new UI.TextFilterUI(false); |
| 17 this._textFilterUI.addEventListener(UI.FilterUI.Events.FilterChanged, this._
filterChanged, this); |
| 18 this._filterBar.addFilter(this._textFilterUI); |
| 19 |
| 20 this._deleteAllButton = this._addButton(Common.UIString('Clear All'), 'large
icon-clear', this.deleteAllItems); |
| 21 this._deleteSelectedButton = |
| 22 this._addButton(Common.UIString('Delete Selected'), 'largeicon-delete',
this.deleteSelectedItem); |
| 23 this._refreshButton = this._addButton(Common.UIString('Refresh'), 'largeicon
-refresh', this.refreshItems); |
| 24 this._filterButton = this._filterBar.filterButton(); |
| 25 |
| 26 this._mainToolbar = new UI.Toolbar('top-resources-toolbar', this.element); |
| 27 |
| 28 var toolbarItems = [ |
| 29 this._refreshButton, this._deleteAllButton, this._deleteSelectedButton, ne
w UI.ToolbarSeparator(), |
| 30 this._filterButton |
| 31 ]; |
| 32 |
| 33 this.element.addEventListener('contextmenu', this._showContextMenu.bind(this
), true); |
| 34 |
| 35 for (var item of toolbarItems) |
| 36 this._mainToolbar.appendToolbarItem(item); |
| 37 |
| 38 this._filterBar.show(this.element); |
| 39 } |
| 40 |
| 41 /** |
| 42 * @param {string} label |
| 43 * @param {string} glyph |
| 44 * @param {!Function} callback |
| 45 * @return {!UI.ToolbarButton} |
| 46 */ |
| 47 _addButton(label, glyph, callback) { |
| 48 var button = new UI.ToolbarButton(label, glyph); |
| 49 button.addEventListener(UI.ToolbarButton.Events.Click, callback, this); |
| 50 return button; |
| 51 } |
| 52 |
| 53 /** |
| 54 * @param {!Event} event |
| 55 */ |
| 56 _showContextMenu(event) { |
| 57 var contextMenu = new UI.ContextMenu(event); |
| 58 contextMenu.appendItem(Common.UIString('Refresh'), this.refreshItems.bind(th
is)); |
| 59 contextMenu.show(); |
| 60 } |
| 61 |
| 62 |
| 63 /** |
| 64 * @param {!Common.Event} event |
| 65 */ |
| 66 _filterChanged(event) { |
| 67 var text = this._textFilterUI.value(); |
| 68 this._filterRegex = text ? new RegExp(text.escapeForRegExp(), 'i') : null; |
| 69 this.refreshItems(); |
| 70 } |
| 71 |
| 72 /** |
| 73 * @param {!Array<?Object>} items |
| 74 * @param {function(?Object): string} keyFunction |
| 75 * @return {!Array<?Object>} |
| 76 * @protected |
| 77 */ |
| 78 filter(items, keyFunction) { |
| 79 if (!this._filterRegex) |
| 80 return items; |
| 81 return items.filter(item => this._filterRegex.test(keyFunction(item))); |
| 82 } |
| 83 |
| 84 /** |
| 85 * @override |
| 86 */ |
| 87 wasShown() { |
| 88 this.refreshItems(); |
| 89 } |
| 90 |
| 91 /** |
| 92 * @override |
| 93 */ |
| 94 willHide() { |
| 95 this.setCanDeleteSelected(false); |
| 96 } |
| 97 |
| 98 /** |
| 99 * @param {boolean} enabled |
| 100 * @protected |
| 101 */ |
| 102 setCanDeleteAll(enabled) { |
| 103 this._deleteAllButton.setEnabled(enabled); |
| 104 } |
| 105 |
| 106 /** |
| 107 * @param {boolean} enabled |
| 108 * @protected |
| 109 */ |
| 110 setCanDeleteSelected(enabled) { |
| 111 this._deleteSelectedButton.setEnabled(enabled); |
| 112 } |
| 113 |
| 114 /** |
| 115 * @param {boolean} enabled |
| 116 * @protected |
| 117 */ |
| 118 setCanRefresh(enabled) { |
| 119 this._refreshButton.setEnabled(enabled); |
| 120 } |
| 121 |
| 122 /** |
| 123 * @param {boolean} enabled |
| 124 * @protected |
| 125 */ |
| 126 setCanFilter(enabled) { |
| 127 this._filterButton.setEnabled(enabled); |
| 128 } |
| 129 |
| 130 deleteAllItems() { |
| 131 } |
| 132 |
| 133 deleteSelectedItem() { |
| 134 } |
| 135 |
| 136 refreshItems() { |
| 137 } |
| 138 }; |
| OLD | NEW |