2 * Copyright (C) 2012 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.ContentProviderBasedProjectDelegate}
34 * @param {string} name
35 * @param {string} type
37 WebInspector.SimpleProjectDelegate = function(name, type)
39 WebInspector.ContentProviderBasedProjectDelegate.call(this, type);
41 this._lastUniqueSuffix = 0;
44 WebInspector.SimpleProjectDelegate.projectId = function(name, type)
46 var typePrefix = type !== WebInspector.projectTypes.Network ? (type + ":") : "";
47 return typePrefix + name;
50 WebInspector.SimpleProjectDelegate.prototype = {
56 return WebInspector.SimpleProjectDelegate.projectId(this._name, this.type());
62 displayName: function()
64 if (typeof this._displayName !== "undefined")
65 return this._displayName;
67 this._displayName = this.type() !== WebInspector.projectTypes.Snippets ? WebInspector.UIString("(no domain)") : "";
68 return this._displayName;
70 var parsedURL = new WebInspector.ParsedURL(this._name);
71 if (parsedURL.isValid) {
72 this._displayName = parsedURL.host + (parsedURL.port ? (":" + parsedURL.port) : "");
73 if (!this._displayName)
74 this._displayName = this._name;
77 this._displayName = this._name;
78 return this._displayName;
82 * @param {string} parentPath
83 * @param {string} name
85 * @param {!WebInspector.ContentProvider} contentProvider
86 * @param {boolean} isEditable
87 * @param {boolean=} isContentScript
90 addFile: function(parentPath, name, forceUniquePath, url, contentProvider, isEditable, isContentScript)
93 name = this._ensureUniqueName(parentPath, name);
94 return this.addContentProvider(parentPath, name, url, contentProvider, isEditable, isContentScript);
98 * @param {string} parentPath
99 * @param {string} name
102 _ensureUniqueName: function(parentPath, name)
104 var path = parentPath ? parentPath + "/" + name : name;
105 var uniquePath = path;
107 var contentProviders = this.contentProviders();
108 while (contentProviders[uniquePath]) {
109 suffix = " (" + (++this._lastUniqueSuffix) + ")";
110 uniquePath = path + suffix;
112 return name + suffix;
115 __proto__: WebInspector.ContentProviderBasedProjectDelegate.prototype
120 * @extends {WebInspector.Object}
121 * @param {!WebInspector.Workspace} workspace
122 * @param {string} type
124 WebInspector.SimpleWorkspaceProvider = function(workspace, type)
126 this._workspace = workspace;
128 this._simpleProjectDelegates = {};
131 WebInspector.SimpleWorkspaceProvider.prototype = {
133 * @param {string} projectName
134 * @return {!WebInspector.SimpleProjectDelegate}
136 _projectDelegate: function(projectName)
138 if (this._simpleProjectDelegates[projectName])
139 return this._simpleProjectDelegates[projectName];
140 var simpleProjectDelegate = new WebInspector.SimpleProjectDelegate(projectName, this._type);
141 this._simpleProjectDelegates[projectName] = simpleProjectDelegate;
142 this._workspace.addProject(simpleProjectDelegate);
143 return simpleProjectDelegate;
147 * @param {string} url
148 * @param {!WebInspector.ContentProvider} contentProvider
149 * @param {boolean} isEditable
150 * @param {boolean=} isContentScript
151 * @return {!WebInspector.UISourceCode}
153 addFileForURL: function(url, contentProvider, isEditable, isContentScript)
155 return this._innerAddFileForURL(url, contentProvider, isEditable, false, isContentScript);
159 * @param {string} url
160 * @param {!WebInspector.ContentProvider} contentProvider
161 * @param {boolean} isEditable
162 * @param {boolean=} isContentScript
163 * @return {!WebInspector.UISourceCode}
165 addUniqueFileForURL: function(url, contentProvider, isEditable, isContentScript)
167 return this._innerAddFileForURL(url, contentProvider, isEditable, true, isContentScript);
171 * @param {string} url
172 * @param {!WebInspector.ContentProvider} contentProvider
173 * @param {boolean} isEditable
174 * @param {boolean} forceUnique
175 * @param {boolean=} isContentScript
176 * @return {!WebInspector.UISourceCode}
178 _innerAddFileForURL: function(url, contentProvider, isEditable, forceUnique, isContentScript)
180 var splitURL = WebInspector.ParsedURL.splitURL(url);
181 var projectName = splitURL[0];
182 var parentPath = splitURL.slice(1, splitURL.length - 1).join("/");
183 var name = splitURL[splitURL.length - 1];
184 var projectDelegate = this._projectDelegate(projectName);
185 var path = projectDelegate.addFile(parentPath, name, forceUnique, url, contentProvider, isEditable, isContentScript);
186 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (this._workspace.uiSourceCode(projectDelegate.id(), path));
187 console.assert(uiSourceCode);
193 for (var projectName in this._simpleProjectDelegates)
194 this._simpleProjectDelegates[projectName].reset();
195 this._simpleProjectDelegates = {};
198 __proto__: WebInspector.Object.prototype