OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * | 10 * |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 this._searchPanelElement = this.element.createChild("div"); | 144 this._searchPanelElement = this.element.createChild("div"); |
145 this._searchPanelElement.tabIndex = 0; | 145 this._searchPanelElement.tabIndex = 0; |
146 this._searchPanelElement.className = "search-panel"; | 146 this._searchPanelElement.className = "search-panel"; |
147 this._searchPanelElement.addEventListener("keydown", this._onKeyDown.bind(th
is), false); | 147 this._searchPanelElement.addEventListener("keydown", this._onKeyDown.bind(th
is), false); |
148 | 148 |
149 this._searchResultsElement = this.element.createChild("div"); | 149 this._searchResultsElement = this.element.createChild("div"); |
150 this._searchResultsElement.className = "search-results"; | 150 this._searchResultsElement.className = "search-results"; |
151 | 151 |
152 this._search = this._searchPanelElement.createChild("input"); | 152 this._search = this._searchPanelElement.createChild("input"); |
153 this._search.setAttribute("type", "search"); | 153 this._search.setAttribute("type", "search"); |
| 154 this._search.addStyleClass("search-config-search"); |
154 this._search.setAttribute("results", "0"); | 155 this._search.setAttribute("results", "0"); |
155 this._search.setAttribute("size", 20); | 156 this._search.setAttribute("size", 20); |
156 | 157 |
| 158 this._ignoreCaseLabel = this._searchPanelElement.createChild("label"); |
| 159 this._ignoreCaseLabel.addStyleClass("search-config-label"); |
| 160 this._ignoreCaseCheckbox = this._ignoreCaseLabel.createChild("input"); |
| 161 this._ignoreCaseCheckbox.setAttribute("type", "checkbox"); |
| 162 this._ignoreCaseCheckbox.addStyleClass("search-config-checkbox"); |
| 163 this._ignoreCaseLabel.appendChild(document.createTextNode(WebInspector.UIStr
ing("Ignore case"))); |
| 164 |
| 165 |
| 166 this._regexLabel = this._searchPanelElement.createChild("label"); |
| 167 this._regexLabel.addStyleClass("search-config-label"); |
| 168 this._regexCheckbox = this._regexLabel.createChild("input"); |
| 169 this._regexCheckbox.setAttribute("type", "checkbox"); |
| 170 this._regexCheckbox.addStyleClass("search-config-checkbox"); |
| 171 this._regexLabel.appendChild(document.createTextNode(WebInspector.UIString("
Regular expression"))); |
| 172 |
157 this._load(); | 173 this._load(); |
158 } | 174 } |
159 | 175 |
160 // Number of recent search queries to store. | 176 // Number of recent search queries to store. |
161 WebInspector.SearchView.maxQueriesCount = 20; | 177 WebInspector.SearchView.maxQueriesCount = 20; |
162 | 178 |
163 WebInspector.SearchView.prototype = { | 179 WebInspector.SearchView.prototype = { |
164 /** | 180 /** |
165 * @type {WebInspector.SearchConfig} | 181 * @type {WebInspector.SearchConfig} |
166 */ | 182 */ |
167 get searchConfig() | 183 get searchConfig() |
168 { | 184 { |
169 var searchConfig = {}; | 185 var searchConfig = {}; |
170 searchConfig.query = this._search.value; | 186 searchConfig.query = this._search.value; |
| 187 searchConfig.ignoreCase = this._ignoreCaseCheckbox.checked; |
| 188 searchConfig.isRegex = this._regexCheckbox.checked; |
171 return searchConfig; | 189 return searchConfig; |
172 }, | 190 }, |
173 | 191 |
174 /** | 192 /** |
175 * @type {WebInspector.SearchResultsPane} | 193 * @type {WebInspector.SearchResultsPane} |
176 */ | 194 */ |
177 set resultsPane(resultsPane) | 195 set resultsPane(resultsPane) |
178 { | 196 { |
179 this._searchResultsElement.removeChildren(); | 197 this._searchResultsElement.removeChildren(); |
180 this._searchResultsElement.appendChild(resultsPane.element); | 198 this._searchResultsElement.appendChild(resultsPane.element); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 _save: function() | 247 _save: function() |
230 { | 248 { |
231 var searchConfig = new WebInspector.SearchConfig(this.searchConfig.query
, this.searchConfig.ignoreCase, this.searchConfig.isRegex); | 249 var searchConfig = new WebInspector.SearchConfig(this.searchConfig.query
, this.searchConfig.ignoreCase, this.searchConfig.isRegex); |
232 WebInspector.settings.advancedSearchConfig.set(searchConfig); | 250 WebInspector.settings.advancedSearchConfig.set(searchConfig); |
233 }, | 251 }, |
234 | 252 |
235 _load: function() | 253 _load: function() |
236 { | 254 { |
237 var searchConfig = WebInspector.settings.advancedSearchConfig.get(); | 255 var searchConfig = WebInspector.settings.advancedSearchConfig.get(); |
238 this._search.value = searchConfig.query; | 256 this._search.value = searchConfig.query; |
| 257 this._ignoreCaseCheckbox.checked = searchConfig.ignoreCase; |
| 258 this._regexCheckbox.checked = searchConfig.isRegex; |
239 }, | 259 }, |
240 | 260 |
241 _onAction: function() | 261 _onAction: function() |
242 { | 262 { |
243 this._save(); | 263 this._save(); |
244 this._controller.startSearch(this.searchConfig); | 264 this._controller.startSearch(this.searchConfig); |
245 } | 265 } |
246 } | 266 } |
247 | 267 |
248 WebInspector.SearchView.prototype.__proto__ = WebInspector.View.prototype; | 268 WebInspector.SearchView.prototype.__proto__ = WebInspector.View.prototype; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 */ | 353 */ |
334 createAnchor: function(file, lineNumber) { }, | 354 createAnchor: function(file, lineNumber) { }, |
335 | 355 |
336 /** | 356 /** |
337 * @param {Object} file | 357 * @param {Object} file |
338 * @return {string} | 358 * @return {string} |
339 */ | 359 */ |
340 fileName: function(file) { }, | 360 fileName: function(file) { }, |
341 | 361 |
342 /** | 362 /** |
| 363 * @return {RegExp} |
| 364 */ |
| 365 _createSearchRegex: function() |
| 366 { |
| 367 var regexFlags = this._searchConfig.ignoreCase ? "gi" : "g"; |
| 368 var regexObject; |
| 369 try { |
| 370 regexObject = new RegExp(this._searchConfig.query, regexFlags); |
| 371 } catch (e) { |
| 372 // Silent catch. |
| 373 } |
| 374 |
| 375 if (!regexObject) |
| 376 regexObject = createSearchRegex(this._searchConfig.query, regexFlags
); |
| 377 |
| 378 return regexObject; |
| 379 }, |
| 380 |
| 381 /** |
343 * @param {Object} searchResult | 382 * @param {Object} searchResult |
344 */ | 383 */ |
345 addSearchResult: function(searchResult) | 384 addSearchResult: function(searchResult) |
346 { | 385 { |
347 this._searchResults.push(searchResult); | 386 this._searchResults.push(searchResult); |
348 var file = searchResult.file; | 387 var file = searchResult.file; |
349 var fileName = this.fileName(file); | 388 var fileName = this.fileName(file); |
350 var searchMatches = searchResult.searchMatches; | 389 var searchMatches = searchResult.searchMatches; |
351 | 390 |
352 // Expand first file with matches only. | 391 // Expand first file with matches only. |
353 var fileTreeElement = this._addFileTreeElement(fileName, searchMatches.l
ength, this._searchResults.length === 1); | 392 var fileTreeElement = this._addFileTreeElement(fileName, searchMatches.l
ength, this._searchResults.length === 1); |
354 | 393 |
355 var regexObject = createSearchRegex(this._searchConfig.query, "g"); | 394 var regexObject = this._createSearchRegex(); |
356 for (var i = 0; i < searchMatches.length; i++) { | 395 for (var i = 0; i < searchMatches.length; i++) { |
357 var lineNumber = searchMatches[i].lineNumber; | 396 var lineNumber = searchMatches[i].lineNumber; |
358 | 397 |
359 var anchor = this.createAnchor(file, lineNumber); | 398 var anchor = this.createAnchor(file, lineNumber); |
360 | 399 |
361 var numberString = numberToStringWithSpacesPadding(lineNumber + 1, 4
); | 400 var numberString = numberToStringWithSpacesPadding(lineNumber + 1, 4
); |
362 var lineNumberSpan = document.createElement("span"); | 401 var lineNumberSpan = document.createElement("span"); |
363 lineNumberSpan.addStyleClass("webkit-line-number"); | 402 lineNumberSpan.addStyleClass("webkit-line-number"); |
364 lineNumberSpan.addStyleClass("search-match-line-number"); | 403 lineNumberSpan.addStyleClass("search-match-line-number"); |
365 lineNumberSpan.textContent = numberString; | 404 lineNumberSpan.textContent = numberString; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 matchRanges.push({ offset: match.index, length: match[0].length }); | 464 matchRanges.push({ offset: match.index, length: match[0].length }); |
426 match = regexObject.exec(lineContent); | 465 match = regexObject.exec(lineContent); |
427 } | 466 } |
428 highlightRangesWithStyleClass(contentSpan, matchRanges, "highlighted-mat
ch"); | 467 highlightRangesWithStyleClass(contentSpan, matchRanges, "highlighted-mat
ch"); |
429 | 468 |
430 return contentSpan; | 469 return contentSpan; |
431 } | 470 } |
432 } | 471 } |
433 | 472 |
434 WebInspector.FileBasedSearchResultsPane.prototype.__proto__ = WebInspector.Searc
hResultsPane.prototype; | 473 WebInspector.FileBasedSearchResultsPane.prototype.__proto__ = WebInspector.Searc
hResultsPane.prototype; |
| 474 |
| 475 /** |
| 476 * @constructor |
| 477 * @param {Object} file |
| 478 * @param {Array.<Object>} searchMatches |
| 479 */ |
| 480 WebInspector.FileBasedSearchResultsPane.SearchResult = function(file, searchMatc
hes) { |
| 481 this.file = file; |
| 482 this.searchMatches = searchMatches; |
| 483 } |
OLD | NEW |