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 /** |
| 6 * @unrestricted |
| 7 */ |
| 8 Sources.OutlineQuickOpen = class extends QuickOpen.FilteredListWidget.Provider { |
| 9 constructor() { |
| 10 super(); |
| 11 this._items = []; |
| 12 this._active = false; |
| 13 } |
| 14 |
| 15 /** |
| 16 * @override |
| 17 */ |
| 18 attach() { |
| 19 this._items = []; |
| 20 this._active = false; |
| 21 |
| 22 var uiSourceCode = this._currentUISourceCode(); |
| 23 if (uiSourceCode) { |
| 24 this._active = Common.formatterWorkerPool.outlineForMimetype( |
| 25 uiSourceCode.workingCopy(), uiSourceCode.contentType().canonicalMimeTy
pe(), |
| 26 this._didBuildOutlineChunk.bind(this)); |
| 27 } |
| 28 } |
| 29 |
| 30 /** |
| 31 * @param {boolean} isLastChunk |
| 32 * @param {!Array<!Common.FormatterWorkerPool.OutlineItem>} items |
| 33 */ |
| 34 _didBuildOutlineChunk(isLastChunk, items) { |
| 35 this._items.push(...items); |
| 36 this.refresh(); |
| 37 } |
| 38 |
| 39 /** |
| 40 * @override |
| 41 * @return {number} |
| 42 */ |
| 43 itemCount() { |
| 44 return this._items.length; |
| 45 } |
| 46 |
| 47 /** |
| 48 * @override |
| 49 * @param {number} itemIndex |
| 50 * @return {string} |
| 51 */ |
| 52 itemKeyAt(itemIndex) { |
| 53 var item = this._items[itemIndex]; |
| 54 return item.title + (item.subtitle ? item.subtitle : ''); |
| 55 } |
| 56 |
| 57 /** |
| 58 * @override |
| 59 * @param {number} itemIndex |
| 60 * @param {string} query |
| 61 * @return {number} |
| 62 */ |
| 63 itemScoreAt(itemIndex, query) { |
| 64 var item = this._items[itemIndex]; |
| 65 var methodName = query.split('(')[0]; |
| 66 if (methodName.toLowerCase() === item.title.toLowerCase()) |
| 67 return 1 / (1 + item.line); |
| 68 return -item.line - 1; |
| 69 } |
| 70 |
| 71 /** |
| 72 * @override |
| 73 * @param {number} itemIndex |
| 74 * @param {string} query |
| 75 * @param {!Element} titleElement |
| 76 * @param {!Element} subtitleElement |
| 77 */ |
| 78 renderItem(itemIndex, query, titleElement, subtitleElement) { |
| 79 var item = this._items[itemIndex]; |
| 80 titleElement.textContent = item.title + (item.subtitle ? item.subtitle : '')
; |
| 81 QuickOpen.FilteredListWidget.highlightRanges(titleElement, query); |
| 82 subtitleElement.textContent = ':' + (item.line + 1); |
| 83 } |
| 84 |
| 85 /** |
| 86 * @override |
| 87 * @param {?number} itemIndex |
| 88 * @param {string} promptValue |
| 89 */ |
| 90 selectItem(itemIndex, promptValue) { |
| 91 if (itemIndex === null) |
| 92 return; |
| 93 var uiSourceCode = this._currentUISourceCode(); |
| 94 if (!uiSourceCode) |
| 95 return; |
| 96 var lineNumber = this._items[itemIndex].line; |
| 97 if (!isNaN(lineNumber) && lineNumber >= 0) |
| 98 Common.Revealer.reveal(uiSourceCode.uiLocation(lineNumber, this._items[ite
mIndex].column)); |
| 99 } |
| 100 |
| 101 |
| 102 /** |
| 103 * @return {?Workspace.UISourceCode} |
| 104 */ |
| 105 _currentUISourceCode() { |
| 106 var sourcesView = UI.context.flavor(Sources.SourcesView); |
| 107 if (!sourcesView) |
| 108 return null; |
| 109 return sourcesView.currentUISourceCode(); |
| 110 } |
| 111 |
| 112 /** |
| 113 * @override |
| 114 * @return {string} |
| 115 */ |
| 116 notFoundText() { |
| 117 if (!this._currentUISourceCode()) |
| 118 return Common.UIString('No file selected.'); |
| 119 if (!this._active) |
| 120 return Common.UIString('Open a JavaScript or CSS file to see symbols'); |
| 121 return Common.UIString('No results found'); |
| 122 } |
| 123 }; |
OLD | NEW |