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

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 24 this._filterItem.input.addEventListener('keydown', event => this._onFilterKe yDown(event));
31 ];
32 25
33 this.element.addEventListener('contextmenu', this._showContextMenu.bind(this ), true); 26 var toolbarItems = [this._refreshButton, this._deleteAllButton, this._delete SelectedButton, this._filterItem];
34
35 for (var item of toolbarItems) 27 for (var item of toolbarItems)
36 this._mainToolbar.appendToolbarItem(item); 28 this._mainToolbar.appendToolbarItem(item);
37 29
38 this._filterBar.show(this.element); 30 this.element.addEventListener('contextmenu', this._showContextMenu.bind(this ), true);
39 } 31 }
40 32
41 /** 33 /**
42 * @param {string} label 34 * @param {string} label
43 * @param {string} glyph 35 * @param {string} glyph
44 * @param {!Function} callback 36 * @param {!Function} callback
45 * @return {!UI.ToolbarButton} 37 * @return {!UI.ToolbarButton}
46 */ 38 */
47 _addButton(label, glyph, callback) { 39 _addButton(label, glyph, callback) {
48 var button = new UI.ToolbarButton(label, glyph); 40 var button = new UI.ToolbarButton(label, glyph);
49 button.addEventListener(UI.ToolbarButton.Events.Click, callback, this); 41 button.addEventListener(UI.ToolbarButton.Events.Click, callback, this);
50 return button; 42 return button;
51 } 43 }
52 44
53 /** 45 /**
54 * @param {!Event} event 46 * @param {!Event} event
55 */ 47 */
56 _showContextMenu(event) { 48 _showContextMenu(event) {
57 var contextMenu = new UI.ContextMenu(event); 49 var contextMenu = new UI.ContextMenu(event);
58 contextMenu.appendItem(Common.UIString('Refresh'), this.refreshItems.bind(th is)); 50 contextMenu.appendItem(Common.UIString('Refresh'), this.refreshItems.bind(th is));
59 contextMenu.show(); 51 contextMenu.show();
60 } 52 }
61 53
54 /**
55 * @param {!Event} event
56 */
57 _onFilterKeyDown(event) {
58 if (event.key !== 'ArrowDown')
59 return;
60 event.consume(true);
61 this.focusGrid();
62 }
62 63
63 /** 64 /**
64 * @param {!Common.Event} event 65 * @param {!Common.Event} event
65 */ 66 */
66 _filterChanged(event) { 67 _filterChanged(event) {
67 var text = this._textFilterUI.value(); 68 var text = /** @type {?string} */ (event.data);
68 this._filterRegex = text ? new RegExp(text.escapeForRegExp(), 'i') : null; 69 this._filterRegex = text ? new RegExp(text.escapeForRegExp(), 'i') : null;
69 this.refreshItems(); 70 this.refreshItems();
70 } 71 }
71 72
72 /** 73 /**
73 * @param {!Array<?Object>} items 74 * @param {!Array<?Object>} items
74 * @param {function(?Object): string} keyFunction 75 * @param {function(?Object): string} keyFunction
75 * @return {!Array<?Object>} 76 * @return {!Array<?Object>}
76 * @protected 77 * @protected
77 */ 78 */
78 filter(items, keyFunction) { 79 filter(items, keyFunction) {
79 if (!this._filterRegex) 80 if (!this._filterRegex)
80 return items; 81 return items;
81 return items.filter(item => this._filterRegex.test(keyFunction(item))); 82 return items.filter(item => this._filterRegex.test(keyFunction(item)));
82 } 83 }
83 84
84 /** 85 /**
85 * @override 86 * @override
86 */ 87 */
87 wasShown() { 88 wasShown() {
88 this.refreshItems(); 89 this.refreshItems();
89 } 90 }
90 91
91 /** 92 /**
92 * @override
93 */
94 willHide() {
95 this.setCanDeleteSelected(false);
96 }
97
98 /**
99 * @param {boolean} enabled 93 * @param {boolean} enabled
100 * @protected 94 * @protected
101 */ 95 */
102 setCanDeleteAll(enabled) { 96 setCanDeleteAll(enabled) {
103 this._deleteAllButton.setEnabled(enabled); 97 this._deleteAllButton.setEnabled(enabled);
104 } 98 }
105 99
106 /** 100 /**
107 * @param {boolean} enabled 101 * @param {boolean} enabled
108 * @protected 102 * @protected
109 */ 103 */
110 setCanDeleteSelected(enabled) { 104 setCanDeleteSelected(enabled) {
111 this._deleteSelectedButton.setEnabled(enabled); 105 this._deleteSelectedButton.setEnabled(enabled);
112 } 106 }
113 107
114 /** 108 /**
115 * @param {boolean} enabled 109 * @param {boolean} enabled
116 * @protected 110 * @protected
117 */ 111 */
118 setCanRefresh(enabled) { 112 setCanRefresh(enabled) {
119 this._refreshButton.setEnabled(enabled); 113 this._refreshButton.setEnabled(enabled);
120 } 114 }
121 115
122 /** 116 /**
123 * @param {boolean} enabled 117 * @param {boolean} enabled
124 * @protected 118 * @protected
125 */ 119 */
126 setCanFilter(enabled) { 120 setCanFilter(enabled) {
127 this._filterButton.setEnabled(enabled); 121 this._filterItem.setEnabled(enabled);
128 } 122 }
129 123
130 deleteAllItems() { 124 deleteAllItems() {
131 } 125 }
132 126
133 deleteSelectedItem() { 127 deleteSelectedItem() {
134 } 128 }
135 129
136 refreshItems() { 130 refreshItems() {
137 } 131 }
132
133 focusGrid() {
pfeldman 2017/02/07 23:15:35 Wait, we don't want to do this!
eostroukhov 2017/02/07 23:55:45 I removed the handler for the down arrow.
134 }
138 }; 135 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698