| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 Snippets.SnippetsQuickOpen = class extends QuickOpen.FilteredListWidget.Provider
{ |
| 6 constructor() { |
| 7 super(); |
| 8 /** @type {!Array<!Workspace.UISourceCode>} */ |
| 9 this._snippets = []; |
| 10 } |
| 11 /** |
| 12 * @override |
| 13 * @param {?number} itemIndex |
| 14 * @param {string} promptValue |
| 15 */ |
| 16 selectItem(itemIndex, promptValue) { |
| 17 if (itemIndex === null) |
| 18 return; |
| 19 var currentExecutionContext = UI.context.flavor(SDK.ExecutionContext); |
| 20 if (currentExecutionContext) |
| 21 Snippets.scriptSnippetModel.evaluateScriptSnippet(currentExecutionContext,
this._snippets[itemIndex]); |
| 22 } |
| 23 |
| 24 /** |
| 25 * @override |
| 26 * @param {string} query |
| 27 * @return {string} |
| 28 */ |
| 29 notFoundText(query) { |
| 30 return Common.UIString('No snippets found.'); |
| 31 } |
| 32 |
| 33 /** |
| 34 * @override |
| 35 */ |
| 36 attach() { |
| 37 this._snippets = Snippets.scriptSnippetModel.project().uiSourceCodes(); |
| 38 } |
| 39 |
| 40 /** |
| 41 * @override |
| 42 */ |
| 43 detach() { |
| 44 this._snippets = []; |
| 45 } |
| 46 |
| 47 |
| 48 /** |
| 49 * @override |
| 50 * @return {number} |
| 51 */ |
| 52 itemCount() { |
| 53 return this._snippets.length; |
| 54 } |
| 55 |
| 56 /** |
| 57 * @override |
| 58 * @param {number} itemIndex |
| 59 * @return {string} |
| 60 */ |
| 61 itemKeyAt(itemIndex) { |
| 62 return this._snippets[itemIndex].name(); |
| 63 } |
| 64 |
| 65 /** |
| 66 * @override |
| 67 * @param {number} itemIndex |
| 68 * @param {string} query |
| 69 * @param {!Element} titleElement |
| 70 * @param {!Element} subtitleElement |
| 71 */ |
| 72 renderItem(itemIndex, query, titleElement, subtitleElement) { |
| 73 titleElement.textContent = this._snippets[itemIndex].name(); |
| 74 titleElement.classList.add('monospace'); |
| 75 QuickOpen.FilteredListWidget.highlightRanges(titleElement, query, true); |
| 76 } |
| 77 }; |
| OLD | NEW |