blob: c2c3228e4c626fdc65e8e0dda98d4db1074facf3 [file] [log] [blame]
Blink Reformat4c46d092018-04-07 15:32:371// 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
5Snippets.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) {
Tim van der Lippe1d6e57a2019-09-30 11:55:3417 if (itemIndex === null) {
Blink Reformat4c46d092018-04-07 15:32:3718 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:3419 }
Alexey Kozyatinskiy3a2eb282018-08-21 16:22:0220 Snippets.evaluateScriptSnippet(this._snippets[itemIndex]);
Blink Reformat4c46d092018-04-07 15:32:3721 }
22
23 /**
24 * @override
25 * @param {string} query
26 * @return {string}
27 */
28 notFoundText(query) {
29 return Common.UIString('No snippets found.');
30 }
31
32 /**
33 * @override
34 */
35 attach() {
Alexey Kozyatinskiy3a2eb282018-08-21 16:22:0236 this._snippets = Snippets.project.uiSourceCodes();
Blink Reformat4c46d092018-04-07 15:32:3737 }
38
39 /**
40 * @override
41 */
42 detach() {
43 this._snippets = [];
44 }
45
46
47 /**
48 * @override
49 * @return {number}
50 */
51 itemCount() {
52 return this._snippets.length;
53 }
54
55 /**
56 * @override
57 * @param {number} itemIndex
58 * @return {string}
59 */
60 itemKeyAt(itemIndex) {
61 return this._snippets[itemIndex].name();
62 }
63
64 /**
65 * @override
66 * @param {number} itemIndex
67 * @param {string} query
68 * @param {!Element} titleElement
69 * @param {!Element} subtitleElement
70 */
71 renderItem(itemIndex, query, titleElement, subtitleElement) {
Alexey Kozyatinskiy3a2eb282018-08-21 16:22:0272 titleElement.textContent = unescape(this._snippets[itemIndex].name());
Blink Reformat4c46d092018-04-07 15:32:3773 titleElement.classList.add('monospace');
74 QuickOpen.FilteredListWidget.highlightRanges(titleElement, query, true);
75 }
76};