OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
8 * 1. Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * | |
11 * 2. Redistributions in binary form must reproduce the above | |
12 * copyright notice, this list of conditions and the following disclaimer | |
13 * in the documentation and/or other materials provided with the | |
14 * distribution. | |
15 * | |
16 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS | |
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. | |
20 * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
27 */ | |
28 | |
29 /** | |
30 * @unrestricted | |
31 */ | |
32 Sources.StyleSheetOutlineDialog = class extends QuickOpen.FilteredListWidget.Pro
vider { | |
33 /** | |
34 * @param {!Workspace.UISourceCode} uiSourceCode | |
35 * @param {function(number, number)} selectItemCallback | |
36 */ | |
37 constructor(uiSourceCode, selectItemCallback) { | |
38 super(); | |
39 this._selectItemCallback = selectItemCallback; | |
40 /** @type {!Array<!Common.FormatterWorkerPool.CSSRule>} */ | |
41 this._rules = []; | |
42 Common.formatterWorkerPool.parseCSS(uiSourceCode.workingCopy(), (isLastChunk
, rules) => { | |
43 this._rules.push(...rules); | |
44 this.refresh(); | |
45 }); | |
46 } | |
47 | |
48 /** | |
49 * @param {!Workspace.UISourceCode} uiSourceCode | |
50 * @param {function(number, number)} selectItemCallback | |
51 */ | |
52 static show(uiSourceCode, selectItemCallback) { | |
53 Sources.StyleSheetOutlineDialog._instanceForTests = | |
54 new Sources.StyleSheetOutlineDialog(uiSourceCode, selectItemCallback); | |
55 new QuickOpen.FilteredListWidget(Sources.StyleSheetOutlineDialog._instanceFo
rTests).showAsDialog(); | |
56 } | |
57 | |
58 /** | |
59 * @override | |
60 * @return {number} | |
61 */ | |
62 itemCount() { | |
63 return this._rules.length; | |
64 } | |
65 | |
66 /** | |
67 * @override | |
68 * @param {number} itemIndex | |
69 * @return {string} | |
70 */ | |
71 itemKeyAt(itemIndex) { | |
72 var rule = this._rules[itemIndex]; | |
73 return rule.selectorText || rule.atRule; | |
74 } | |
75 | |
76 /** | |
77 * @override | |
78 * @param {number} itemIndex | |
79 * @param {string} query | |
80 * @return {number} | |
81 */ | |
82 itemScoreAt(itemIndex, query) { | |
83 var rule = this._rules[itemIndex]; | |
84 return -rule.lineNumber; | |
85 } | |
86 | |
87 /** | |
88 * @override | |
89 * @param {number} itemIndex | |
90 * @param {string} query | |
91 * @param {!Element} titleElement | |
92 * @param {!Element} subtitleElement | |
93 */ | |
94 renderItem(itemIndex, query, titleElement, subtitleElement) { | |
95 var rule = this._rules[itemIndex]; | |
96 titleElement.textContent = rule.selectorText || rule.atRule; | |
97 QuickOpen.FilteredListWidget.highlightRanges(titleElement, query); | |
98 subtitleElement.textContent = ':' + (rule.lineNumber + 1); | |
99 } | |
100 | |
101 /** | |
102 * @override | |
103 * @param {?number} itemIndex | |
104 * @param {string} promptValue | |
105 */ | |
106 selectItem(itemIndex, promptValue) { | |
107 if (itemIndex === null) | |
108 return; | |
109 var rule = this._rules[itemIndex]; | |
110 var lineNumber = rule.lineNumber; | |
111 if (!isNaN(lineNumber) && lineNumber >= 0) | |
112 this._selectItemCallback(lineNumber, rule.columnNumber); | |
113 } | |
114 }; | |
OLD | NEW |