FileSystemProjectDelegate.js [plain text]
WebInspector.FileSystemProjectDelegate = function(isolatedFileSystem, workspace)
{
this._fileSystem = isolatedFileSystem;
this._workspace = workspace;
}
WebInspector.FileSystemProjectDelegate._scriptExtensions = ["js", "java", "cc", "cpp", "h", "cs", "py", "php"].keySet();
WebInspector.FileSystemProjectDelegate.projectId = function(fileSystemPath)
{
return "filesystem:" + fileSystemPath;
}
WebInspector.FileSystemProjectDelegate.prototype = {
id: function()
{
return WebInspector.FileSystemProjectDelegate.projectId(this._fileSystem.path());
},
type: function()
{
return WebInspector.projectTypes.FileSystem;
},
fileSystemPath: function()
{
return this._fileSystem.path();
},
displayName: function()
{
return this._fileSystem.path().substr(this._fileSystem.path().lastIndexOf("/") + 1);
},
_filePathForPath: function(path)
{
return "/" + path.join("/");
},
requestFileContent: function(path, callback)
{
var filePath = this._filePathForPath(path);
this._fileSystem.requestFileContent(filePath, innerCallback.bind(this));
function innerCallback(content)
{
var contentType = this._contentTypeForPath(path);
callback(content, false, contentType.canonicalMimeType());
}
},
canSetFileContent: function()
{
return true;
},
setFileContent: function(path, newContent, callback)
{
var filePath = this._filePathForPath(path);
this._fileSystem.setFileContent(filePath, newContent, callback.bind(this, ""));
},
searchInFileContent: function(path, query, caseSensitive, isRegex, callback)
{
var filePath = this._filePathForPath(path);
this._fileSystem.requestFileContent(filePath, contentCallback.bind(this));
function contentCallback(content)
{
var result = [];
if (content !== null)
result = WebInspector.ContentProvider.performSearchInContent(content, query, caseSensitive, isRegex);
callback(result);
}
},
_contentTypeForPath: function(path)
{
var fileName = path[path.length - 1];
var extensionIndex = fileName.lastIndexOf(".");
var extension = "";
if (extensionIndex !== -1)
extension = fileName.substring(extensionIndex + 1);
var contentType = WebInspector.resourceTypes.Other;
if (WebInspector.FileSystemProjectDelegate._scriptExtensions[extension])
return WebInspector.resourceTypes.Script;
if (extension === "css")
return WebInspector.resourceTypes.Stylesheet;
if (extension === "html")
return WebInspector.resourceTypes.Document;
return WebInspector.resourceTypes.Other;
},
populate: function()
{
this._fileSystem.requestFilesRecursive("", fileLoaded.bind(this));
function fileLoaded(filePath)
{
var path = filePath.split("/");
path.shift();
console.assert(path.length);
var fullPath = this._fileSystem.path() + filePath;
var url = this._workspace.urlForPath(fullPath);
var contentType = this._contentTypeForPath(path);
var fileDescriptor = new WebInspector.FileDescriptor(path, "file://" + fullPath, url, contentType, true);
this._addFile(fileDescriptor);
}
},
_addFile: function(fileDescriptor)
{
this.dispatchEventToListeners(WebInspector.ProjectDelegate.Events.FileAdded, fileDescriptor);
},
_removeFile: function(path)
{
this.dispatchEventToListeners(WebInspector.ProjectDelegate.Events.FileRemoved, path);
},
reset: function()
{
this.dispatchEventToListeners(WebInspector.ProjectDelegate.Events.Reset, null);
},
__proto__: WebInspector.Object.prototype
}
WebInspector.fileSystemProjectDelegate = null;
WebInspector.FileSystemWorkspaceProvider = function(isolatedFileSystemManager, workspace)
{
this._isolatedFileSystemManager = isolatedFileSystemManager;
this._workspace = workspace;
this._isolatedFileSystemManager.addEventListener(WebInspector.IsolatedFileSystemManager.Events.FileSystemAdded, this._fileSystemAdded, this);
this._isolatedFileSystemManager.addEventListener(WebInspector.IsolatedFileSystemManager.Events.FileSystemRemoved, this._fileSystemRemoved, this);
this._simpleProjectDelegates = {};
}
WebInspector.FileSystemWorkspaceProvider.prototype = {
_fileSystemAdded: function(event)
{
var fileSystem = (event.data);
var projectId = WebInspector.FileSystemProjectDelegate.projectId(fileSystem.path());
var projectDelegate = new WebInspector.FileSystemProjectDelegate(fileSystem, this._workspace)
this._simpleProjectDelegates[projectDelegate.id()] = projectDelegate;
console.assert(!this._workspace.project(projectDelegate.id()));
this._workspace.addProject(projectDelegate);
projectDelegate.populate();
},
_fileSystemRemoved: function(event)
{
var fileSystem = (event.data);
var projectId = WebInspector.FileSystemProjectDelegate.projectId(fileSystem.path());
this._workspace.removeProject(projectId);
delete this._simpleProjectDelegates[projectId];
},
fileSystemPath: function(uiSourceCode)
{
var projectDelegate = this._simpleProjectDelegates[uiSourceCode.project().id()];
return projectDelegate.fileSystemPath();
}
}
WebInspector.fileSystemWorkspaceProvider = null;