| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 /** | |
| 32 * @constructor | |
| 33 * @implements {WebInspector.ProjectDelegate} | |
| 34 * @param {!WebInspector.Workspace} workspace | |
| 35 * @param {string} id | |
| 36 * @param {!WebInspector.projectTypes} type | |
| 37 */ | |
| 38 WebInspector.ContentProviderBasedProjectDelegate = function(workspace, id, type) | |
| 39 { | |
| 40 this._type = type; | |
| 41 /** @type {!Object.<string, !WebInspector.ContentProvider>} */ | |
| 42 this._contentProviders = {}; | |
| 43 this._workspace = workspace; | |
| 44 this._id = id; | |
| 45 this._projectStore = workspace.addProject(id, this); | |
| 46 } | |
| 47 | |
| 48 WebInspector.ContentProviderBasedProjectDelegate.prototype = { | |
| 49 /** | |
| 50 * @return {string} | |
| 51 */ | |
| 52 type: function() | |
| 53 { | |
| 54 return this._type; | |
| 55 }, | |
| 56 | |
| 57 /** | |
| 58 * @return {string} | |
| 59 */ | |
| 60 displayName: function() | |
| 61 { | |
| 62 // Overriddden by subclasses | |
| 63 return ""; | |
| 64 }, | |
| 65 | |
| 66 /** | |
| 67 * @param {string} path | |
| 68 * @param {function(?Date, ?number)} callback | |
| 69 */ | |
| 70 requestMetadata: function(path, callback) | |
| 71 { | |
| 72 callback(null, null); | |
| 73 }, | |
| 74 | |
| 75 /** | |
| 76 * @param {string} path | |
| 77 * @param {function(?string)} callback | |
| 78 */ | |
| 79 requestFileContent: function(path, callback) | |
| 80 { | |
| 81 var contentProvider = this._contentProviders[path]; | |
| 82 contentProvider.requestContent(callback); | |
| 83 | |
| 84 /** | |
| 85 * @param {?string} content | |
| 86 * @param {boolean} encoded | |
| 87 * @param {string} mimeType | |
| 88 */ | |
| 89 function innerCallback(content, encoded, mimeType) | |
| 90 { | |
| 91 callback(content); | |
| 92 } | |
| 93 }, | |
| 94 | |
| 95 /** | |
| 96 * @return {boolean} | |
| 97 */ | |
| 98 canSetFileContent: function() | |
| 99 { | |
| 100 return false; | |
| 101 }, | |
| 102 | |
| 103 /** | |
| 104 * @param {string} path | |
| 105 * @param {string} newContent | |
| 106 * @param {function(?string)} callback | |
| 107 */ | |
| 108 setFileContent: function(path, newContent, callback) | |
| 109 { | |
| 110 callback(null); | |
| 111 }, | |
| 112 | |
| 113 /** | |
| 114 * @return {boolean} | |
| 115 */ | |
| 116 canRename: function() | |
| 117 { | |
| 118 return false; | |
| 119 }, | |
| 120 | |
| 121 /** | |
| 122 * @param {string} path | |
| 123 * @param {string} newName | |
| 124 * @param {function(boolean, string=, string=, string=, !WebInspector.Resour
ceType=)} callback | |
| 125 */ | |
| 126 rename: function(path, newName, callback) | |
| 127 { | |
| 128 this.performRename(path, newName, innerCallback.bind(this)); | |
| 129 | |
| 130 /** | |
| 131 * @param {boolean} success | |
| 132 * @param {string=} newName | |
| 133 * @this {WebInspector.ContentProviderBasedProjectDelegate} | |
| 134 */ | |
| 135 function innerCallback(success, newName) | |
| 136 { | |
| 137 if (success) | |
| 138 this._updateName(path, /** @type {string} */ (newName)); | |
| 139 callback(success, newName); | |
| 140 } | |
| 141 }, | |
| 142 | |
| 143 /** | |
| 144 * @param {string} path | |
| 145 * @param {function()=} callback | |
| 146 */ | |
| 147 refresh: function(path, callback) | |
| 148 { | |
| 149 if (callback) | |
| 150 callback(); | |
| 151 }, | |
| 152 | |
| 153 /** | |
| 154 * @param {string} path | |
| 155 */ | |
| 156 excludeFolder: function(path) | |
| 157 { | |
| 158 }, | |
| 159 | |
| 160 /** | |
| 161 * @param {string} path | |
| 162 * @param {?string} name | |
| 163 * @param {string} content | |
| 164 * @param {function(?string)} callback | |
| 165 */ | |
| 166 createFile: function(path, name, content, callback) | |
| 167 { | |
| 168 }, | |
| 169 | |
| 170 /** | |
| 171 * @param {string} path | |
| 172 */ | |
| 173 deleteFile: function(path) | |
| 174 { | |
| 175 }, | |
| 176 | |
| 177 remove: function() | |
| 178 { | |
| 179 }, | |
| 180 | |
| 181 /** | |
| 182 * @param {string} path | |
| 183 * @param {string} newName | |
| 184 * @param {function(boolean, string=)} callback | |
| 185 */ | |
| 186 performRename: function(path, newName, callback) | |
| 187 { | |
| 188 callback(false); | |
| 189 }, | |
| 190 | |
| 191 /** | |
| 192 * @param {string} path | |
| 193 * @param {string} newName | |
| 194 */ | |
| 195 _updateName: function(path, newName) | |
| 196 { | |
| 197 var oldPath = path; | |
| 198 var copyOfPath = path.split("/"); | |
| 199 copyOfPath[copyOfPath.length - 1] = newName; | |
| 200 var newPath = copyOfPath.join("/"); | |
| 201 this._contentProviders[newPath] = this._contentProviders[oldPath]; | |
| 202 delete this._contentProviders[oldPath]; | |
| 203 }, | |
| 204 | |
| 205 /** | |
| 206 * @param {string} path | |
| 207 * @param {string} query | |
| 208 * @param {boolean} caseSensitive | |
| 209 * @param {boolean} isRegex | |
| 210 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} cal
lback | |
| 211 */ | |
| 212 searchInFileContent: function(path, query, caseSensitive, isRegex, callback) | |
| 213 { | |
| 214 var contentProvider = this._contentProviders[path]; | |
| 215 contentProvider.searchInContent(query, caseSensitive, isRegex, callback)
; | |
| 216 }, | |
| 217 | |
| 218 /** | |
| 219 * @param {!WebInspector.ProjectSearchConfig} searchConfig | |
| 220 * @param {!Array.<string>} filesMathingFileQuery | |
| 221 * @param {!WebInspector.Progress} progress | |
| 222 * @param {function(!Array.<string>)} callback | |
| 223 */ | |
| 224 findFilesMatchingSearchRequest: function(searchConfig, filesMathingFileQuery
, progress, callback) | |
| 225 { | |
| 226 var result = []; | |
| 227 var paths = filesMathingFileQuery; | |
| 228 var totalCount = paths.length; | |
| 229 if (totalCount === 0) { | |
| 230 // searchInContent should call back later. | |
| 231 setTimeout(doneCallback, 0); | |
| 232 return; | |
| 233 } | |
| 234 | |
| 235 var barrier = new CallbackBarrier(); | |
| 236 progress.setTotalWork(paths.length); | |
| 237 for (var i = 0; i < paths.length; ++i) | |
| 238 searchInContent.call(this, paths[i], barrier.createCallback(searchIn
ContentCallback.bind(null, paths[i]))); | |
| 239 barrier.callWhenDone(doneCallback); | |
| 240 | |
| 241 /** | |
| 242 * @param {string} path | |
| 243 * @param {function(boolean)} callback | |
| 244 * @this {WebInspector.ContentProviderBasedProjectDelegate} | |
| 245 */ | |
| 246 function searchInContent(path, callback) | |
| 247 { | |
| 248 var queriesToRun = searchConfig.queries().slice(); | |
| 249 searchNextQuery.call(this); | |
| 250 | |
| 251 /** | |
| 252 * @this {WebInspector.ContentProviderBasedProjectDelegate} | |
| 253 */ | |
| 254 function searchNextQuery() | |
| 255 { | |
| 256 if (!queriesToRun.length) { | |
| 257 callback(true); | |
| 258 return; | |
| 259 } | |
| 260 var query = queriesToRun.shift(); | |
| 261 this._contentProviders[path].searchInContent(query, !searchConfi
g.ignoreCase(), searchConfig.isRegex(), contentCallback.bind(this)); | |
| 262 } | |
| 263 | |
| 264 /** | |
| 265 * @param {!Array.<!WebInspector.ContentProvider.SearchMatch>} searc
hMatches | |
| 266 * @this {WebInspector.ContentProviderBasedProjectDelegate} | |
| 267 */ | |
| 268 function contentCallback(searchMatches) | |
| 269 { | |
| 270 if (!searchMatches.length) { | |
| 271 callback(false); | |
| 272 return; | |
| 273 } | |
| 274 searchNextQuery.call(this); | |
| 275 } | |
| 276 } | |
| 277 | |
| 278 /** | |
| 279 * @param {string} path | |
| 280 * @param {boolean} matches | |
| 281 */ | |
| 282 function searchInContentCallback(path, matches) | |
| 283 { | |
| 284 if (matches) | |
| 285 result.push(path); | |
| 286 progress.worked(1); | |
| 287 } | |
| 288 | |
| 289 function doneCallback() | |
| 290 { | |
| 291 callback(result); | |
| 292 progress.done(); | |
| 293 } | |
| 294 }, | |
| 295 | |
| 296 /** | |
| 297 * @param {!WebInspector.Progress} progress | |
| 298 */ | |
| 299 indexContent: function(progress) | |
| 300 { | |
| 301 setTimeout(progress.done.bind(progress), 0); | |
| 302 }, | |
| 303 | |
| 304 /** | |
| 305 * @param {string} parentPath | |
| 306 * @param {string} name | |
| 307 * @param {string} url | |
| 308 * @param {!WebInspector.ContentProvider} contentProvider | |
| 309 * @return {string} | |
| 310 */ | |
| 311 addContentProvider: function(parentPath, name, url, contentProvider) | |
| 312 { | |
| 313 var path = parentPath ? parentPath + "/" + name : name; | |
| 314 if (this._contentProviders[path]) | |
| 315 return path; | |
| 316 var fileDescriptor = new WebInspector.FileDescriptor(parentPath, name, u
rl, url, contentProvider.contentType()); | |
| 317 this._contentProviders[path] = contentProvider; | |
| 318 this._projectStore.addFile(fileDescriptor); | |
| 319 return path; | |
| 320 }, | |
| 321 | |
| 322 /** | |
| 323 * @param {string} path | |
| 324 */ | |
| 325 removeFile: function(path) | |
| 326 { | |
| 327 delete this._contentProviders[path]; | |
| 328 this._projectStore.removeFile(path); | |
| 329 }, | |
| 330 | |
| 331 /** | |
| 332 * @return {!Object.<string, !WebInspector.ContentProvider>} | |
| 333 */ | |
| 334 contentProviders: function() | |
| 335 { | |
| 336 return this._contentProviders; | |
| 337 }, | |
| 338 | |
| 339 reset: function() | |
| 340 { | |
| 341 this._contentProviders = {}; | |
| 342 this._workspace.removeProject(this._id); | |
| 343 this._projectStore = this._workspace.addProject(this._id, this); | |
| 344 } | |
| 345 } | |
| OLD | NEW |