| 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 | |
| 5 /** | 4 /** |
| 6 * @constructor | 5 * @unrestricted |
| 7 * @extends {WebInspector.VBox} | |
| 8 */ | 6 */ |
| 9 WebInspector.AdvancedSearchView = function() | 7 WebInspector.AdvancedSearchView = class extends WebInspector.VBox { |
| 10 { | 8 constructor() { |
| 11 WebInspector.VBox.call(this, true); | 9 super(true); |
| 12 this.setMinimumSize(0, 40); | 10 this.setMinimumSize(0, 40); |
| 13 this.registerRequiredCSS("sources/sourcesSearch.css"); | 11 this.registerRequiredCSS('sources/sourcesSearch.css'); |
| 14 | 12 |
| 15 this._searchId = 0; | 13 this._searchId = 0; |
| 16 | 14 |
| 17 this.contentElement.classList.add("search-view"); | 15 this.contentElement.classList.add('search-view'); |
| 18 | 16 |
| 19 this._searchPanelElement = this.contentElement.createChild("div", "search-dr
awer-header"); | 17 this._searchPanelElement = this.contentElement.createChild('div', 'search-dr
awer-header'); |
| 20 this._searchPanelElement.addEventListener("keydown", this._onKeyDown.bind(th
is), false); | 18 this._searchPanelElement.addEventListener('keydown', this._onKeyDown.bind(th
is), false); |
| 21 this._searchPanelElement.addEventListener("input", this._onInput.bind(this),
false); | 19 this._searchPanelElement.addEventListener('input', this._onInput.bind(this),
false); |
| 22 | 20 |
| 23 this._searchResultsElement = this.contentElement.createChild("div"); | 21 this._searchResultsElement = this.contentElement.createChild('div'); |
| 24 this._searchResultsElement.className = "search-results"; | 22 this._searchResultsElement.className = 'search-results'; |
| 25 | 23 |
| 26 this._search = WebInspector.HistoryInput.create(); | 24 this._search = WebInspector.HistoryInput.create(); |
| 27 this._searchPanelElement.appendChild(this._search); | 25 this._searchPanelElement.appendChild(this._search); |
| 28 this._search.placeholder = WebInspector.UIString("Search all sources (use \"
file:\" to filter by path)\u200e"); | 26 this._search.placeholder = WebInspector.UIString('Search all sources (use "f
ile:" to filter by path)\u200e'); |
| 29 this._search.setAttribute("type", "text"); | 27 this._search.setAttribute('type', 'text'); |
| 30 this._search.classList.add("search-config-search"); | 28 this._search.classList.add('search-config-search'); |
| 31 this._search.setAttribute("results", "0"); | 29 this._search.setAttribute('results', '0'); |
| 32 this._search.setAttribute("size", 42); | 30 this._search.setAttribute('size', 42); |
| 33 | 31 |
| 34 this._searchPanelElement.createChild("div", "search-icon"); | 32 this._searchPanelElement.createChild('div', 'search-icon'); |
| 35 this._searchInputClearElement = this._searchPanelElement.createChild("div",
"search-cancel-button"); | 33 this._searchInputClearElement = this._searchPanelElement.createChild('div',
'search-cancel-button'); |
| 36 this._searchInputClearElement.hidden = true; | 34 this._searchInputClearElement.hidden = true; |
| 37 this._searchInputClearElement.addEventListener("click", this._onSearchInputC
lear.bind(this), false); | 35 this._searchInputClearElement.addEventListener('click', this._onSearchInputC
lear.bind(this), false); |
| 38 | 36 |
| 39 this._ignoreCaseLabel = createCheckboxLabel(WebInspector.UIString("Ignore ca
se")); | 37 this._ignoreCaseLabel = createCheckboxLabel(WebInspector.UIString('Ignore ca
se')); |
| 40 this._ignoreCaseLabel.classList.add("search-config-label"); | 38 this._ignoreCaseLabel.classList.add('search-config-label'); |
| 41 this._searchPanelElement.appendChild(this._ignoreCaseLabel); | 39 this._searchPanelElement.appendChild(this._ignoreCaseLabel); |
| 42 this._ignoreCaseCheckbox = this._ignoreCaseLabel.checkboxElement; | 40 this._ignoreCaseCheckbox = this._ignoreCaseLabel.checkboxElement; |
| 43 this._ignoreCaseCheckbox.classList.add("search-config-checkbox"); | 41 this._ignoreCaseCheckbox.classList.add('search-config-checkbox'); |
| 44 | 42 |
| 45 this._regexLabel = createCheckboxLabel(WebInspector.UIString("Regular expres
sion")); | 43 this._regexLabel = createCheckboxLabel(WebInspector.UIString('Regular expres
sion')); |
| 46 this._regexLabel.classList.add("search-config-label"); | 44 this._regexLabel.classList.add('search-config-label'); |
| 47 this._searchPanelElement.appendChild(this._regexLabel); | 45 this._searchPanelElement.appendChild(this._regexLabel); |
| 48 this._regexCheckbox = this._regexLabel.checkboxElement; | 46 this._regexCheckbox = this._regexLabel.checkboxElement; |
| 49 this._regexCheckbox.classList.add("search-config-checkbox"); | 47 this._regexCheckbox.classList.add('search-config-checkbox'); |
| 50 | 48 |
| 51 this._searchToolbarElement = this.contentElement.createChild("div", "search-
toolbar-summary"); | 49 this._searchToolbarElement = this.contentElement.createChild('div', 'search-
toolbar-summary'); |
| 52 this._searchMessageElement = this._searchToolbarElement.createChild("div", "
search-message"); | 50 this._searchMessageElement = this._searchToolbarElement.createChild('div', '
search-message'); |
| 53 this._searchProgressPlaceholderElement = this._searchToolbarElement.createCh
ild("div", "flex-centered"); | 51 this._searchProgressPlaceholderElement = this._searchToolbarElement.createCh
ild('div', 'flex-centered'); |
| 54 this._searchResultsMessageElement = this._searchToolbarElement.createChild("
div", "search-message"); | 52 this._searchResultsMessageElement = this._searchToolbarElement.createChild('
div', 'search-message'); |
| 55 | 53 |
| 56 this._advancedSearchConfig = WebInspector.settings.createLocalSetting("advan
cedSearchConfig", new WebInspector.SearchConfig("", true, false).toPlainObject()
); | 54 this._advancedSearchConfig = WebInspector.settings.createLocalSetting( |
| 55 'advancedSearchConfig', new WebInspector.SearchConfig('', true, false).t
oPlainObject()); |
| 57 this._load(); | 56 this._load(); |
| 58 /** @type {!WebInspector.SearchScope} */ | 57 /** @type {!WebInspector.SearchScope} */ |
| 59 this._searchScope = new WebInspector.SourcesSearchScope(); | 58 this._searchScope = new WebInspector.SourcesSearchScope(); |
| 59 } |
| 60 |
| 61 /** |
| 62 * @param {string} query |
| 63 * @param {string=} filePath |
| 64 */ |
| 65 static openSearch(query, filePath) { |
| 66 WebInspector.viewManager.showView('sources.search'); |
| 67 var searchView = |
| 68 /** @type {!WebInspector.AdvancedSearchView} */ (self.runtime.sharedInst
ance(WebInspector.AdvancedSearchView)); |
| 69 var fileMask = filePath ? ' file:' + filePath : ''; |
| 70 searchView._toggle(query + fileMask); |
| 71 } |
| 72 |
| 73 /** |
| 74 * @return {!WebInspector.SearchConfig} |
| 75 */ |
| 76 _buildSearchConfig() { |
| 77 return new WebInspector.SearchConfig( |
| 78 this._search.value, this._ignoreCaseCheckbox.checked, this._regexCheckbo
x.checked); |
| 79 } |
| 80 |
| 81 /** |
| 82 * @param {string} queryCandidate |
| 83 */ |
| 84 _toggle(queryCandidate) { |
| 85 if (queryCandidate) |
| 86 this._search.value = queryCandidate; |
| 87 |
| 88 if (this.isShowing()) |
| 89 this.focus(); |
| 90 else |
| 91 this._focusOnShow = true; |
| 92 |
| 93 this._startIndexing(); |
| 94 } |
| 95 |
| 96 /** |
| 97 * @override |
| 98 */ |
| 99 wasShown() { |
| 100 if (this._focusOnShow) { |
| 101 this.focus(); |
| 102 delete this._focusOnShow; |
| 103 } |
| 104 } |
| 105 |
| 106 _onIndexingFinished() { |
| 107 var finished = !this._progressIndicator.isCanceled(); |
| 108 this._progressIndicator.done(); |
| 109 delete this._progressIndicator; |
| 110 delete this._isIndexing; |
| 111 this._indexingFinished(finished); |
| 112 if (!finished) |
| 113 delete this._pendingSearchConfig; |
| 114 if (!this._pendingSearchConfig) |
| 115 return; |
| 116 var searchConfig = this._pendingSearchConfig; |
| 117 delete this._pendingSearchConfig; |
| 118 this._innerStartSearch(searchConfig); |
| 119 } |
| 120 |
| 121 _startIndexing() { |
| 122 this._isIndexing = true; |
| 123 if (this._progressIndicator) |
| 124 this._progressIndicator.done(); |
| 125 this._progressIndicator = new WebInspector.ProgressIndicator(); |
| 126 this._searchMessageElement.textContent = WebInspector.UIString('Indexing\u20
26'); |
| 127 this._progressIndicator.show(this._searchProgressPlaceholderElement); |
| 128 this._searchScope.performIndexing( |
| 129 new WebInspector.ProgressProxy(this._progressIndicator, this._onIndexing
Finished.bind(this))); |
| 130 } |
| 131 |
| 132 _onSearchInputClear() { |
| 133 this._search.value = ''; |
| 134 this.focus(); |
| 135 this._searchInputClearElement.hidden = true; |
| 136 } |
| 137 |
| 138 /** |
| 139 * @param {number} searchId |
| 140 * @param {!WebInspector.FileBasedSearchResult} searchResult |
| 141 */ |
| 142 _onSearchResult(searchId, searchResult) { |
| 143 if (searchId !== this._searchId || !this._progressIndicator) |
| 144 return; |
| 145 if (this._progressIndicator && this._progressIndicator.isCanceled()) { |
| 146 this._onIndexingFinished(); |
| 147 return; |
| 148 } |
| 149 this._addSearchResult(searchResult); |
| 150 if (!searchResult.searchMatches.length) |
| 151 return; |
| 152 if (!this._searchResultsPane) |
| 153 this._searchResultsPane = this._searchScope.createSearchResultsPane(this._
searchConfig); |
| 154 this._resetResults(); |
| 155 this._searchResultsElement.appendChild(this._searchResultsPane.element); |
| 156 this._searchResultsPane.addSearchResult(searchResult); |
| 157 } |
| 158 |
| 159 /** |
| 160 * @param {number} searchId |
| 161 * @param {boolean} finished |
| 162 */ |
| 163 _onSearchFinished(searchId, finished) { |
| 164 if (searchId !== this._searchId || !this._progressIndicator) |
| 165 return; |
| 166 if (!this._searchResultsPane) |
| 167 this._nothingFound(); |
| 168 this._searchFinished(finished); |
| 169 delete this._searchConfig; |
| 170 } |
| 171 |
| 172 /** |
| 173 * @param {!WebInspector.SearchConfig} searchConfig |
| 174 */ |
| 175 _startSearch(searchConfig) { |
| 176 this._resetSearch(); |
| 177 ++this._searchId; |
| 178 if (!this._isIndexing) |
| 179 this._startIndexing(); |
| 180 this._pendingSearchConfig = searchConfig; |
| 181 } |
| 182 |
| 183 /** |
| 184 * @param {!WebInspector.SearchConfig} searchConfig |
| 185 */ |
| 186 _innerStartSearch(searchConfig) { |
| 187 this._searchConfig = searchConfig; |
| 188 if (this._progressIndicator) |
| 189 this._progressIndicator.done(); |
| 190 this._progressIndicator = new WebInspector.ProgressIndicator(); |
| 191 this._searchStarted(this._progressIndicator); |
| 192 this._searchScope.performSearch( |
| 193 searchConfig, this._progressIndicator, this._onSearchResult.bind(this, t
his._searchId), |
| 194 this._onSearchFinished.bind(this, this._searchId)); |
| 195 } |
| 196 |
| 197 _resetSearch() { |
| 198 this._stopSearch(); |
| 199 |
| 200 if (this._searchResultsPane) { |
| 201 this._resetResults(); |
| 202 delete this._searchResultsPane; |
| 203 } |
| 204 } |
| 205 |
| 206 _stopSearch() { |
| 207 if (this._progressIndicator && !this._isIndexing) |
| 208 this._progressIndicator.cancel(); |
| 209 if (this._searchScope) |
| 210 this._searchScope.stopSearch(); |
| 211 delete this._searchConfig; |
| 212 } |
| 213 |
| 214 /** |
| 215 * @param {!WebInspector.ProgressIndicator} progressIndicator |
| 216 */ |
| 217 _searchStarted(progressIndicator) { |
| 218 this._resetResults(); |
| 219 this._resetCounters(); |
| 220 |
| 221 this._searchMessageElement.textContent = WebInspector.UIString('Searching\u2
026'); |
| 222 progressIndicator.show(this._searchProgressPlaceholderElement); |
| 223 this._updateSearchResultsMessage(); |
| 224 |
| 225 if (!this._searchingView) |
| 226 this._searchingView = new WebInspector.EmptyWidget(WebInspector.UIString('
Searching\u2026')); |
| 227 this._searchingView.show(this._searchResultsElement); |
| 228 } |
| 229 |
| 230 /** |
| 231 * @param {boolean} finished |
| 232 */ |
| 233 _indexingFinished(finished) { |
| 234 this._searchMessageElement.textContent = finished ? '' : WebInspector.UIStri
ng('Indexing interrupted.'); |
| 235 } |
| 236 |
| 237 _updateSearchResultsMessage() { |
| 238 if (this._searchMatchesCount && this._searchResultsCount) |
| 239 this._searchResultsMessageElement.textContent = WebInspector.UIString( |
| 240 'Found %d matches in %d files.', this._searchMatchesCount, this._nonEm
ptySearchResultsCount); |
| 241 else |
| 242 this._searchResultsMessageElement.textContent = ''; |
| 243 } |
| 244 |
| 245 _resetResults() { |
| 246 if (this._searchingView) |
| 247 this._searchingView.detach(); |
| 248 if (this._notFoundView) |
| 249 this._notFoundView.detach(); |
| 250 this._searchResultsElement.removeChildren(); |
| 251 } |
| 252 |
| 253 _resetCounters() { |
| 254 this._searchMatchesCount = 0; |
| 255 this._searchResultsCount = 0; |
| 256 this._nonEmptySearchResultsCount = 0; |
| 257 } |
| 258 |
| 259 _nothingFound() { |
| 260 this._resetResults(); |
| 261 |
| 262 if (!this._notFoundView) |
| 263 this._notFoundView = new WebInspector.EmptyWidget(WebInspector.UIString('N
o matches found.')); |
| 264 this._notFoundView.show(this._searchResultsElement); |
| 265 this._searchResultsMessageElement.textContent = WebInspector.UIString('No ma
tches found.'); |
| 266 } |
| 267 |
| 268 /** |
| 269 * @param {!WebInspector.FileBasedSearchResult} searchResult |
| 270 */ |
| 271 _addSearchResult(searchResult) { |
| 272 this._searchMatchesCount += searchResult.searchMatches.length; |
| 273 this._searchResultsCount++; |
| 274 if (searchResult.searchMatches.length) |
| 275 this._nonEmptySearchResultsCount++; |
| 276 this._updateSearchResultsMessage(); |
| 277 } |
| 278 |
| 279 /** |
| 280 * @param {boolean} finished |
| 281 */ |
| 282 _searchFinished(finished) { |
| 283 this._searchMessageElement.textContent = |
| 284 finished ? WebInspector.UIString('Search finished.') : WebInspector.UISt
ring('Search interrupted.'); |
| 285 } |
| 286 |
| 287 /** |
| 288 * @override |
| 289 */ |
| 290 focus() { |
| 291 this._search.focus(); |
| 292 this._search.select(); |
| 293 } |
| 294 |
| 295 /** |
| 296 * @override |
| 297 */ |
| 298 willHide() { |
| 299 this._stopSearch(); |
| 300 } |
| 301 |
| 302 /** |
| 303 * @param {!Event} event |
| 304 */ |
| 305 _onKeyDown(event) { |
| 306 switch (event.keyCode) { |
| 307 case WebInspector.KeyboardShortcut.Keys.Enter.code: |
| 308 this._onAction(); |
| 309 break; |
| 310 } |
| 311 } |
| 312 |
| 313 _onInput() { |
| 314 if (this._search.value && this._search.value.length) |
| 315 this._searchInputClearElement.hidden = false; |
| 316 else |
| 317 this._searchInputClearElement.hidden = true; |
| 318 } |
| 319 |
| 320 _save() { |
| 321 this._advancedSearchConfig.set(this._buildSearchConfig().toPlainObject()); |
| 322 } |
| 323 |
| 324 _load() { |
| 325 var searchConfig = WebInspector.SearchConfig.fromPlainObject(this._advancedS
earchConfig.get()); |
| 326 this._search.value = searchConfig.query(); |
| 327 this._ignoreCaseCheckbox.checked = searchConfig.ignoreCase(); |
| 328 this._regexCheckbox.checked = searchConfig.isRegex(); |
| 329 if (this._search.value && this._search.value.length) |
| 330 this._searchInputClearElement.hidden = false; |
| 331 } |
| 332 |
| 333 _onAction() { |
| 334 var searchConfig = this._buildSearchConfig(); |
| 335 if (!searchConfig.query() || !searchConfig.query().length) |
| 336 return; |
| 337 |
| 338 this._save(); |
| 339 this._startSearch(searchConfig); |
| 340 } |
| 60 }; | 341 }; |
| 61 | 342 |
| 62 WebInspector.AdvancedSearchView.prototype = { | 343 |
| 63 /** | 344 /** |
| 64 * @return {!WebInspector.SearchConfig} | 345 * @unrestricted |
| 65 */ | 346 */ |
| 66 _buildSearchConfig: function() | 347 WebInspector.SearchResultsPane = class { |
| 67 { | 348 /** |
| 68 return new WebInspector.SearchConfig(this._search.value, this._ignoreCas
eCheckbox.checked, this._regexCheckbox.checked); | 349 * @param {!WebInspector.ProjectSearchConfig} searchConfig |
| 69 }, | 350 */ |
| 70 | 351 constructor(searchConfig) { |
| 71 /** | 352 this._searchConfig = searchConfig; |
| 72 * @param {string} queryCandidate | 353 this.element = createElement('div'); |
| 73 */ | 354 } |
| 74 _toggle: function(queryCandidate) | 355 |
| 75 { | 356 /** |
| 76 if (queryCandidate) | 357 * @return {!WebInspector.ProjectSearchConfig} |
| 77 this._search.value = queryCandidate; | 358 */ |
| 78 | 359 get searchConfig() { |
| 79 if (this.isShowing()) | 360 return this._searchConfig; |
| 80 this.focus(); | 361 } |
| 81 else | 362 |
| 82 this._focusOnShow = true; | 363 /** |
| 83 | 364 * @param {!WebInspector.FileBasedSearchResult} searchResult |
| 84 this._startIndexing(); | 365 */ |
| 85 }, | 366 addSearchResult(searchResult) { |
| 86 | 367 } |
| 87 wasShown: function() | |
| 88 { | |
| 89 if (this._focusOnShow) { | |
| 90 this.focus(); | |
| 91 delete this._focusOnShow; | |
| 92 } | |
| 93 }, | |
| 94 | |
| 95 _onIndexingFinished: function() | |
| 96 { | |
| 97 var finished = !this._progressIndicator.isCanceled(); | |
| 98 this._progressIndicator.done(); | |
| 99 delete this._progressIndicator; | |
| 100 delete this._isIndexing; | |
| 101 this._indexingFinished(finished); | |
| 102 if (!finished) | |
| 103 delete this._pendingSearchConfig; | |
| 104 if (!this._pendingSearchConfig) | |
| 105 return; | |
| 106 var searchConfig = this._pendingSearchConfig; | |
| 107 delete this._pendingSearchConfig; | |
| 108 this._innerStartSearch(searchConfig); | |
| 109 }, | |
| 110 | |
| 111 _startIndexing: function() | |
| 112 { | |
| 113 this._isIndexing = true; | |
| 114 if (this._progressIndicator) | |
| 115 this._progressIndicator.done(); | |
| 116 this._progressIndicator = new WebInspector.ProgressIndicator(); | |
| 117 this._searchMessageElement.textContent = WebInspector.UIString("Indexing
\u2026"); | |
| 118 this._progressIndicator.show(this._searchProgressPlaceholderElement); | |
| 119 this._searchScope.performIndexing(new WebInspector.ProgressProxy(this._p
rogressIndicator, this._onIndexingFinished.bind(this))); | |
| 120 }, | |
| 121 | |
| 122 _onSearchInputClear: function() | |
| 123 { | |
| 124 this._search.value = ""; | |
| 125 this.focus(); | |
| 126 this._searchInputClearElement.hidden = true; | |
| 127 }, | |
| 128 | |
| 129 /** | |
| 130 * @param {number} searchId | |
| 131 * @param {!WebInspector.FileBasedSearchResult} searchResult | |
| 132 */ | |
| 133 _onSearchResult: function(searchId, searchResult) | |
| 134 { | |
| 135 if (searchId !== this._searchId || !this._progressIndicator) | |
| 136 return; | |
| 137 if (this._progressIndicator && this._progressIndicator.isCanceled()) { | |
| 138 this._onIndexingFinished(); | |
| 139 return; | |
| 140 } | |
| 141 this._addSearchResult(searchResult); | |
| 142 if (!searchResult.searchMatches.length) | |
| 143 return; | |
| 144 if (!this._searchResultsPane) | |
| 145 this._searchResultsPane = this._searchScope.createSearchResultsPane(
this._searchConfig); | |
| 146 this._resetResults(); | |
| 147 this._searchResultsElement.appendChild(this._searchResultsPane.element); | |
| 148 this._searchResultsPane.addSearchResult(searchResult); | |
| 149 }, | |
| 150 | |
| 151 /** | |
| 152 * @param {number} searchId | |
| 153 * @param {boolean} finished | |
| 154 */ | |
| 155 _onSearchFinished: function(searchId, finished) | |
| 156 { | |
| 157 if (searchId !== this._searchId || !this._progressIndicator) | |
| 158 return; | |
| 159 if (!this._searchResultsPane) | |
| 160 this._nothingFound(); | |
| 161 this._searchFinished(finished); | |
| 162 delete this._searchConfig; | |
| 163 }, | |
| 164 | |
| 165 /** | |
| 166 * @param {!WebInspector.SearchConfig} searchConfig | |
| 167 */ | |
| 168 _startSearch: function(searchConfig) | |
| 169 { | |
| 170 this._resetSearch(); | |
| 171 ++this._searchId; | |
| 172 if (!this._isIndexing) | |
| 173 this._startIndexing(); | |
| 174 this._pendingSearchConfig = searchConfig; | |
| 175 }, | |
| 176 | |
| 177 /** | |
| 178 * @param {!WebInspector.SearchConfig} searchConfig | |
| 179 */ | |
| 180 _innerStartSearch: function(searchConfig) | |
| 181 { | |
| 182 this._searchConfig = searchConfig; | |
| 183 if (this._progressIndicator) | |
| 184 this._progressIndicator.done(); | |
| 185 this._progressIndicator = new WebInspector.ProgressIndicator(); | |
| 186 this._searchStarted(this._progressIndicator); | |
| 187 this._searchScope.performSearch(searchConfig, this._progressIndicator, t
his._onSearchResult.bind(this, this._searchId), this._onSearchFinished.bind(this
, this._searchId)); | |
| 188 }, | |
| 189 | |
| 190 _resetSearch: function() | |
| 191 { | |
| 192 this._stopSearch(); | |
| 193 | |
| 194 if (this._searchResultsPane) { | |
| 195 this._resetResults(); | |
| 196 delete this._searchResultsPane; | |
| 197 } | |
| 198 }, | |
| 199 | |
| 200 _stopSearch: function() | |
| 201 { | |
| 202 if (this._progressIndicator && !this._isIndexing) | |
| 203 this._progressIndicator.cancel(); | |
| 204 if (this._searchScope) | |
| 205 this._searchScope.stopSearch(); | |
| 206 delete this._searchConfig; | |
| 207 }, | |
| 208 | |
| 209 /** | |
| 210 * @param {!WebInspector.ProgressIndicator} progressIndicator | |
| 211 */ | |
| 212 _searchStarted: function(progressIndicator) | |
| 213 { | |
| 214 this._resetResults(); | |
| 215 this._resetCounters(); | |
| 216 | |
| 217 this._searchMessageElement.textContent = WebInspector.UIString("Searchin
g\u2026"); | |
| 218 progressIndicator.show(this._searchProgressPlaceholderElement); | |
| 219 this._updateSearchResultsMessage(); | |
| 220 | |
| 221 if (!this._searchingView) | |
| 222 this._searchingView = new WebInspector.EmptyWidget(WebInspector.UISt
ring("Searching\u2026")); | |
| 223 this._searchingView.show(this._searchResultsElement); | |
| 224 }, | |
| 225 | |
| 226 /** | |
| 227 * @param {boolean} finished | |
| 228 */ | |
| 229 _indexingFinished: function(finished) | |
| 230 { | |
| 231 this._searchMessageElement.textContent = finished ? "" : WebInspector.UI
String("Indexing interrupted."); | |
| 232 }, | |
| 233 | |
| 234 _updateSearchResultsMessage: function() | |
| 235 { | |
| 236 if (this._searchMatchesCount && this._searchResultsCount) | |
| 237 this._searchResultsMessageElement.textContent = WebInspector.UIStrin
g("Found %d matches in %d files.", this._searchMatchesCount, this._nonEmptySearc
hResultsCount); | |
| 238 else | |
| 239 this._searchResultsMessageElement.textContent = ""; | |
| 240 }, | |
| 241 | |
| 242 _resetResults: function() | |
| 243 { | |
| 244 if (this._searchingView) | |
| 245 this._searchingView.detach(); | |
| 246 if (this._notFoundView) | |
| 247 this._notFoundView.detach(); | |
| 248 this._searchResultsElement.removeChildren(); | |
| 249 }, | |
| 250 | |
| 251 _resetCounters: function() | |
| 252 { | |
| 253 this._searchMatchesCount = 0; | |
| 254 this._searchResultsCount = 0; | |
| 255 this._nonEmptySearchResultsCount = 0; | |
| 256 }, | |
| 257 | |
| 258 _nothingFound: function() | |
| 259 { | |
| 260 this._resetResults(); | |
| 261 | |
| 262 if (!this._notFoundView) | |
| 263 this._notFoundView = new WebInspector.EmptyWidget(WebInspector.UIStr
ing("No matches found.")); | |
| 264 this._notFoundView.show(this._searchResultsElement); | |
| 265 this._searchResultsMessageElement.textContent = WebInspector.UIString("N
o matches found."); | |
| 266 }, | |
| 267 | |
| 268 /** | |
| 269 * @param {!WebInspector.FileBasedSearchResult} searchResult | |
| 270 */ | |
| 271 _addSearchResult: function(searchResult) | |
| 272 { | |
| 273 this._searchMatchesCount += searchResult.searchMatches.length; | |
| 274 this._searchResultsCount++; | |
| 275 if (searchResult.searchMatches.length) | |
| 276 this._nonEmptySearchResultsCount++; | |
| 277 this._updateSearchResultsMessage(); | |
| 278 }, | |
| 279 | |
| 280 /** | |
| 281 * @param {boolean} finished | |
| 282 */ | |
| 283 _searchFinished: function(finished) | |
| 284 { | |
| 285 this._searchMessageElement.textContent = finished ? WebInspector.UIStrin
g("Search finished.") : WebInspector.UIString("Search interrupted."); | |
| 286 }, | |
| 287 | |
| 288 focus: function() | |
| 289 { | |
| 290 this._search.focus(); | |
| 291 this._search.select(); | |
| 292 }, | |
| 293 | |
| 294 willHide: function() | |
| 295 { | |
| 296 this._stopSearch(); | |
| 297 }, | |
| 298 | |
| 299 /** | |
| 300 * @param {!Event} event | |
| 301 */ | |
| 302 _onKeyDown: function(event) | |
| 303 { | |
| 304 switch (event.keyCode) { | |
| 305 case WebInspector.KeyboardShortcut.Keys.Enter.code: | |
| 306 this._onAction(); | |
| 307 break; | |
| 308 } | |
| 309 }, | |
| 310 | |
| 311 _onInput: function() | |
| 312 { | |
| 313 if (this._search.value && this._search.value.length) | |
| 314 this._searchInputClearElement.hidden = false; | |
| 315 else | |
| 316 this._searchInputClearElement.hidden = true; | |
| 317 }, | |
| 318 | |
| 319 _save: function() | |
| 320 { | |
| 321 this._advancedSearchConfig.set(this._buildSearchConfig().toPlainObject()
); | |
| 322 }, | |
| 323 | |
| 324 _load: function() | |
| 325 { | |
| 326 var searchConfig = WebInspector.SearchConfig.fromPlainObject(this._advan
cedSearchConfig.get()); | |
| 327 this._search.value = searchConfig.query(); | |
| 328 this._ignoreCaseCheckbox.checked = searchConfig.ignoreCase(); | |
| 329 this._regexCheckbox.checked = searchConfig.isRegex(); | |
| 330 if (this._search.value && this._search.value.length) | |
| 331 this._searchInputClearElement.hidden = false; | |
| 332 }, | |
| 333 | |
| 334 _onAction: function() | |
| 335 { | |
| 336 var searchConfig = this._buildSearchConfig(); | |
| 337 if (!searchConfig.query() || !searchConfig.query().length) | |
| 338 return; | |
| 339 | |
| 340 this._save(); | |
| 341 this._startSearch(searchConfig); | |
| 342 }, | |
| 343 | |
| 344 __proto__: WebInspector.VBox.prototype | |
| 345 }; | 368 }; |
| 346 | 369 |
| 347 /** | 370 /** |
| 348 * @param {string} query | 371 * @implements {WebInspector.ActionDelegate} |
| 349 * @param {string=} filePath | 372 * @unrestricted |
| 350 */ | 373 */ |
| 351 WebInspector.AdvancedSearchView.openSearch = function(query, filePath) | 374 WebInspector.AdvancedSearchView.ActionDelegate = class { |
| 352 { | 375 /** |
| 353 WebInspector.viewManager.showView("sources.search"); | 376 * @override |
| 354 var searchView = /** @type {!WebInspector.AdvancedSearchView} */ (self.runti
me.sharedInstance(WebInspector.AdvancedSearchView)); | 377 * @param {!WebInspector.Context} context |
| 355 var fileMask = filePath ? " file:" + filePath : ""; | 378 * @param {string} actionId |
| 356 searchView._toggle(query + fileMask); | 379 * @return {boolean} |
| 380 */ |
| 381 handleAction(context, actionId) { |
| 382 this._showSearch(); |
| 383 return true; |
| 384 } |
| 385 |
| 386 _showSearch() { |
| 387 var selection = WebInspector.inspectorView.element.getDeepSelection(); |
| 388 var queryCandidate = ''; |
| 389 if (selection.rangeCount) |
| 390 queryCandidate = selection.toString().replace(/\r?\n.*/, ''); |
| 391 WebInspector.AdvancedSearchView.openSearch(queryCandidate); |
| 392 } |
| 357 }; | 393 }; |
| 358 | 394 |
| 359 /** | 395 /** |
| 360 * @constructor | 396 * @unrestricted |
| 361 * @param {!WebInspector.ProjectSearchConfig} searchConfig | |
| 362 */ | 397 */ |
| 363 WebInspector.SearchResultsPane = function(searchConfig) | 398 WebInspector.FileBasedSearchResult = class { |
| 364 { | 399 /** |
| 365 this._searchConfig = searchConfig; | 400 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 366 this.element = createElement("div"); | 401 * @param {!Array.<!Object>} searchMatches |
| 367 }; | 402 */ |
| 368 | 403 constructor(uiSourceCode, searchMatches) { |
| 369 WebInspector.SearchResultsPane.prototype = { | |
| 370 /** | |
| 371 * @return {!WebInspector.ProjectSearchConfig} | |
| 372 */ | |
| 373 get searchConfig() | |
| 374 { | |
| 375 return this._searchConfig; | |
| 376 }, | |
| 377 | |
| 378 /** | |
| 379 * @param {!WebInspector.FileBasedSearchResult} searchResult | |
| 380 */ | |
| 381 addSearchResult: function(searchResult) { } | |
| 382 }; | |
| 383 | |
| 384 /** | |
| 385 * @constructor | |
| 386 * @implements {WebInspector.ActionDelegate} | |
| 387 */ | |
| 388 WebInspector.AdvancedSearchView.ActionDelegate = function() | |
| 389 { | |
| 390 }; | |
| 391 | |
| 392 WebInspector.AdvancedSearchView.ActionDelegate.prototype = { | |
| 393 /** | |
| 394 * @override | |
| 395 * @param {!WebInspector.Context} context | |
| 396 * @param {string} actionId | |
| 397 * @return {boolean} | |
| 398 */ | |
| 399 handleAction: function(context, actionId) | |
| 400 { | |
| 401 this._showSearch(); | |
| 402 return true; | |
| 403 }, | |
| 404 | |
| 405 _showSearch: function() | |
| 406 { | |
| 407 var selection = WebInspector.inspectorView.element.getDeepSelection(); | |
| 408 var queryCandidate = ""; | |
| 409 if (selection.rangeCount) | |
| 410 queryCandidate = selection.toString().replace(/\r?\n.*/, ""); | |
| 411 WebInspector.AdvancedSearchView.openSearch(queryCandidate); | |
| 412 }, | |
| 413 }; | |
| 414 | |
| 415 /** | |
| 416 * @constructor | |
| 417 * @param {!WebInspector.UISourceCode} uiSourceCode | |
| 418 * @param {!Array.<!Object>} searchMatches | |
| 419 */ | |
| 420 WebInspector.FileBasedSearchResult = function(uiSourceCode, searchMatches) { | |
| 421 this.uiSourceCode = uiSourceCode; | 404 this.uiSourceCode = uiSourceCode; |
| 422 this.searchMatches = searchMatches; | 405 this.searchMatches = searchMatches; |
| 406 } |
| 423 }; | 407 }; |
| 424 | 408 |
| 425 /** | 409 /** |
| 426 * @interface | 410 * @interface |
| 427 */ | 411 */ |
| 428 WebInspector.SearchScope = function() | 412 WebInspector.SearchScope = function() {}; |
| 429 { | 413 |
| 414 WebInspector.SearchScope.prototype = { |
| 415 /** |
| 416 * @param {!WebInspector.SearchConfig} searchConfig |
| 417 * @param {!WebInspector.Progress} progress |
| 418 * @param {function(!WebInspector.FileBasedSearchResult)} searchResultCallback |
| 419 * @param {function(boolean)} searchFinishedCallback |
| 420 */ |
| 421 performSearch: function(searchConfig, progress, searchResultCallback, searchFi
nishedCallback) {}, |
| 422 |
| 423 /** |
| 424 * @param {!WebInspector.Progress} progress |
| 425 */ |
| 426 performIndexing: function(progress) {}, |
| 427 |
| 428 stopSearch: function() {}, |
| 429 |
| 430 /** |
| 431 * @param {!WebInspector.ProjectSearchConfig} searchConfig |
| 432 * @return {!WebInspector.SearchResultsPane} |
| 433 */ |
| 434 createSearchResultsPane: function(searchConfig) {} |
| 430 }; | 435 }; |
| 431 | |
| 432 WebInspector.SearchScope.prototype = { | |
| 433 /** | |
| 434 * @param {!WebInspector.SearchConfig} searchConfig | |
| 435 * @param {!WebInspector.Progress} progress | |
| 436 * @param {function(!WebInspector.FileBasedSearchResult)} searchResultCallba
ck | |
| 437 * @param {function(boolean)} searchFinishedCallback | |
| 438 */ | |
| 439 performSearch: function(searchConfig, progress, searchResultCallback, search
FinishedCallback) { }, | |
| 440 | |
| 441 /** | |
| 442 * @param {!WebInspector.Progress} progress | |
| 443 */ | |
| 444 performIndexing: function(progress) { }, | |
| 445 | |
| 446 stopSearch: function() { }, | |
| 447 | |
| 448 /** | |
| 449 * @param {!WebInspector.ProjectSearchConfig} searchConfig | |
| 450 * @return {!WebInspector.SearchResultsPane} | |
| 451 */ | |
| 452 createSearchResultsPane: function(searchConfig) { } | |
| 453 }; | |
| OLD | NEW |