| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * @unrestricted | 32 * @unrestricted |
| 33 */ | 33 */ |
| 34 Bindings.FileSystemWorkspaceBinding = class { | 34 Persistence.FileSystemWorkspaceBinding = class { |
| 35 /** | 35 /** |
| 36 * @param {!Workspace.IsolatedFileSystemManager} isolatedFileSystemManager | 36 * @param {!Workspace.IsolatedFileSystemManager} isolatedFileSystemManager |
| 37 * @param {!Workspace.Workspace} workspace | 37 * @param {!Workspace.Workspace} workspace |
| 38 */ | 38 */ |
| 39 constructor(isolatedFileSystemManager, workspace) { | 39 constructor(isolatedFileSystemManager, workspace) { |
| 40 this._isolatedFileSystemManager = isolatedFileSystemManager; | 40 this._isolatedFileSystemManager = isolatedFileSystemManager; |
| 41 this._workspace = workspace; | 41 this._workspace = workspace; |
| 42 this._eventListeners = [ | 42 this._eventListeners = [ |
| 43 this._isolatedFileSystemManager.addEventListener( | 43 this._isolatedFileSystemManager.addEventListener( |
| 44 Workspace.IsolatedFileSystemManager.Events.FileSystemAdded, this._onFi
leSystemAdded, this), | 44 Workspace.IsolatedFileSystemManager.Events.FileSystemAdded, this._onFi
leSystemAdded, this), |
| 45 this._isolatedFileSystemManager.addEventListener( | 45 this._isolatedFileSystemManager.addEventListener( |
| 46 Workspace.IsolatedFileSystemManager.Events.FileSystemRemoved, this._on
FileSystemRemoved, this), | 46 Workspace.IsolatedFileSystemManager.Events.FileSystemRemoved, this._on
FileSystemRemoved, this), |
| 47 this._isolatedFileSystemManager.addEventListener( | 47 this._isolatedFileSystemManager.addEventListener( |
| 48 Workspace.IsolatedFileSystemManager.Events.FileSystemFilesChanged, thi
s._fileSystemFilesChanged, this) | 48 Workspace.IsolatedFileSystemManager.Events.FileSystemFilesChanged, thi
s._fileSystemFilesChanged, this) |
| 49 ]; | 49 ]; |
| 50 /** @type {!Map.<string, !Bindings.FileSystemWorkspaceBinding.FileSystem>} *
/ | 50 /** @type {!Map.<string, !Persistence.FileSystemWorkspaceBinding.FileSystem>
} */ |
| 51 this._boundFileSystems = new Map(); | 51 this._boundFileSystems = new Map(); |
| 52 this._isolatedFileSystemManager.waitForFileSystems().then(this._onFileSystem
sLoaded.bind(this)); | 52 this._isolatedFileSystemManager.waitForFileSystems().then(this._onFileSystem
sLoaded.bind(this)); |
| 53 } | 53 } |
| 54 | 54 |
| 55 /** | 55 /** |
| 56 * @param {string} fileSystemPath | 56 * @param {string} fileSystemPath |
| 57 * @return {string} | 57 * @return {string} |
| 58 */ | 58 */ |
| 59 static projectId(fileSystemPath) { | 59 static projectId(fileSystemPath) { |
| 60 return fileSystemPath; | 60 return fileSystemPath; |
| 61 } | 61 } |
| 62 | 62 |
| 63 /** | 63 /** |
| 64 * @param {!Workspace.UISourceCode} uiSourceCode | 64 * @param {!Workspace.UISourceCode} uiSourceCode |
| 65 * @return {!Array<string>} | 65 * @return {!Array<string>} |
| 66 */ | 66 */ |
| 67 static relativePath(uiSourceCode) { | 67 static relativePath(uiSourceCode) { |
| 68 var baseURL = | 68 var baseURL = |
| 69 /** @type {!Bindings.FileSystemWorkspaceBinding.FileSystem}*/ (uiSourceC
ode.project())._fileSystemBaseURL; | 69 /** @type {!Persistence.FileSystemWorkspaceBinding.FileSystem}*/ (uiSour
ceCode.project())._fileSystemBaseURL; |
| 70 return uiSourceCode.url().substring(baseURL.length).split('/'); | 70 return uiSourceCode.url().substring(baseURL.length).split('/'); |
| 71 } | 71 } |
| 72 | 72 |
| 73 /** | 73 /** |
| 74 * @param {!Workspace.Project} project | 74 * @param {!Workspace.Project} project |
| 75 * @param {string} relativePath | 75 * @param {string} relativePath |
| 76 * @return {string} | 76 * @return {string} |
| 77 */ | 77 */ |
| 78 static completeURL(project, relativePath) { | 78 static completeURL(project, relativePath) { |
| 79 var fsProject = /** @type {!Bindings.FileSystemWorkspaceBinding.FileSystem}*
/ (project); | 79 var fsProject = /** @type {!Persistence.FileSystemWorkspaceBinding.FileSyste
m}*/ (project); |
| 80 return fsProject._fileSystemBaseURL + relativePath; | 80 return fsProject._fileSystemBaseURL + relativePath; |
| 81 } | 81 } |
| 82 | 82 |
| 83 /** | 83 /** |
| 84 * @param {string} extension | 84 * @param {string} extension |
| 85 * @return {!Common.ResourceType} | 85 * @return {!Common.ResourceType} |
| 86 */ | 86 */ |
| 87 static _contentTypeForExtension(extension) { | 87 static _contentTypeForExtension(extension) { |
| 88 if (Bindings.FileSystemWorkspaceBinding._styleSheetExtensions.has(extension)
) | 88 if (Persistence.FileSystemWorkspaceBinding._styleSheetExtensions.has(extensi
on)) |
| 89 return Common.resourceTypes.Stylesheet; | 89 return Common.resourceTypes.Stylesheet; |
| 90 if (Bindings.FileSystemWorkspaceBinding._documentExtensions.has(extension)) | 90 if (Persistence.FileSystemWorkspaceBinding._documentExtensions.has(extension
)) |
| 91 return Common.resourceTypes.Document; | 91 return Common.resourceTypes.Document; |
| 92 if (Bindings.FileSystemWorkspaceBinding._imageExtensions.has(extension)) | 92 if (Persistence.FileSystemWorkspaceBinding._imageExtensions.has(extension)) |
| 93 return Common.resourceTypes.Image; | 93 return Common.resourceTypes.Image; |
| 94 if (Bindings.FileSystemWorkspaceBinding._scriptExtensions.has(extension)) | 94 if (Persistence.FileSystemWorkspaceBinding._scriptExtensions.has(extension)) |
| 95 return Common.resourceTypes.Script; | 95 return Common.resourceTypes.Script; |
| 96 return Common.resourceTypes.Other; | 96 return Common.resourceTypes.Other; |
| 97 } | 97 } |
| 98 | 98 |
| 99 /** | 99 /** |
| 100 * @param {string} projectId | 100 * @param {string} projectId |
| 101 * @return {string} | 101 * @return {string} |
| 102 */ | 102 */ |
| 103 static fileSystemPath(projectId) { | 103 static fileSystemPath(projectId) { |
| 104 return projectId; | 104 return projectId; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 124 */ | 124 */ |
| 125 _onFileSystemAdded(event) { | 125 _onFileSystemAdded(event) { |
| 126 var fileSystem = /** @type {!Workspace.IsolatedFileSystem} */ (event.data); | 126 var fileSystem = /** @type {!Workspace.IsolatedFileSystem} */ (event.data); |
| 127 this._addFileSystem(fileSystem); | 127 this._addFileSystem(fileSystem); |
| 128 } | 128 } |
| 129 | 129 |
| 130 /** | 130 /** |
| 131 * @param {!Workspace.IsolatedFileSystem} fileSystem | 131 * @param {!Workspace.IsolatedFileSystem} fileSystem |
| 132 */ | 132 */ |
| 133 _addFileSystem(fileSystem) { | 133 _addFileSystem(fileSystem) { |
| 134 var boundFileSystem = new Bindings.FileSystemWorkspaceBinding.FileSystem(thi
s, fileSystem, this._workspace); | 134 var boundFileSystem = new Persistence.FileSystemWorkspaceBinding.FileSystem(
this, fileSystem, this._workspace); |
| 135 this._boundFileSystems.set(fileSystem.path(), boundFileSystem); | 135 this._boundFileSystems.set(fileSystem.path(), boundFileSystem); |
| 136 } | 136 } |
| 137 | 137 |
| 138 /** | 138 /** |
| 139 * @param {!Common.Event} event | 139 * @param {!Common.Event} event |
| 140 */ | 140 */ |
| 141 _onFileSystemRemoved(event) { | 141 _onFileSystemRemoved(event) { |
| 142 var fileSystem = /** @type {!Workspace.IsolatedFileSystem} */ (event.data); | 142 var fileSystem = /** @type {!Workspace.IsolatedFileSystem} */ (event.data); |
| 143 var boundFileSystem = this._boundFileSystems.get(fileSystem.path()); | 143 var boundFileSystem = this._boundFileSystems.get(fileSystem.path()); |
| 144 boundFileSystem.dispose(); | 144 boundFileSystem.dispose(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 161 | 161 |
| 162 dispose() { | 162 dispose() { |
| 163 Common.EventTarget.removeEventListeners(this._eventListeners); | 163 Common.EventTarget.removeEventListeners(this._eventListeners); |
| 164 for (var fileSystem of this._boundFileSystems.values()) { | 164 for (var fileSystem of this._boundFileSystems.values()) { |
| 165 fileSystem.dispose(); | 165 fileSystem.dispose(); |
| 166 this._boundFileSystems.remove(fileSystem._fileSystem.path()); | 166 this._boundFileSystems.remove(fileSystem._fileSystem.path()); |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 }; | 169 }; |
| 170 | 170 |
| 171 Bindings.FileSystemWorkspaceBinding._styleSheetExtensions = new Set(['css', 'scs
s', 'sass', 'less']); | 171 Persistence.FileSystemWorkspaceBinding._styleSheetExtensions = new Set(['css', '
scss', 'sass', 'less']); |
| 172 Bindings.FileSystemWorkspaceBinding._documentExtensions = new Set(['htm', 'html'
, 'asp', 'aspx', 'phtml', 'jsp']); | 172 Persistence.FileSystemWorkspaceBinding._documentExtensions = new Set(['htm', 'ht
ml', 'asp', 'aspx', 'phtml', 'jsp']); |
| 173 Bindings.FileSystemWorkspaceBinding._scriptExtensions = new Set([ | 173 Persistence.FileSystemWorkspaceBinding._scriptExtensions = new Set([ |
| 174 'asp', 'aspx', 'c', 'cc', 'cljs', 'coffee', 'cpp', 'cs', 'dart', 'java', 'js', | 174 'asp', 'aspx', 'c', 'cc', 'cljs', 'coffee', 'cpp', 'cs', 'dart', 'java', 'js', |
| 175 'jsp', 'jsx', 'h', 'm', 'mm', 'py', 'sh', 'ts', 'tsx', 'ls' | 175 'jsp', 'jsx', 'h', 'm', 'mm', 'py', 'sh', 'ts', 'tsx', 'ls' |
| 176 ]); | 176 ]); |
| 177 | 177 |
| 178 Bindings.FileSystemWorkspaceBinding._imageExtensions = Workspace.IsolatedFileSys
tem.ImageExtensions; | 178 Persistence.FileSystemWorkspaceBinding._imageExtensions = Workspace.IsolatedFile
System.ImageExtensions; |
| 179 | 179 |
| 180 | 180 |
| 181 /** | 181 /** |
| 182 * @implements {Workspace.Project} | 182 * @implements {Workspace.Project} |
| 183 * @unrestricted | 183 * @unrestricted |
| 184 */ | 184 */ |
| 185 Bindings.FileSystemWorkspaceBinding.FileSystem = class extends Workspace.Project
Store { | 185 Persistence.FileSystemWorkspaceBinding.FileSystem = class extends Workspace.Proj
ectStore { |
| 186 /** | 186 /** |
| 187 * @param {!Bindings.FileSystemWorkspaceBinding} fileSystemWorkspaceBinding | 187 * @param {!Persistence.FileSystemWorkspaceBinding} fileSystemWorkspaceBinding |
| 188 * @param {!Workspace.IsolatedFileSystem} isolatedFileSystem | 188 * @param {!Workspace.IsolatedFileSystem} isolatedFileSystem |
| 189 * @param {!Workspace.Workspace} workspace | 189 * @param {!Workspace.Workspace} workspace |
| 190 */ | 190 */ |
| 191 constructor(fileSystemWorkspaceBinding, isolatedFileSystem, workspace) { | 191 constructor(fileSystemWorkspaceBinding, isolatedFileSystem, workspace) { |
| 192 var fileSystemPath = isolatedFileSystem.path(); | 192 var fileSystemPath = isolatedFileSystem.path(); |
| 193 var id = Bindings.FileSystemWorkspaceBinding.projectId(fileSystemPath); | 193 var id = Persistence.FileSystemWorkspaceBinding.projectId(fileSystemPath); |
| 194 console.assert(!workspace.project(id)); | 194 console.assert(!workspace.project(id)); |
| 195 var displayName = fileSystemPath.substr(fileSystemPath.lastIndexOf('/') + 1)
; | 195 var displayName = fileSystemPath.substr(fileSystemPath.lastIndexOf('/') + 1)
; |
| 196 | 196 |
| 197 super(workspace, id, Workspace.projectTypes.FileSystem, displayName); | 197 super(workspace, id, Workspace.projectTypes.FileSystem, displayName); |
| 198 | 198 |
| 199 this._fileSystem = isolatedFileSystem; | 199 this._fileSystem = isolatedFileSystem; |
| 200 this._fileSystemBaseURL = this._fileSystem.path() + '/'; | 200 this._fileSystemBaseURL = this._fileSystem.path() + '/'; |
| 201 this._fileSystemWorkspaceBinding = fileSystemWorkspaceBinding; | 201 this._fileSystemWorkspaceBinding = fileSystemWorkspaceBinding; |
| 202 this._fileSystemPath = fileSystemPath; | 202 this._fileSystemPath = fileSystemPath; |
| 203 | 203 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 226 _filePathForUISourceCode(uiSourceCode) { | 226 _filePathForUISourceCode(uiSourceCode) { |
| 227 return uiSourceCode.url().substring(this._fileSystemPath.length); | 227 return uiSourceCode.url().substring(this._fileSystemPath.length); |
| 228 } | 228 } |
| 229 | 229 |
| 230 /** | 230 /** |
| 231 * @override | 231 * @override |
| 232 * @param {!Workspace.UISourceCode} uiSourceCode | 232 * @param {!Workspace.UISourceCode} uiSourceCode |
| 233 * @return {!Promise<?Workspace.UISourceCodeMetadata>} | 233 * @return {!Promise<?Workspace.UISourceCodeMetadata>} |
| 234 */ | 234 */ |
| 235 requestMetadata(uiSourceCode) { | 235 requestMetadata(uiSourceCode) { |
| 236 if (uiSourceCode[Bindings.FileSystemWorkspaceBinding._metadata]) | 236 if (uiSourceCode[Persistence.FileSystemWorkspaceBinding._metadata]) |
| 237 return uiSourceCode[Bindings.FileSystemWorkspaceBinding._metadata]; | 237 return uiSourceCode[Persistence.FileSystemWorkspaceBinding._metadata]; |
| 238 var relativePath = this._filePathForUISourceCode(uiSourceCode); | 238 var relativePath = this._filePathForUISourceCode(uiSourceCode); |
| 239 var promise = this._fileSystem.getMetadata(relativePath).then(onMetadata); | 239 var promise = this._fileSystem.getMetadata(relativePath).then(onMetadata); |
| 240 uiSourceCode[Bindings.FileSystemWorkspaceBinding._metadata] = promise; | 240 uiSourceCode[Persistence.FileSystemWorkspaceBinding._metadata] = promise; |
| 241 return promise; | 241 return promise; |
| 242 | 242 |
| 243 /** | 243 /** |
| 244 * @param {?{modificationTime: !Date, size: number}} metadata | 244 * @param {?{modificationTime: !Date, size: number}} metadata |
| 245 * @return {?Workspace.UISourceCodeMetadata} | 245 * @return {?Workspace.UISourceCodeMetadata} |
| 246 */ | 246 */ |
| 247 function onMetadata(metadata) { | 247 function onMetadata(metadata) { |
| 248 if (!metadata) | 248 if (!metadata) |
| 249 return null; | 249 return null; |
| 250 return new Workspace.UISourceCodeMetadata(metadata.modificationTime, metad
ata.size); | 250 return new Workspace.UISourceCodeMetadata(metadata.modificationTime, metad
ata.size); |
| 251 } | 251 } |
| 252 } | 252 } |
| 253 | 253 |
| 254 /** | 254 /** |
| 255 * @override | 255 * @override |
| 256 * @param {!Workspace.UISourceCode} uiSourceCode | 256 * @param {!Workspace.UISourceCode} uiSourceCode |
| 257 * @param {function(?string)} callback | 257 * @param {function(?string)} callback |
| 258 */ | 258 */ |
| 259 requestFileContent(uiSourceCode, callback) { | 259 requestFileContent(uiSourceCode, callback) { |
| 260 var filePath = this._filePathForUISourceCode(uiSourceCode); | 260 var filePath = this._filePathForUISourceCode(uiSourceCode); |
| 261 var isImage = Bindings.FileSystemWorkspaceBinding._imageExtensions.has(Commo
n.ParsedURL.extractExtension(filePath)); | 261 var isImage = |
| 262 Persistence.FileSystemWorkspaceBinding._imageExtensions.has(Common.Parse
dURL.extractExtension(filePath)); |
| 262 | 263 |
| 263 this._fileSystem.requestFileContent(filePath, isImage ? base64CallbackWrappe
r : callback); | 264 this._fileSystem.requestFileContent(filePath, isImage ? base64CallbackWrappe
r : callback); |
| 264 | 265 |
| 265 /** | 266 /** |
| 266 * @param {?string} result | 267 * @param {?string} result |
| 267 */ | 268 */ |
| 268 function base64CallbackWrapper(result) { | 269 function base64CallbackWrapper(result) { |
| 269 if (!result) { | 270 if (!result) { |
| 270 callback(result); | 271 callback(result); |
| 271 return; | 272 return; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 callback(true, uiSourceCode.name(), uiSourceCode.url(), uiSourceCode.conte
ntType()); | 314 callback(true, uiSourceCode.name(), uiSourceCode.url(), uiSourceCode.conte
ntType()); |
| 314 return; | 315 return; |
| 315 } | 316 } |
| 316 | 317 |
| 317 var filePath = this._filePathForUISourceCode(uiSourceCode); | 318 var filePath = this._filePathForUISourceCode(uiSourceCode); |
| 318 this._fileSystem.renameFile(filePath, newName, innerCallback.bind(this)); | 319 this._fileSystem.renameFile(filePath, newName, innerCallback.bind(this)); |
| 319 | 320 |
| 320 /** | 321 /** |
| 321 * @param {boolean} success | 322 * @param {boolean} success |
| 322 * @param {string=} newName | 323 * @param {string=} newName |
| 323 * @this {Bindings.FileSystemWorkspaceBinding.FileSystem} | 324 * @this {Persistence.FileSystemWorkspaceBinding.FileSystem} |
| 324 */ | 325 */ |
| 325 function innerCallback(success, newName) { | 326 function innerCallback(success, newName) { |
| 326 if (!success || !newName) { | 327 if (!success || !newName) { |
| 327 callback(false, newName); | 328 callback(false, newName); |
| 328 return; | 329 return; |
| 329 } | 330 } |
| 330 console.assert(newName); | 331 console.assert(newName); |
| 331 var slash = filePath.lastIndexOf('/'); | 332 var slash = filePath.lastIndexOf('/'); |
| 332 var parentPath = filePath.substring(0, slash); | 333 var parentPath = filePath.substring(0, slash); |
| 333 filePath = parentPath + '/' + newName; | 334 filePath = parentPath + '/' + newName; |
| 334 filePath = filePath.substr(1); | 335 filePath = filePath.substr(1); |
| 335 var extension = this._extensionForPath(newName); | 336 var extension = this._extensionForPath(newName); |
| 336 var newURL = this._fileSystemBaseURL + filePath; | 337 var newURL = this._fileSystemBaseURL + filePath; |
| 337 var newContentType = Bindings.FileSystemWorkspaceBinding._contentTypeForEx
tension(extension); | 338 var newContentType = Persistence.FileSystemWorkspaceBinding._contentTypeFo
rExtension(extension); |
| 338 this.renameUISourceCode(uiSourceCode, newName); | 339 this.renameUISourceCode(uiSourceCode, newName); |
| 339 callback(true, newName, newURL, newContentType); | 340 callback(true, newName, newURL, newContentType); |
| 340 } | 341 } |
| 341 } | 342 } |
| 342 | 343 |
| 343 /** | 344 /** |
| 344 * @override | 345 * @override |
| 345 * @param {!Workspace.UISourceCode} uiSourceCode | 346 * @param {!Workspace.UISourceCode} uiSourceCode |
| 346 * @param {string} query | 347 * @param {string} query |
| 347 * @param {boolean} caseSensitive | 348 * @param {boolean} caseSensitive |
| (...skipping 24 matching lines...) Expand all Loading... |
| 372 */ | 373 */ |
| 373 findFilesMatchingSearchRequest(searchConfig, filesMathingFileQuery, progress,
callback) { | 374 findFilesMatchingSearchRequest(searchConfig, filesMathingFileQuery, progress,
callback) { |
| 374 var result = filesMathingFileQuery; | 375 var result = filesMathingFileQuery; |
| 375 var queriesToRun = searchConfig.queries().slice(); | 376 var queriesToRun = searchConfig.queries().slice(); |
| 376 if (!queriesToRun.length) | 377 if (!queriesToRun.length) |
| 377 queriesToRun.push(''); | 378 queriesToRun.push(''); |
| 378 progress.setTotalWork(queriesToRun.length); | 379 progress.setTotalWork(queriesToRun.length); |
| 379 searchNextQuery.call(this); | 380 searchNextQuery.call(this); |
| 380 | 381 |
| 381 /** | 382 /** |
| 382 * @this {Bindings.FileSystemWorkspaceBinding.FileSystem} | 383 * @this {Persistence.FileSystemWorkspaceBinding.FileSystem} |
| 383 */ | 384 */ |
| 384 function searchNextQuery() { | 385 function searchNextQuery() { |
| 385 if (!queriesToRun.length) { | 386 if (!queriesToRun.length) { |
| 386 progress.done(); | 387 progress.done(); |
| 387 callback(result); | 388 callback(result); |
| 388 return; | 389 return; |
| 389 } | 390 } |
| 390 var query = queriesToRun.shift(); | 391 var query = queriesToRun.shift(); |
| 391 this._fileSystem.searchInPath(searchConfig.isRegex() ? '' : query, progres
s, innerCallback.bind(this)); | 392 this._fileSystem.searchInPath(searchConfig.isRegex() ? '' : query, progres
s, innerCallback.bind(this)); |
| 392 } | 393 } |
| 393 | 394 |
| 394 /** | 395 /** |
| 395 * @param {!Array.<string>} files | 396 * @param {!Array.<string>} files |
| 396 * @this {Bindings.FileSystemWorkspaceBinding.FileSystem} | 397 * @this {Persistence.FileSystemWorkspaceBinding.FileSystem} |
| 397 */ | 398 */ |
| 398 function innerCallback(files) { | 399 function innerCallback(files) { |
| 399 files = files.sort(); | 400 files = files.sort(); |
| 400 progress.worked(1); | 401 progress.worked(1); |
| 401 result = result.intersectOrdered(files, String.naturalOrderComparator); | 402 result = result.intersectOrdered(files, String.naturalOrderComparator); |
| 402 searchNextQuery.call(this); | 403 searchNextQuery.call(this); |
| 403 } | 404 } |
| 404 } | 405 } |
| 405 | 406 |
| 406 /** | 407 /** |
| (...skipping 15 matching lines...) Expand all Loading... |
| 422 return path.substring(extensionIndex + 1).toLowerCase(); | 423 return path.substring(extensionIndex + 1).toLowerCase(); |
| 423 } | 424 } |
| 424 | 425 |
| 425 populate() { | 426 populate() { |
| 426 var chunkSize = 1000; | 427 var chunkSize = 1000; |
| 427 var filePaths = this._fileSystem.filePaths(); | 428 var filePaths = this._fileSystem.filePaths(); |
| 428 reportFileChunk.call(this, 0); | 429 reportFileChunk.call(this, 0); |
| 429 | 430 |
| 430 /** | 431 /** |
| 431 * @param {number} from | 432 * @param {number} from |
| 432 * @this {Bindings.FileSystemWorkspaceBinding.FileSystem} | 433 * @this {Persistence.FileSystemWorkspaceBinding.FileSystem} |
| 433 */ | 434 */ |
| 434 function reportFileChunk(from) { | 435 function reportFileChunk(from) { |
| 435 var to = Math.min(from + chunkSize, filePaths.length); | 436 var to = Math.min(from + chunkSize, filePaths.length); |
| 436 for (var i = from; i < to; ++i) | 437 for (var i = from; i < to; ++i) |
| 437 this._addFile(filePaths[i]); | 438 this._addFile(filePaths[i]); |
| 438 if (to < filePaths.length) | 439 if (to < filePaths.length) |
| 439 setTimeout(reportFileChunk.bind(this, to), 100); | 440 setTimeout(reportFileChunk.bind(this, to), 100); |
| 440 } | 441 } |
| 441 } | 442 } |
| 442 | 443 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 466 * @param {?string} name | 467 * @param {?string} name |
| 467 * @param {string} content | 468 * @param {string} content |
| 468 * @param {function(?Workspace.UISourceCode)} callback | 469 * @param {function(?Workspace.UISourceCode)} callback |
| 469 */ | 470 */ |
| 470 createFile(path, name, content, callback) { | 471 createFile(path, name, content, callback) { |
| 471 this._fileSystem.createFile(path, name, innerCallback.bind(this)); | 472 this._fileSystem.createFile(path, name, innerCallback.bind(this)); |
| 472 var createFilePath; | 473 var createFilePath; |
| 473 | 474 |
| 474 /** | 475 /** |
| 475 * @param {?string} filePath | 476 * @param {?string} filePath |
| 476 * @this {Bindings.FileSystemWorkspaceBinding.FileSystem} | 477 * @this {Persistence.FileSystemWorkspaceBinding.FileSystem} |
| 477 */ | 478 */ |
| 478 function innerCallback(filePath) { | 479 function innerCallback(filePath) { |
| 479 if (!filePath) { | 480 if (!filePath) { |
| 480 callback(null); | 481 callback(null); |
| 481 return; | 482 return; |
| 482 } | 483 } |
| 483 createFilePath = filePath; | 484 createFilePath = filePath; |
| 484 if (!content) { | 485 if (!content) { |
| 485 contentSet.call(this); | 486 contentSet.call(this); |
| 486 return; | 487 return; |
| 487 } | 488 } |
| 488 this._fileSystem.setFileContent(filePath, content, contentSet.bind(this)); | 489 this._fileSystem.setFileContent(filePath, content, contentSet.bind(this)); |
| 489 } | 490 } |
| 490 | 491 |
| 491 /** | 492 /** |
| 492 * @this {Bindings.FileSystemWorkspaceBinding.FileSystem} | 493 * @this {Persistence.FileSystemWorkspaceBinding.FileSystem} |
| 493 */ | 494 */ |
| 494 function contentSet() { | 495 function contentSet() { |
| 495 callback(this._addFile(createFilePath)); | 496 callback(this._addFile(createFilePath)); |
| 496 } | 497 } |
| 497 } | 498 } |
| 498 | 499 |
| 499 /** | 500 /** |
| 500 * @override | 501 * @override |
| 501 * @param {string} path | 502 * @param {string} path |
| 502 */ | 503 */ |
| 503 deleteFile(path) { | 504 deleteFile(path) { |
| 504 this._fileSystem.deleteFile(path); | 505 this._fileSystem.deleteFile(path); |
| 505 this.removeUISourceCode(path); | 506 this.removeUISourceCode(path); |
| 506 } | 507 } |
| 507 | 508 |
| 508 /** | 509 /** |
| 509 * @override | 510 * @override |
| 510 */ | 511 */ |
| 511 remove() { | 512 remove() { |
| 512 this._fileSystemWorkspaceBinding._isolatedFileSystemManager.removeFileSystem
(this._fileSystem); | 513 this._fileSystemWorkspaceBinding._isolatedFileSystemManager.removeFileSystem
(this._fileSystem); |
| 513 } | 514 } |
| 514 | 515 |
| 515 /** | 516 /** |
| 516 * @param {string} filePath | 517 * @param {string} filePath |
| 517 * @return {!Workspace.UISourceCode} | 518 * @return {!Workspace.UISourceCode} |
| 518 */ | 519 */ |
| 519 _addFile(filePath) { | 520 _addFile(filePath) { |
| 520 var extension = this._extensionForPath(filePath); | 521 var extension = this._extensionForPath(filePath); |
| 521 var contentType = Bindings.FileSystemWorkspaceBinding._contentTypeForExtensi
on(extension); | 522 var contentType = Persistence.FileSystemWorkspaceBinding._contentTypeForExte
nsion(extension); |
| 522 | 523 |
| 523 var uiSourceCode = this.createUISourceCode(this._fileSystemBaseURL + filePat
h, contentType); | 524 var uiSourceCode = this.createUISourceCode(this._fileSystemBaseURL + filePat
h, contentType); |
| 524 this.addUISourceCode(uiSourceCode); | 525 this.addUISourceCode(uiSourceCode); |
| 525 return uiSourceCode; | 526 return uiSourceCode; |
| 526 } | 527 } |
| 527 | 528 |
| 528 /** | 529 /** |
| 529 * @param {string} path | 530 * @param {string} path |
| 530 */ | 531 */ |
| 531 _fileChanged(path) { | 532 _fileChanged(path) { |
| 532 var uiSourceCode = this.uiSourceCodeForURL(path); | 533 var uiSourceCode = this.uiSourceCodeForURL(path); |
| 533 if (!uiSourceCode) { | 534 if (!uiSourceCode) { |
| 534 var contentType = Bindings.FileSystemWorkspaceBinding._contentTypeForExten
sion(this._extensionForPath(path)); | 535 var contentType = Persistence.FileSystemWorkspaceBinding._contentTypeForEx
tension(this._extensionForPath(path)); |
| 535 this.addUISourceCode(this.createUISourceCode(path, contentType)); | 536 this.addUISourceCode(this.createUISourceCode(path, contentType)); |
| 536 return; | 537 return; |
| 537 } | 538 } |
| 538 uiSourceCode[Bindings.FileSystemWorkspaceBinding._metadata] = null; | 539 uiSourceCode[Persistence.FileSystemWorkspaceBinding._metadata] = null; |
| 539 uiSourceCode.checkContentUpdated(); | 540 uiSourceCode.checkContentUpdated(); |
| 540 } | 541 } |
| 541 | 542 |
| 542 dispose() { | 543 dispose() { |
| 543 this.removeProject(); | 544 this.removeProject(); |
| 544 } | 545 } |
| 545 }; | 546 }; |
| 546 | 547 |
| 547 Bindings.FileSystemWorkspaceBinding._metadata = Symbol('FileSystemWorkspaceBindi
ng.Metadata'); | 548 Persistence.FileSystemWorkspaceBinding._metadata = Symbol('FileSystemWorkspaceBi
nding.Metadata'); |
| OLD | NEW |