2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
33 * @extends {WebInspector.Object}
34 * @implements {WebInspector.ProjectDelegate}
35 * @param {!WebInspector.Workspace} workspace
37 * @param {!WebInspector.projectTypes} type
39 WebInspector
.ContentProviderBasedProjectDelegate = function(workspace
, id
, type
)
41 WebInspector
.Object
.call(this);
43 /** @type {!Object.<string, !WebInspector.ContentProvider>} */
44 this._contentProviders
= {};
45 this._workspace
= workspace
;
47 workspace
.addProject(id
, this);
50 WebInspector
.ContentProviderBasedProjectDelegate
.prototype = {
64 displayName: function()
66 // Overridden by subclasses
76 // Overridden by subclasses
82 * @param {string} path
83 * @param {function(?Date, ?number)} callback
85 requestMetadata: function(path
, callback
)
92 * @param {string} path
93 * @param {function(?string)} callback
95 requestFileContent: function(path
, callback
)
97 var contentProvider
= this._contentProviders
[path
];
98 contentProvider
.requestContent(callback
);
101 * @param {?string} content
102 * @param {boolean} encoded
103 * @param {string} mimeType
105 function innerCallback(content
, encoded
, mimeType
)
115 canSetFileContent: function()
122 * @param {string} path
123 * @param {string} newContent
124 * @param {function(?string)} callback
126 setFileContent: function(path
, newContent
, callback
)
135 canRename: function()
142 * @param {string} path
143 * @param {string} newName
144 * @param {function(boolean, string=, string=, string=, !WebInspector.ResourceType=)} callback
146 rename: function(path
, newName
, callback
)
148 this.performRename(path
, newName
, innerCallback
.bind(this));
151 * @param {boolean} success
152 * @param {string=} newName
153 * @this {WebInspector.ContentProviderBasedProjectDelegate}
155 function innerCallback(success
, newName
)
158 this._updateName(path
, /** @type {string} */ (newName
));
159 callback(success
, newName
);
165 * @param {string} path
166 * @param {function()=} callback
168 refresh: function(path
, callback
)
176 * @param {string} path
178 excludeFolder: function(path
)
184 * @param {string} path
185 * @param {?string} name
186 * @param {string} content
187 * @param {function(?string)} callback
189 createFile: function(path
, name
, content
, callback
)
195 * @param {string} path
197 deleteFile: function(path
)
209 * @param {string} path
210 * @param {string} newName
211 * @param {function(boolean, string=)} callback
213 performRename: function(path
, newName
, callback
)
219 * @param {string} path
220 * @param {string} newName
222 _updateName: function(path
, newName
)
225 var copyOfPath
= path
.split("/");
226 copyOfPath
[copyOfPath
.length
- 1] = newName
;
227 var newPath
= copyOfPath
.join("/");
228 this._contentProviders
[newPath
] = this._contentProviders
[oldPath
];
229 delete this._contentProviders
[oldPath
];
234 * @param {string} path
235 * @param {string} query
236 * @param {boolean} caseSensitive
237 * @param {boolean} isRegex
238 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} callback
240 searchInFileContent: function(path
, query
, caseSensitive
, isRegex
, callback
)
242 var contentProvider
= this._contentProviders
[path
];
243 contentProvider
.searchInContent(query
, caseSensitive
, isRegex
, callback
);
248 * @param {!WebInspector.ProjectSearchConfig} searchConfig
249 * @param {!Array.<string>} filesMathingFileQuery
250 * @param {!WebInspector.Progress} progress
251 * @param {function(!Array.<string>)} callback
253 findFilesMatchingSearchRequest: function(searchConfig
, filesMathingFileQuery
, progress
, callback
)
256 var paths
= filesMathingFileQuery
;
257 var totalCount
= paths
.length
;
258 if (totalCount
=== 0) {
259 // searchInContent should call back later.
260 setTimeout(doneCallback
, 0);
264 var barrier
= new CallbackBarrier();
265 progress
.setTotalWork(paths
.length
);
266 for (var i
= 0; i
< paths
.length
; ++i
)
267 searchInContent
.call(this, paths
[i
], barrier
.createCallback(searchInContentCallback
.bind(null, paths
[i
])));
268 barrier
.callWhenDone(doneCallback
);
271 * @param {string} path
272 * @param {function(boolean)} callback
273 * @this {WebInspector.ContentProviderBasedProjectDelegate}
275 function searchInContent(path
, callback
)
277 var queriesToRun
= searchConfig
.queries().slice();
278 searchNextQuery
.call(this);
281 * @this {WebInspector.ContentProviderBasedProjectDelegate}
283 function searchNextQuery()
285 if (!queriesToRun
.length
) {
289 var query
= queriesToRun
.shift();
290 this._contentProviders
[path
].searchInContent(query
, !searchConfig
.ignoreCase(), searchConfig
.isRegex(), contentCallback
.bind(this));
294 * @param {!Array.<!WebInspector.ContentProvider.SearchMatch>} searchMatches
295 * @this {WebInspector.ContentProviderBasedProjectDelegate}
297 function contentCallback(searchMatches
)
299 if (!searchMatches
.length
) {
303 searchNextQuery
.call(this);
308 * @param {string} path
309 * @param {boolean} matches
311 function searchInContentCallback(path
, matches
)
318 function doneCallback()
327 * @param {!WebInspector.Progress} progress
329 indexContent: function(progress
)
331 setTimeout(progress
.done
.bind(progress
), 0);
335 * @param {string} parentPath
336 * @param {string} name
337 * @param {string} originURL
338 * @param {string} url
339 * @param {!WebInspector.ContentProvider} contentProvider
342 addContentProvider: function(parentPath
, name
, originURL
, url
, contentProvider
)
344 var path
= parentPath
? parentPath
+ "/" + name
: name
;
345 if (this._contentProviders
[path
])
347 var fileDescriptor
= new WebInspector
.FileDescriptor(parentPath
, name
, originURL
, url
, contentProvider
.contentType());
348 this._contentProviders
[path
] = contentProvider
;
349 this.dispatchEventToListeners(WebInspector
.ProjectDelegate
.Events
.FileAdded
, fileDescriptor
);
354 * @param {string} path
356 removeFile: function(path
)
358 delete this._contentProviders
[path
];
359 this.dispatchEventToListeners(WebInspector
.ProjectDelegate
.Events
.FileRemoved
, path
);
363 * @return {!Object.<string, !WebInspector.ContentProvider>}
365 contentProviders: function()
367 return this._contentProviders
;
372 this._contentProviders
= {};
373 this._workspace
.removeProject(this._id
);
374 this._workspace
.addProject(this._id
, this);
377 __proto__
: WebInspector
.Object
.prototype