blob: 979e5e7b71e43b1ad4e45ae14e3e8d6c9d54db8b [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
Jan Schefflercde20c72020-07-30 11:10:365// @ts-nocheck
6// TODO(crbug.com/1011811): Enable TypeScript compiler checks
7
Tim van der Lippe58e91122020-02-04 13:06:478import * as Common from '../common/common.js';
9import * as QuickOpen from '../quick_open/quick_open.js';
10import * as Workspace from '../workspace/workspace.js'; // eslint-disable-line no-unused-vars
11
Tim van der Lippe22c82032020-01-14 17:00:5112import {evaluateScriptSnippet} from './ScriptSnippetFileSystem.js';
13
Tim van der Lippe046a8d32020-03-17 14:48:3514export class SnippetsQuickOpen extends QuickOpen.FilteredListWidget.Provider {
Blink Reformat4c46d092018-04-07 15:32:3715 constructor() {
16 super();
Tim van der Lippe58e91122020-02-04 13:06:4717 /** @type {!Array<!Workspace.UISourceCode.UISourceCode>} */
Blink Reformat4c46d092018-04-07 15:32:3718 this._snippets = [];
19 }
20 /**
21 * @override
22 * @param {?number} itemIndex
23 * @param {string} promptValue
24 */
25 selectItem(itemIndex, promptValue) {
Tim van der Lippe1d6e57a2019-09-30 11:55:3426 if (itemIndex === null) {
Blink Reformat4c46d092018-04-07 15:32:3727 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:3428 }
Tim van der Lippe22c82032020-01-14 17:00:5129 evaluateScriptSnippet(this._snippets[itemIndex]);
Blink Reformat4c46d092018-04-07 15:32:3730 }
31
32 /**
33 * @override
34 * @param {string} query
35 * @return {string}
36 */
37 notFoundText(query) {
Tim van der Lippe58e91122020-02-04 13:06:4738 return Common.UIString.UIString('No snippets found.');
Blink Reformat4c46d092018-04-07 15:32:3739 }
40
41 /**
42 * @override
43 */
44 attach() {
Alexey Kozyatinskiy3a2eb282018-08-21 16:22:0245 this._snippets = Snippets.project.uiSourceCodes();
Blink Reformat4c46d092018-04-07 15:32:3746 }
47
48 /**
49 * @override
50 */
51 detach() {
52 this._snippets = [];
53 }
54
55
56 /**
57 * @override
58 * @return {number}
59 */
60 itemCount() {
61 return this._snippets.length;
62 }
63
64 /**
65 * @override
66 * @param {number} itemIndex
67 * @return {string}
68 */
69 itemKeyAt(itemIndex) {
70 return this._snippets[itemIndex].name();
71 }
72
73 /**
74 * @override
75 * @param {number} itemIndex
76 * @param {string} query
77 * @param {!Element} titleElement
78 * @param {!Element} subtitleElement
79 */
80 renderItem(itemIndex, query, titleElement, subtitleElement) {
Simon Zünda292e762020-07-23 19:22:1081 titleElement.textContent = unescape(this._snippets[itemIndex].name());
Blink Reformat4c46d092018-04-07 15:32:3782 titleElement.classList.add('monospace');
Tim van der Lippe58e91122020-02-04 13:06:4783 QuickOpen.FilteredListWidget.FilteredListWidget.highlightRanges(titleElement, query, true);
Blink Reformat4c46d092018-04-07 15:32:3784 }
Paul Lewisa0eb3612019-11-27 15:44:5285}