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