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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/quick_open/CommandMenu.js

Issue 2736853002: DevTools: Convert FilteredListWidget to use an optional provider (Closed)
Patch Set: missing timeout Created 3 years, 9 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 * @unrestricted 5 * @unrestricted
6 */ 6 */
7 QuickOpen.CommandMenu = class { 7 QuickOpen.CommandMenu = class {
8 constructor() { 8 constructor() {
9 this._commands = []; 9 this._commands = [];
10 this._loadCommands(); 10 this._loadCommands();
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 } 102 }
103 103
104 /** 104 /**
105 * @return {!Array.<!QuickOpen.CommandMenu.Command>} 105 * @return {!Array.<!QuickOpen.CommandMenu.Command>}
106 */ 106 */
107 commands() { 107 commands() {
108 return this._commands; 108 return this._commands;
109 } 109 }
110 }; 110 };
111 111
112 /** 112 QuickOpen.CommandMenuProvider = class extends QuickOpen.FilteredListWidget.Provi der {
113 * @unrestricted
114 */
115 QuickOpen.CommandMenuDelegate = class extends QuickOpen.FilteredListWidget.Deleg ate {
116 constructor() { 113 constructor() {
117 super(); 114 super();
118 this._commands = []; 115 this._commands = [];
119 this._appendAvailableCommands(); 116 this._appendAvailableCommands();
120 } 117 }
121 118
122 _appendAvailableCommands() { 119 _appendAvailableCommands() {
123 var allCommands = QuickOpen.commandMenu.commands(); 120 var allCommands = QuickOpen.commandMenu.commands();
124 121
125 // Populate whitelisted actions. 122 // Populate whitelisted actions.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 * @override 190 * @override
194 * @param {number} itemIndex 191 * @param {number} itemIndex
195 * @param {string} query 192 * @param {string} query
196 * @param {!Element} titleElement 193 * @param {!Element} titleElement
197 * @param {!Element} subtitleElement 194 * @param {!Element} subtitleElement
198 */ 195 */
199 renderItem(itemIndex, query, titleElement, subtitleElement) { 196 renderItem(itemIndex, query, titleElement, subtitleElement) {
200 var command = this._commands[itemIndex]; 197 var command = this._commands[itemIndex];
201 titleElement.removeChildren(); 198 titleElement.removeChildren();
202 var tagElement = titleElement.createChild('span', 'tag'); 199 var tagElement = titleElement.createChild('span', 'tag');
203 var index = String.hashCode(command.category()) % QuickOpen.CommandMenuDeleg ate.MaterialPaletteColors.length; 200 var index = String.hashCode(command.category()) % QuickOpen.CommandMenuProvi der.MaterialPaletteColors.length;
204 tagElement.style.backgroundColor = QuickOpen.CommandMenuDelegate.MaterialPal etteColors[index]; 201 tagElement.style.backgroundColor = QuickOpen.CommandMenuProvider.MaterialPal etteColors[index];
205 tagElement.textContent = command.category(); 202 tagElement.textContent = command.category();
206 titleElement.createTextChild(command.title()); 203 titleElement.createTextChild(command.title());
207 QuickOpen.FilteredListWidget.highlightRanges(titleElement, query, true); 204 QuickOpen.FilteredListWidget.highlightRanges(titleElement, query, true);
208 subtitleElement.textContent = command.shortcut(); 205 subtitleElement.textContent = command.shortcut();
209 } 206 }
210 207
211 /** 208 /**
212 * @override 209 * @override
213 * @param {?number} itemIndex 210 * @param {?number} itemIndex
214 * @param {string} promptValue 211 * @param {string} promptValue
215 */ 212 */
216 selectItem(itemIndex, promptValue) { 213 selectItem(itemIndex, promptValue) {
217 if (itemIndex === null) 214 if (itemIndex === null)
218 return; 215 return;
219 this._commands[itemIndex].execute(); 216 this._commands[itemIndex].execute();
220 Host.userMetrics.actionTaken(Host.UserMetrics.Action.SelectCommandFromComman dMenu); 217 Host.userMetrics.actionTaken(Host.UserMetrics.Action.SelectCommandFromComman dMenu);
221 } 218 }
222 219
223 /** 220 /**
224 * @override 221 * @override
225 * @return {string} 222 * @return {string}
226 */ 223 */
227 notFoundText() { 224 notFoundText() {
228 return Common.UIString('No commands found'); 225 return Common.UIString('No commands found');
229 } 226 }
230 }; 227 };
231 228
232 QuickOpen.CommandMenuDelegate.MaterialPaletteColors = [ 229 QuickOpen.CommandMenuProvider.MaterialPaletteColors = [
233 '#F44336', '#E91E63', '#9C27B0', '#673AB7', '#3F51B5', '#03A9F4', '#00BCD4', ' #009688', '#4CAF50', '#8BC34A', 230 '#F44336', '#E91E63', '#9C27B0', '#673AB7', '#3F51B5', '#03A9F4', '#00BCD4', ' #009688', '#4CAF50', '#8BC34A',
234 '#CDDC39', '#FFC107', '#FF9800', '#FF5722', '#795548', '#9E9E9E', '#607D8B' 231 '#CDDC39', '#FFC107', '#FF9800', '#FF5722', '#795548', '#9E9E9E', '#607D8B'
235 ]; 232 ];
236 233
237 /** 234 /**
238 * @unrestricted 235 * @unrestricted
239 */ 236 */
240 QuickOpen.CommandMenu.Command = class { 237 QuickOpen.CommandMenu.Command = class {
241 /** 238 /**
242 * @param {string} category 239 * @param {string} category
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 * @unrestricted 301 * @unrestricted
305 */ 302 */
306 QuickOpen.CommandMenu.ShowActionDelegate = class { 303 QuickOpen.CommandMenu.ShowActionDelegate = class {
307 /** 304 /**
308 * @override 305 * @override
309 * @param {!UI.Context} context 306 * @param {!UI.Context} context
310 * @param {string} actionId 307 * @param {string} actionId
311 * @return {boolean} 308 * @return {boolean}
312 */ 309 */
313 handleAction(context, actionId) { 310 handleAction(context, actionId) {
314 new QuickOpen.FilteredListWidget(new QuickOpen.CommandMenuDelegate()).showAs Dialog(); 311 new QuickOpen.FilteredListWidget(new QuickOpen.CommandMenuProvider()).showAs Dialog();
315 InspectorFrontendHost.bringToFront(); 312 InspectorFrontendHost.bringToFront();
316 return true; 313 return true;
317 } 314 }
318 }; 315 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698