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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/resources/StorageItemsView.js

Issue 2662403002: [DevTools] Merge filter bar with the main toolbar (Closed)
Patch Set: [DevTools] Merge filter bar with the main toolbar Created 3 years, 10 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 unified diff | Download patch
OLDNEW
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
31 ];
32 24
33 this.element.addEventListener('contextmenu', this._showContextMenu.bind(this ), true); 25 var toolbarItems = [this._refreshButton, this._deleteAllButton, this._delete SelectedButton, this._filterItem];
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
63 /** 53 /**
64 * @param {!Common.Event} event 54 * @param {!Common.Event} event
65 */ 55 */
66 _filterChanged(event) { 56 _filterChanged(event) {
67 var text = this._textFilterUI.value(); 57 var text = /** @type {?string} */ (event.data);
68 this._filterRegex = text ? new RegExp(text.escapeForRegExp(), 'i') : null; 58 this._filterRegex = text ? new RegExp(text.escapeForRegExp(), 'i') : null;
69 this.refreshItems(); 59 this.refreshItems();
70 } 60 }
71 61
72 /** 62 /**
73 * @param {!Array<?Object>} items 63 * @param {!Array<?Object>} items
74 * @param {function(?Object): string} keyFunction 64 * @param {function(?Object): string} keyFunction
75 * @return {!Array<?Object>} 65 * @return {!Array<?Object>}
76 * @protected 66 * @protected
77 */ 67 */
78 filter(items, keyFunction) { 68 filter(items, keyFunction) {
79 if (!this._filterRegex) 69 if (!this._filterRegex)
80 return items; 70 return items;
81 return items.filter(item => this._filterRegex.test(keyFunction(item))); 71 return items.filter(item => this._filterRegex.test(keyFunction(item)));
82 } 72 }
83 73
84 /** 74 /**
85 * @override 75 * @override
86 */ 76 */
87 wasShown() { 77 wasShown() {
88 this.refreshItems(); 78 this.refreshItems();
89 } 79 }
90 80
91 /** 81 /**
92 * @override
93 */
94 willHide() {
95 this.setCanDeleteSelected(false);
96 }
97
98 /**
99 * @param {boolean} enabled 82 * @param {boolean} enabled
100 * @protected 83 * @protected
101 */ 84 */
102 setCanDeleteAll(enabled) { 85 setCanDeleteAll(enabled) {
103 this._deleteAllButton.setEnabled(enabled); 86 this._deleteAllButton.setEnabled(enabled);
104 } 87 }
105 88
106 /** 89 /**
107 * @param {boolean} enabled 90 * @param {boolean} enabled
108 * @protected 91 * @protected
109 */ 92 */
110 setCanDeleteSelected(enabled) { 93 setCanDeleteSelected(enabled) {
111 this._deleteSelectedButton.setEnabled(enabled); 94 this._deleteSelectedButton.setEnabled(enabled);
112 } 95 }
113 96
114 /** 97 /**
115 * @param {boolean} enabled 98 * @param {boolean} enabled
116 * @protected 99 * @protected
117 */ 100 */
118 setCanRefresh(enabled) { 101 setCanRefresh(enabled) {
119 this._refreshButton.setEnabled(enabled); 102 this._refreshButton.setEnabled(enabled);
120 } 103 }
121 104
122 /** 105 /**
123 * @param {boolean} enabled 106 * @param {boolean} enabled
124 * @protected 107 * @protected
125 */ 108 */
126 setCanFilter(enabled) { 109 setCanFilter(enabled) {
127 this._filterButton.setEnabled(enabled); 110 this._filterItem.setEnabled(enabled);
128 } 111 }
129 112
130 deleteAllItems() { 113 deleteAllItems() {
131 } 114 }
132 115
133 deleteSelectedItem() { 116 deleteSelectedItem() {
134 } 117 }
135 118
136 refreshItems() { 119 refreshItems() {
137 } 120 }
138 }; 121 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698