SimpleWorkspaceProvider.js [plain text]
WebInspector.SimpleProjectDelegate = function(name, type)
{
WebInspector.ContentProviderBasedProjectDelegate.call(this, type);
this._name = name;
this._lastUniqueSuffix = 0;
}
WebInspector.SimpleProjectDelegate.projectId = function(name, type)
{
var typePrefix = type !== WebInspector.projectTypes.Network ? (type + ":") : "";
return typePrefix + name;
}
WebInspector.SimpleProjectDelegate.prototype = {
id: function()
{
return WebInspector.SimpleProjectDelegate.projectId(this._name, this.type());
},
displayName: function()
{
if (typeof this._displayName !== "undefined")
return this._displayName;
if (!this._name) {
this._displayName = this.type() !== WebInspector.projectTypes.Snippets ? WebInspector.UIString("(no domain)") : "";
return this._displayName;
}
var parsedURL = new WebInspector.ParsedURL(this._name);
if (parsedURL.isValid) {
this._displayName = parsedURL.host + (parsedURL.port ? (":" + parsedURL.port) : "");
if (!this._displayName)
this._displayName = this._name;
}
else
this._displayName = this._name;
return this._displayName;
},
addFile: function(path, forceUniquePath, url, contentProvider, isEditable, isContentScript)
{
if (forceUniquePath)
this._ensureUniquePath(path);
return this.addContentProvider(path, url, contentProvider, isEditable, isContentScript);
},
_ensureUniquePath: function(path)
{
var uniquePath = path.join("/");
var suffix = "";
var contentProviders = this.contentProviders();
while (contentProviders[uniquePath]) {
suffix = " (" + (++this._lastUniqueSuffix) + ")";
uniquePath = path + suffix;
}
path[path.length - 1] += suffix;
},
__proto__: WebInspector.ContentProviderBasedProjectDelegate.prototype
}
WebInspector.SimpleWorkspaceProvider = function(workspace, type)
{
this._workspace = workspace;
this._type = type;
this._simpleProjectDelegates = {};
}
WebInspector.SimpleWorkspaceProvider.pathForSplittedURL = function(splittedURL)
{
var result = splittedURL.slice();
result.shift();
return result;
}
WebInspector.SimpleWorkspaceProvider.prototype = {
_projectDelegate: function(projectName)
{
if (this._simpleProjectDelegates[projectName])
return this._simpleProjectDelegates[projectName];
var simpleProjectDelegate = new WebInspector.SimpleProjectDelegate(projectName, this._type);
this._simpleProjectDelegates[projectName] = simpleProjectDelegate;
this._workspace.addProject(simpleProjectDelegate);
return simpleProjectDelegate;
},
addFileForURL: function(url, contentProvider, isEditable, isContentScript)
{
return this._innerAddFileForURL(url, contentProvider, isEditable, false, isContentScript);
},
addUniqueFileForURL: function(url, contentProvider, isEditable, isContentScript)
{
return this._innerAddFileForURL(url, contentProvider, isEditable, true, isContentScript);
},
_innerAddFileForURL: function(url, contentProvider, isEditable, forceUnique, isContentScript)
{
var splittedURL = WebInspector.ParsedURL.splitURL(url);
var projectName = splittedURL[0];
var path = WebInspector.SimpleWorkspaceProvider.pathForSplittedURL(splittedURL);
return this._innerAddFile(projectName, path, url, contentProvider, isEditable, forceUnique, isContentScript);
},
addFileByName: function(projectName, name, contentProvider, isEditable, isContentScript)
{
return this._innerAddFile("", [name], name, contentProvider, isEditable, false, isContentScript);
},
_innerAddFile: function(projectName, path, url, contentProvider, isEditable, forceUnique, isContentScript)
{
var projectDelegate = this._projectDelegate(projectName);
path = projectDelegate.addFile(path, forceUnique, url, contentProvider, isEditable, isContentScript);
return this._workspace.uiSourceCode(projectDelegate.id(), path);
},
removeFileByName: function(projectName, name)
{
var projectDelegate = this._projectDelegate(projectName);
projectDelegate.removeFile([name]);
},
reset: function()
{
for (var projectName in this._simpleProjectDelegates)
this._simpleProjectDelegates[projectName].reset();
this._simpleProjectDelegates = {};
},
__proto__: WebInspector.Object.prototype
}