| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 var projects = this._projects(); | 105 var projects = this._projects(); |
| 106 var barrier = new CallbackBarrier(); | 106 var barrier = new CallbackBarrier(); |
| 107 var compositeProgress = new WebInspector.CompositeProgress(progress); | 107 var compositeProgress = new WebInspector.CompositeProgress(progress); |
| 108 for (var i = 0; i < projects.length; ++i) { | 108 for (var i = 0; i < projects.length; ++i) { |
| 109 var project = projects[i]; | 109 var project = projects[i]; |
| 110 var weight = project.uiSourceCodes().length; | 110 var weight = project.uiSourceCodes().length; |
| 111 var projectProgress = new WebInspector.CompositeProgress(compositePr
ogress.createSubProgress(weight)); | 111 var projectProgress = new WebInspector.CompositeProgress(compositePr
ogress.createSubProgress(weight)); |
| 112 var findMatchingFilesProgress = projectProgress.createSubProgress(); | 112 var findMatchingFilesProgress = projectProgress.createSubProgress(); |
| 113 var searchContentProgress = projectProgress.createSubProgress(); | 113 var searchContentProgress = projectProgress.createSubProgress(); |
| 114 var barrierCallback = barrier.createCallback(); | 114 var barrierCallback = barrier.createCallback(); |
| 115 var callback = this._processMatchingFilesForProject.bind(this, this.
_searchId, project, searchContentProgress, barrierCallback); | 115 var filesMathingFileQuery = this._projectFilesMatchingFileQuery(proj
ect, searchConfig); |
| 116 project.findFilesMatchingSearchRequest(searchConfig, findMatchingFil
esProgress, callback); | 116 var callback = this._processMatchingFilesForProject.bind(this, this.
_searchId, project, filesMathingFileQuery, searchContentProgress, barrierCallbac
k); |
| 117 project.findFilesMatchingSearchRequest(searchConfig, filesMathingFil
eQuery, findMatchingFilesProgress, callback); |
| 117 } | 118 } |
| 118 barrier.callWhenDone(this._searchFinishedCallback.bind(this, true)); | 119 barrier.callWhenDone(this._searchFinishedCallback.bind(this, true)); |
| 119 }, | 120 }, |
| 120 | 121 |
| 121 /** | 122 /** |
| 123 * @param {!WebInspector.Project} project |
| 124 * @param {!WebInspector.ProjectSearchConfig} searchConfig |
| 125 * @param {boolean=} dirtyOnly |
| 126 * @return {!Array.<string>} |
| 127 */ |
| 128 _projectFilesMatchingFileQuery: function(project, searchConfig, dirtyOnly) |
| 129 { |
| 130 var result = []; |
| 131 var uiSourceCodes = project.uiSourceCodes(); |
| 132 for (var i = 0; i < uiSourceCodes.length; ++i) { |
| 133 var uiSourceCode = uiSourceCodes[i]; |
| 134 if (dirtyOnly && !uiSourceCode.isDirty()) |
| 135 continue; |
| 136 if (this._searchConfig.filePathMatchesFileQuery(uiSourceCode.fullDis
playName())) |
| 137 result.push(uiSourceCode.path()); |
| 138 } |
| 139 result = result.sort(String.naturalOrderComparator); |
| 140 return result; |
| 141 }, |
| 142 |
| 143 /** |
| 122 * @param {number} searchId | 144 * @param {number} searchId |
| 123 * @param {!WebInspector.Project} project | 145 * @param {!WebInspector.Project} project |
| 146 * @param {!Array.<string>} filesMathingFileQuery |
| 124 * @param {!WebInspector.Progress} progress | 147 * @param {!WebInspector.Progress} progress |
| 125 * @param {function()} callback | 148 * @param {function()} callback |
| 126 * @param {!Array.<string>} files | 149 * @param {!Array.<string>} files |
| 127 */ | 150 */ |
| 128 _processMatchingFilesForProject: function(searchId, project, progress, callb
ack, files) | 151 _processMatchingFilesForProject: function(searchId, project, filesMathingFil
eQuery, progress, callback, files) |
| 129 { | 152 { |
| 130 if (searchId !== this._searchId) { | 153 if (searchId !== this._searchId) { |
| 131 this._searchFinishedCallback(false); | 154 this._searchFinishedCallback(false); |
| 132 return; | 155 return; |
| 133 } | 156 } |
| 134 | 157 |
| 135 addDirtyFiles.call(this); | 158 files = files.sort(String.naturalOrderComparator); |
| 159 files = files.intersectOrdered(filesMathingFileQuery, String.naturalOrde
rComparator); |
| 160 var dirtyFiles = this._projectFilesMatchingFileQuery(project, this._sear
chConfig, true); |
| 161 files = files.mergeOrdered(dirtyFiles); |
| 136 | 162 |
| 137 if (!files.length) { | 163 if (!files.length) { |
| 138 progress.done(); | 164 progress.done(); |
| 139 callback(); | 165 callback(); |
| 140 return; | 166 return; |
| 141 } | 167 } |
| 142 | 168 |
| 143 progress.setTotalWork(files.length); | 169 progress.setTotalWork(files.length); |
| 144 | 170 |
| 145 var fileIndex = 0; | 171 var fileIndex = 0; |
| 146 var maxFileContentRequests = 20; | 172 var maxFileContentRequests = 20; |
| 147 var callbacksLeft = 0; | 173 var callbacksLeft = 0; |
| 148 | 174 |
| 149 for (var i = 0; i < maxFileContentRequests && i < files.length; ++i) | 175 for (var i = 0; i < maxFileContentRequests && i < files.length; ++i) |
| 150 scheduleSearchInNextFileOrFinish.call(this); | 176 scheduleSearchInNextFileOrFinish.call(this); |
| 151 | 177 |
| 152 /** | 178 /** |
| 153 * @this {WebInspector.SourcesSearchScope} | |
| 154 */ | |
| 155 function addDirtyFiles() | |
| 156 { | |
| 157 var matchingFiles = StringSet.fromArray(files); | |
| 158 var uiSourceCodes = project.uiSourceCodes(); | |
| 159 for (var i = 0; i < uiSourceCodes.length; ++i) { | |
| 160 if (!uiSourceCodes[i].isDirty()) | |
| 161 continue; | |
| 162 var path = uiSourceCodes[i].path(); | |
| 163 if (!matchingFiles.contains(path) && this._searchConfig.filePath
MatchesFileQuery(path)) | |
| 164 files.push(path); | |
| 165 } | |
| 166 } | |
| 167 | |
| 168 /** | |
| 169 * @param {string} path | 179 * @param {string} path |
| 170 * @this {WebInspector.SourcesSearchScope} | 180 * @this {WebInspector.SourcesSearchScope} |
| 171 */ | 181 */ |
| 172 function searchInNextFile(path) | 182 function searchInNextFile(path) |
| 173 { | 183 { |
| 174 var uiSourceCode = project.uiSourceCode(path); | 184 var uiSourceCode = project.uiSourceCode(path); |
| 175 if (!uiSourceCode) { | 185 if (!uiSourceCode) { |
| 176 --callbacksLeft; | 186 --callbacksLeft; |
| 177 progress.worked(1); | 187 progress.worked(1); |
| 178 scheduleSearchInNextFileOrFinish.call(this); | 188 scheduleSearchInNextFileOrFinish.call(this); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 | 265 |
| 256 /** | 266 /** |
| 257 * @param {!WebInspector.ProjectSearchConfig} searchConfig | 267 * @param {!WebInspector.ProjectSearchConfig} searchConfig |
| 258 * @return {!WebInspector.FileBasedSearchResultsPane} | 268 * @return {!WebInspector.FileBasedSearchResultsPane} |
| 259 */ | 269 */ |
| 260 createSearchResultsPane: function(searchConfig) | 270 createSearchResultsPane: function(searchConfig) |
| 261 { | 271 { |
| 262 return new WebInspector.FileBasedSearchResultsPane(searchConfig); | 272 return new WebInspector.FileBasedSearchResultsPane(searchConfig); |
| 263 } | 273 } |
| 264 } | 274 } |
| OLD | NEW |