| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 /** | 4 /** |
| 5 * @unrestricted | 5 * @unrestricted |
| 6 */ | 6 */ |
| 7 WebInspector.FileBasedSearchResultsPane = class extends WebInspector.SearchResul
tsPane { | 7 Sources.FileBasedSearchResultsPane = class extends Sources.SearchResultsPane { |
| 8 /** | 8 /** |
| 9 * @param {!WebInspector.ProjectSearchConfig} searchConfig | 9 * @param {!Workspace.ProjectSearchConfig} searchConfig |
| 10 */ | 10 */ |
| 11 constructor(searchConfig) { | 11 constructor(searchConfig) { |
| 12 super(searchConfig); | 12 super(searchConfig); |
| 13 | 13 |
| 14 this._searchResults = []; | 14 this._searchResults = []; |
| 15 this._treeOutline = new TreeOutlineInShadow(); | 15 this._treeOutline = new TreeOutlineInShadow(); |
| 16 this._treeOutline.registerRequiredCSS('sources/fileBasedSearchResultsPane.cs
s'); | 16 this._treeOutline.registerRequiredCSS('sources/fileBasedSearchResultsPane.cs
s'); |
| 17 this.element.appendChild(this._treeOutline.element); | 17 this.element.appendChild(this._treeOutline.element); |
| 18 | 18 |
| 19 this._matchesExpandedCount = 0; | 19 this._matchesExpandedCount = 0; |
| 20 } | 20 } |
| 21 | 21 |
| 22 /** | 22 /** |
| 23 * @override | 23 * @override |
| 24 * @param {!WebInspector.FileBasedSearchResult} searchResult | 24 * @param {!Sources.FileBasedSearchResult} searchResult |
| 25 */ | 25 */ |
| 26 addSearchResult(searchResult) { | 26 addSearchResult(searchResult) { |
| 27 this._searchResults.push(searchResult); | 27 this._searchResults.push(searchResult); |
| 28 var uiSourceCode = searchResult.uiSourceCode; | 28 var uiSourceCode = searchResult.uiSourceCode; |
| 29 if (!uiSourceCode) | 29 if (!uiSourceCode) |
| 30 return; | 30 return; |
| 31 this._addFileTreeElement(searchResult); | 31 this._addFileTreeElement(searchResult); |
| 32 } | 32 } |
| 33 | 33 |
| 34 /** | 34 /** |
| 35 * @param {!WebInspector.FileBasedSearchResult} searchResult | 35 * @param {!Sources.FileBasedSearchResult} searchResult |
| 36 */ | 36 */ |
| 37 _addFileTreeElement(searchResult) { | 37 _addFileTreeElement(searchResult) { |
| 38 var fileTreeElement = new WebInspector.FileBasedSearchResultsPane.FileTreeEl
ement(this._searchConfig, searchResult); | 38 var fileTreeElement = new Sources.FileBasedSearchResultsPane.FileTreeElement
(this._searchConfig, searchResult); |
| 39 this._treeOutline.appendChild(fileTreeElement); | 39 this._treeOutline.appendChild(fileTreeElement); |
| 40 // Expand until at least a certain number of matches is expanded. | 40 // Expand until at least a certain number of matches is expanded. |
| 41 if (this._matchesExpandedCount < WebInspector.FileBasedSearchResultsPane.mat
chesExpandedByDefaultCount) | 41 if (this._matchesExpandedCount < Sources.FileBasedSearchResultsPane.matchesE
xpandedByDefaultCount) |
| 42 fileTreeElement.expand(); | 42 fileTreeElement.expand(); |
| 43 this._matchesExpandedCount += searchResult.searchMatches.length; | 43 this._matchesExpandedCount += searchResult.searchMatches.length; |
| 44 } | 44 } |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 WebInspector.FileBasedSearchResultsPane.matchesExpandedByDefaultCount = 20; | 47 Sources.FileBasedSearchResultsPane.matchesExpandedByDefaultCount = 20; |
| 48 WebInspector.FileBasedSearchResultsPane.fileMatchesShownAtOnce = 20; | 48 Sources.FileBasedSearchResultsPane.fileMatchesShownAtOnce = 20; |
| 49 | 49 |
| 50 /** | 50 /** |
| 51 * @unrestricted | 51 * @unrestricted |
| 52 */ | 52 */ |
| 53 WebInspector.FileBasedSearchResultsPane.FileTreeElement = class extends TreeElem
ent { | 53 Sources.FileBasedSearchResultsPane.FileTreeElement = class extends TreeElement { |
| 54 /** | 54 /** |
| 55 * @param {!WebInspector.ProjectSearchConfig} searchConfig | 55 * @param {!Workspace.ProjectSearchConfig} searchConfig |
| 56 * @param {!WebInspector.FileBasedSearchResult} searchResult | 56 * @param {!Sources.FileBasedSearchResult} searchResult |
| 57 */ | 57 */ |
| 58 constructor(searchConfig, searchResult) { | 58 constructor(searchConfig, searchResult) { |
| 59 super('', true); | 59 super('', true); |
| 60 this._searchConfig = searchConfig; | 60 this._searchConfig = searchConfig; |
| 61 this._searchResult = searchResult; | 61 this._searchResult = searchResult; |
| 62 | 62 |
| 63 this.toggleOnClick = true; | 63 this.toggleOnClick = true; |
| 64 this.selectable = false; | 64 this.selectable = false; |
| 65 } | 65 } |
| 66 | 66 |
| 67 /** | 67 /** |
| 68 * @override | 68 * @override |
| 69 */ | 69 */ |
| 70 onexpand() { | 70 onexpand() { |
| 71 if (this._initialized) | 71 if (this._initialized) |
| 72 return; | 72 return; |
| 73 | 73 |
| 74 this._updateMatchesUI(); | 74 this._updateMatchesUI(); |
| 75 this._initialized = true; | 75 this._initialized = true; |
| 76 } | 76 } |
| 77 | 77 |
| 78 _updateMatchesUI() { | 78 _updateMatchesUI() { |
| 79 this.removeChildren(); | 79 this.removeChildren(); |
| 80 var toIndex = Math.min( | 80 var toIndex = Math.min( |
| 81 this._searchResult.searchMatches.length, WebInspector.FileBasedSearchRes
ultsPane.fileMatchesShownAtOnce); | 81 this._searchResult.searchMatches.length, Sources.FileBasedSearchResultsP
ane.fileMatchesShownAtOnce); |
| 82 if (toIndex < this._searchResult.searchMatches.length) { | 82 if (toIndex < this._searchResult.searchMatches.length) { |
| 83 this._appendSearchMatches(0, toIndex - 1); | 83 this._appendSearchMatches(0, toIndex - 1); |
| 84 this._appendShowMoreMatchesElement(toIndex - 1); | 84 this._appendShowMoreMatchesElement(toIndex - 1); |
| 85 } else { | 85 } else { |
| 86 this._appendSearchMatches(0, toIndex); | 86 this._appendSearchMatches(0, toIndex); |
| 87 } | 87 } |
| 88 } | 88 } |
| 89 | 89 |
| 90 /** | 90 /** |
| 91 * @override | 91 * @override |
| 92 */ | 92 */ |
| 93 onattach() { | 93 onattach() { |
| 94 this._updateSearchMatches(); | 94 this._updateSearchMatches(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 _updateSearchMatches() { | 97 _updateSearchMatches() { |
| 98 this.listItemElement.classList.add('search-result'); | 98 this.listItemElement.classList.add('search-result'); |
| 99 | 99 |
| 100 var fileNameSpan = createElement('span'); | 100 var fileNameSpan = createElement('span'); |
| 101 fileNameSpan.className = 'search-result-file-name'; | 101 fileNameSpan.className = 'search-result-file-name'; |
| 102 fileNameSpan.textContent = this._searchResult.uiSourceCode.fullDisplayName()
; | 102 fileNameSpan.textContent = this._searchResult.uiSourceCode.fullDisplayName()
; |
| 103 this.listItemElement.appendChild(fileNameSpan); | 103 this.listItemElement.appendChild(fileNameSpan); |
| 104 | 104 |
| 105 var matchesCountSpan = createElement('span'); | 105 var matchesCountSpan = createElement('span'); |
| 106 matchesCountSpan.className = 'search-result-matches-count'; | 106 matchesCountSpan.className = 'search-result-matches-count'; |
| 107 | 107 |
| 108 var searchMatchesCount = this._searchResult.searchMatches.length; | 108 var searchMatchesCount = this._searchResult.searchMatches.length; |
| 109 if (searchMatchesCount === 1) | 109 if (searchMatchesCount === 1) |
| 110 matchesCountSpan.textContent = WebInspector.UIString('(%d match)', searchM
atchesCount); | 110 matchesCountSpan.textContent = Common.UIString('(%d match)', searchMatches
Count); |
| 111 else | 111 else |
| 112 matchesCountSpan.textContent = WebInspector.UIString('(%d matches)', searc
hMatchesCount); | 112 matchesCountSpan.textContent = Common.UIString('(%d matches)', searchMatch
esCount); |
| 113 | 113 |
| 114 this.listItemElement.appendChild(matchesCountSpan); | 114 this.listItemElement.appendChild(matchesCountSpan); |
| 115 if (this.expanded) | 115 if (this.expanded) |
| 116 this._updateMatchesUI(); | 116 this._updateMatchesUI(); |
| 117 } | 117 } |
| 118 | 118 |
| 119 /** | 119 /** |
| 120 * @param {number} fromIndex | 120 * @param {number} fromIndex |
| 121 * @param {number} toIndex | 121 * @param {number} toIndex |
| 122 */ | 122 */ |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 searchMatchElement.listItemElement.className = 'search-match source-code'; | 154 searchMatchElement.listItemElement.className = 'search-match source-code'; |
| 155 searchMatchElement.listItemElement.appendChild(anchor); | 155 searchMatchElement.listItemElement.appendChild(anchor); |
| 156 } | 156 } |
| 157 } | 157 } |
| 158 | 158 |
| 159 /** | 159 /** |
| 160 * @param {number} startMatchIndex | 160 * @param {number} startMatchIndex |
| 161 */ | 161 */ |
| 162 _appendShowMoreMatchesElement(startMatchIndex) { | 162 _appendShowMoreMatchesElement(startMatchIndex) { |
| 163 var matchesLeftCount = this._searchResult.searchMatches.length - startMatchI
ndex; | 163 var matchesLeftCount = this._searchResult.searchMatches.length - startMatchI
ndex; |
| 164 var showMoreMatchesText = WebInspector.UIString('Show all matches (%d more).
', matchesLeftCount); | 164 var showMoreMatchesText = Common.UIString('Show all matches (%d more).', mat
chesLeftCount); |
| 165 this._showMoreMatchesTreeElement = new TreeElement(showMoreMatchesText); | 165 this._showMoreMatchesTreeElement = new TreeElement(showMoreMatchesText); |
| 166 this.appendChild(this._showMoreMatchesTreeElement); | 166 this.appendChild(this._showMoreMatchesTreeElement); |
| 167 this._showMoreMatchesTreeElement.listItemElement.classList.add('show-more-ma
tches'); | 167 this._showMoreMatchesTreeElement.listItemElement.classList.add('show-more-ma
tches'); |
| 168 this._showMoreMatchesTreeElement.onselect = this._showMoreMatchesElementSele
cted.bind(this, startMatchIndex); | 168 this._showMoreMatchesTreeElement.onselect = this._showMoreMatchesElementSele
cted.bind(this, startMatchIndex); |
| 169 } | 169 } |
| 170 | 170 |
| 171 /** | 171 /** |
| 172 * @param {!WebInspector.UISourceCode} uiSourceCode | 172 * @param {!Workspace.UISourceCode} uiSourceCode |
| 173 * @param {number} lineNumber | 173 * @param {number} lineNumber |
| 174 * @param {number} columnNumber | 174 * @param {number} columnNumber |
| 175 * @return {!Element} | 175 * @return {!Element} |
| 176 */ | 176 */ |
| 177 _createAnchor(uiSourceCode, lineNumber, columnNumber) { | 177 _createAnchor(uiSourceCode, lineNumber, columnNumber) { |
| 178 return WebInspector.Linkifier.linkifyUsingRevealer(uiSourceCode.uiLocation(l
ineNumber, columnNumber), ''); | 178 return Components.Linkifier.linkifyUsingRevealer(uiSourceCode.uiLocation(lin
eNumber, columnNumber), ''); |
| 179 } | 179 } |
| 180 | 180 |
| 181 /** | 181 /** |
| 182 * @param {string} lineContent | 182 * @param {string} lineContent |
| 183 * @param {!Array.<!WebInspector.SourceRange>} matchRanges | 183 * @param {!Array.<!Common.SourceRange>} matchRanges |
| 184 */ | 184 */ |
| 185 _createContentSpan(lineContent, matchRanges) { | 185 _createContentSpan(lineContent, matchRanges) { |
| 186 var contentSpan = createElement('span'); | 186 var contentSpan = createElement('span'); |
| 187 contentSpan.className = 'search-match-content'; | 187 contentSpan.className = 'search-match-content'; |
| 188 contentSpan.textContent = lineContent; | 188 contentSpan.textContent = lineContent; |
| 189 WebInspector.highlightRangesWithStyleClass(contentSpan, matchRanges, 'highli
ghted-match'); | 189 UI.highlightRangesWithStyleClass(contentSpan, matchRanges, 'highlighted-matc
h'); |
| 190 return contentSpan; | 190 return contentSpan; |
| 191 } | 191 } |
| 192 | 192 |
| 193 /** | 193 /** |
| 194 * @param {string} lineContent | 194 * @param {string} lineContent |
| 195 * @param {!RegExp} regex | 195 * @param {!RegExp} regex |
| 196 * @return {!Array.<!WebInspector.SourceRange>} | 196 * @return {!Array.<!Common.SourceRange>} |
| 197 */ | 197 */ |
| 198 _regexMatchRanges(lineContent, regex) { | 198 _regexMatchRanges(lineContent, regex) { |
| 199 regex.lastIndex = 0; | 199 regex.lastIndex = 0; |
| 200 var match; | 200 var match; |
| 201 var matchRanges = []; | 201 var matchRanges = []; |
| 202 while ((regex.lastIndex < lineContent.length) && (match = regex.exec(lineCon
tent))) | 202 while ((regex.lastIndex < lineContent.length) && (match = regex.exec(lineCon
tent))) |
| 203 matchRanges.push(new WebInspector.SourceRange(match.index, match[0].length
)); | 203 matchRanges.push(new Common.SourceRange(match.index, match[0].length)); |
| 204 | 204 |
| 205 return matchRanges; | 205 return matchRanges; |
| 206 } | 206 } |
| 207 | 207 |
| 208 /** | 208 /** |
| 209 * @param {number} startMatchIndex | 209 * @param {number} startMatchIndex |
| 210 * @return {boolean} | 210 * @return {boolean} |
| 211 */ | 211 */ |
| 212 _showMoreMatchesElementSelected(startMatchIndex) { | 212 _showMoreMatchesElementSelected(startMatchIndex) { |
| 213 this.removeChild(this._showMoreMatchesTreeElement); | 213 this.removeChild(this._showMoreMatchesTreeElement); |
| 214 this._appendSearchMatches(startMatchIndex, this._searchResult.searchMatches.
length); | 214 this._appendSearchMatches(startMatchIndex, this._searchResult.searchMatches.
length); |
| 215 return false; | 215 return false; |
| 216 } | 216 } |
| 217 }; | 217 }; |
| OLD | NEW |