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

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.addEventListener(UI.ToolbarInput.Event.KeyDown, event => th is._onFilterKeyDown(event));
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
53 /**
54 * @param {!Common.Event} event
55 */
56 _onFilterKeyDown(event) {
pfeldman 2017/02/06 19:37:42 Drop this, can be added later.
eostroukhov 2017/02/07 00:24:18 Why? I added it because as a user, I tried this an
57 if (event.data.code !== 'ArrowDown')
58 return;
59 event.data.consume(true);
60 this.focusGrid();
61 }
62 62
63 /** 63 /**
64 * @param {!Common.Event} event 64 * @param {!Common.Event} event
65 */ 65 */
66 _filterChanged(event) { 66 _filterChanged(event) {
67 var text = this._textFilterUI.value(); 67 var text = event.data;
pfeldman 2017/02/06 19:37:42 Cast to string.
eostroukhov 2017/02/07 00:24:18 Done.
68 this._filterRegex = text ? new RegExp(text.escapeForRegExp(), 'i') : null; 68 this._filterRegex = text ? new RegExp(text.escapeForRegExp(), 'i') : null;
69 this.refreshItems(); 69 this.refreshItems();
70 } 70 }
71 71
72 /** 72 /**
73 * @param {!Array<?Object>} items 73 * @param {!Array<?Object>} items
74 * @param {function(?Object): string} keyFunction 74 * @param {function(?Object): string} keyFunction
75 * @return {!Array<?Object>} 75 * @return {!Array<?Object>}
76 * @protected 76 * @protected
77 */ 77 */
78 filter(items, keyFunction) { 78 filter(items, keyFunction) {
79 if (!this._filterRegex) 79 if (!this._filterRegex)
80 return items; 80 return items;
81 return items.filter(item => this._filterRegex.test(keyFunction(item))); 81 return items.filter(item => this._filterRegex.test(keyFunction(item)));
82 } 82 }
83 83
84 /** 84 /**
85 * @override 85 * @override
86 */ 86 */
87 wasShown() { 87 wasShown() {
88 this.refreshItems(); 88 this.refreshItems();
89 } 89 }
90 90
91 /** 91 /**
92 * @override
93 */
94 willHide() {
95 this.setCanDeleteSelected(false);
96 }
97
98 /**
99 * @param {boolean} enabled 92 * @param {boolean} enabled
100 * @protected 93 * @protected
101 */ 94 */
102 setCanDeleteAll(enabled) { 95 setCanDeleteAll(enabled) {
103 this._deleteAllButton.setEnabled(enabled); 96 this._deleteAllButton.setEnabled(enabled);
104 } 97 }
105 98
106 /** 99 /**
107 * @param {boolean} enabled 100 * @param {boolean} enabled
108 * @protected 101 * @protected
109 */ 102 */
110 setCanDeleteSelected(enabled) { 103 setCanDeleteSelected(enabled) {
111 this._deleteSelectedButton.setEnabled(enabled); 104 this._deleteSelectedButton.setEnabled(enabled);
112 } 105 }
113 106
114 /** 107 /**
115 * @param {boolean} enabled 108 * @param {boolean} enabled
116 * @protected 109 * @protected
117 */ 110 */
118 setCanRefresh(enabled) { 111 setCanRefresh(enabled) {
119 this._refreshButton.setEnabled(enabled); 112 this._refreshButton.setEnabled(enabled);
120 } 113 }
121 114
122 /** 115 /**
123 * @param {boolean} enabled 116 * @param {boolean} enabled
124 * @protected 117 * @protected
125 */ 118 */
126 setCanFilter(enabled) { 119 setCanFilter(enabled) {
127 this._filterButton.setEnabled(enabled); 120 this._filterItem.setEnabled(enabled);
128 } 121 }
129 122
130 deleteAllItems() { 123 deleteAllItems() {
131 } 124 }
132 125
133 deleteSelectedItem() { 126 deleteSelectedItem() {
134 } 127 }
135 128
136 refreshItems() { 129 refreshItems() {
137 } 130 }
131
132 focusGrid() {
133 }
138 }; 134 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698