| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 |
| 11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. | 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
| 17 * | 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 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 | |
| 31 /** | 30 /** |
| 32 * @interface | 31 * @interface |
| 33 */ | 32 */ |
| 34 WebInspector.ProjectSearchConfig = function() {}; | 33 WebInspector.ProjectSearchConfig = function() {}; |
| 35 | 34 |
| 36 WebInspector.ProjectSearchConfig.prototype = { | 35 WebInspector.ProjectSearchConfig.prototype = { |
| 37 /** | 36 /** |
| 38 * @return {string} | 37 * @return {string} |
| 39 */ | 38 */ |
| 40 query: function() { }, | 39 query: function() {}, |
| 41 | 40 |
| 42 /** | 41 /** |
| 43 * @return {boolean} | 42 * @return {boolean} |
| 44 */ | 43 */ |
| 45 ignoreCase: function() { }, | 44 ignoreCase: function() {}, |
| 46 | 45 |
| 47 /** | 46 /** |
| 48 * @return {boolean} | 47 * @return {boolean} |
| 49 */ | 48 */ |
| 50 isRegex: function() { }, | 49 isRegex: function() {}, |
| 51 | 50 |
| 52 /** | 51 /** |
| 53 * @return {!Array.<string>} | 52 * @return {!Array.<string>} |
| 54 */ | 53 */ |
| 55 queries: function() { }, | 54 queries: function() {}, |
| 56 | 55 |
| 57 /** | 56 /** |
| 58 * @param {string} filePath | 57 * @param {string} filePath |
| 59 * @return {boolean} | 58 * @return {boolean} |
| 60 */ | 59 */ |
| 61 filePathMatchesFileQuery: function(filePath) { } | 60 filePathMatchesFileQuery: function(filePath) {} |
| 62 }; | 61 }; |
| 63 | 62 |
| 64 /** | 63 /** |
| 65 * @interface | 64 * @interface |
| 66 */ | 65 */ |
| 67 WebInspector.Project = function() { }; | 66 WebInspector.Project = function() {}; |
| 68 | 67 |
| 69 /** | 68 /** |
| 70 * @param {!WebInspector.Project} project | 69 * @param {!WebInspector.Project} project |
| 71 * @return {boolean} | 70 * @return {boolean} |
| 72 */ | 71 */ |
| 73 WebInspector.Project.isServiceProject = function(project) | 72 WebInspector.Project.isServiceProject = function(project) { |
| 74 { | 73 return project.type() === WebInspector.projectTypes.Debugger || |
| 75 return project.type() === WebInspector.projectTypes.Debugger || project.type
() === WebInspector.projectTypes.Formatter || project.type() === WebInspector.pr
ojectTypes.Service; | 74 project.type() === WebInspector.projectTypes.Formatter || project.type() =
== WebInspector.projectTypes.Service; |
| 76 }; | 75 }; |
| 77 | 76 |
| 78 WebInspector.Project.prototype = { | 77 WebInspector.Project.prototype = { |
| 79 /** | 78 /** |
| 80 * @return {!WebInspector.Workspace} | 79 * @return {!WebInspector.Workspace} |
| 81 */ | 80 */ |
| 82 workspace: function() { }, | 81 workspace: function() {}, |
| 83 | 82 |
| 84 /** | 83 /** |
| 85 * @return {string} | 84 * @return {string} |
| 86 */ | 85 */ |
| 87 id: function() { }, | 86 id: function() {}, |
| 88 | 87 |
| 89 /** | 88 /** |
| 90 * @return {string} | 89 * @return {string} |
| 91 */ | 90 */ |
| 92 type: function() { }, | 91 type: function() {}, |
| 93 | 92 |
| 94 /** | 93 /** |
| 95 * @return {string} | 94 * @return {string} |
| 96 */ | 95 */ |
| 97 displayName: function() { }, | 96 displayName: function() {}, |
| 98 | 97 |
| 99 /** | 98 /** |
| 100 * @param {!WebInspector.UISourceCode} uiSourceCode | 99 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 101 * @return {!Promise<?WebInspector.UISourceCodeMetadata>} | 100 * @return {!Promise<?WebInspector.UISourceCodeMetadata>} |
| 102 */ | 101 */ |
| 103 requestMetadata: function(uiSourceCode) { }, | 102 requestMetadata: function(uiSourceCode) {}, |
| 104 | 103 |
| 105 /** | 104 /** |
| 106 * @param {!WebInspector.UISourceCode} uiSourceCode | 105 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 107 * @param {function(?string)} callback | 106 * @param {function(?string)} callback |
| 108 */ | 107 */ |
| 109 requestFileContent: function(uiSourceCode, callback) { }, | 108 requestFileContent: function(uiSourceCode, callback) {}, |
| 110 | 109 |
| 111 /** | 110 /** |
| 112 * @return {boolean} | 111 * @return {boolean} |
| 113 */ | 112 */ |
| 114 canSetFileContent: function() { }, | 113 canSetFileContent: function() {}, |
| 115 | 114 |
| 116 /** | 115 /** |
| 117 * @param {!WebInspector.UISourceCode} uiSourceCode | 116 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 118 * @param {string} newContent | 117 * @param {string} newContent |
| 119 * @param {function(?string)} callback | 118 * @param {function(?string)} callback |
| 120 */ | 119 */ |
| 121 setFileContent: function(uiSourceCode, newContent, callback) { }, | 120 setFileContent: function(uiSourceCode, newContent, callback) {}, |
| 122 | 121 |
| 123 /** | 122 /** |
| 124 * @return {boolean} | 123 * @return {boolean} |
| 125 */ | 124 */ |
| 126 canRename: function() { }, | 125 canRename: function() {}, |
| 127 | 126 |
| 128 /** | 127 /** |
| 129 * @param {!WebInspector.UISourceCode} uiSourceCode | 128 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 130 * @param {string} newName | 129 * @param {string} newName |
| 131 * @param {function(boolean, string=, string=, !WebInspector.ResourceType=)}
callback | 130 * @param {function(boolean, string=, string=, !WebInspector.ResourceType=)} c
allback |
| 132 */ | 131 */ |
| 133 rename: function(uiSourceCode, newName, callback) { }, | 132 rename: function(uiSourceCode, newName, callback) {}, |
| 134 | 133 |
| 135 /** | 134 /** |
| 136 * @param {string} path | 135 * @param {string} path |
| 137 */ | 136 */ |
| 138 excludeFolder: function(path) { }, | 137 excludeFolder: function(path) {}, |
| 139 | 138 |
| 140 /** | 139 /** |
| 141 * @param {string} path | 140 * @param {string} path |
| 142 * @param {?string} name | 141 * @param {?string} name |
| 143 * @param {string} content | 142 * @param {string} content |
| 144 * @param {function(?WebInspector.UISourceCode)} callback | 143 * @param {function(?WebInspector.UISourceCode)} callback |
| 145 */ | 144 */ |
| 146 createFile: function(path, name, content, callback) { }, | 145 createFile: function(path, name, content, callback) {}, |
| 147 | 146 |
| 148 /** | 147 /** |
| 149 * @param {string} path | 148 * @param {string} path |
| 150 */ | 149 */ |
| 151 deleteFile: function(path) { }, | 150 deleteFile: function(path) {}, |
| 152 | 151 |
| 153 remove: function() { }, | 152 remove: function() {}, |
| 154 | 153 |
| 155 /** | 154 /** |
| 156 * @param {!WebInspector.UISourceCode} uiSourceCode | 155 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 157 * @param {string} query | 156 * @param {string} query |
| 158 * @param {boolean} caseSensitive | 157 * @param {boolean} caseSensitive |
| 159 * @param {boolean} isRegex | 158 * @param {boolean} isRegex |
| 160 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} cal
lback | 159 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} callb
ack |
| 161 */ | 160 */ |
| 162 searchInFileContent: function(uiSourceCode, query, caseSensitive, isRegex, c
allback) { }, | 161 searchInFileContent: function(uiSourceCode, query, caseSensitive, isRegex, cal
lback) {}, |
| 163 | 162 |
| 164 /** | 163 /** |
| 165 * @param {!WebInspector.ProjectSearchConfig} searchConfig | 164 * @param {!WebInspector.ProjectSearchConfig} searchConfig |
| 166 * @param {!Array.<string>} filesMathingFileQuery | 165 * @param {!Array.<string>} filesMathingFileQuery |
| 167 * @param {!WebInspector.Progress} progress | 166 * @param {!WebInspector.Progress} progress |
| 168 * @param {function(!Array.<string>)} callback | 167 * @param {function(!Array.<string>)} callback |
| 169 */ | 168 */ |
| 170 findFilesMatchingSearchRequest: function(searchConfig, filesMathingFileQuery
, progress, callback) { }, | 169 findFilesMatchingSearchRequest: function(searchConfig, filesMathingFileQuery,
progress, callback) {}, |
| 171 | 170 |
| 172 /** | 171 /** |
| 173 * @param {!WebInspector.Progress} progress | 172 * @param {!WebInspector.Progress} progress |
| 174 */ | 173 */ |
| 175 indexContent: function(progress) { }, | 174 indexContent: function(progress) {}, |
| 176 | 175 |
| 177 /** | 176 /** |
| 178 * @param {string} url | 177 * @param {string} url |
| 179 * @return {?WebInspector.UISourceCode} | 178 * @return {?WebInspector.UISourceCode} |
| 180 */ | 179 */ |
| 181 uiSourceCodeForURL: function(url) { }, | 180 uiSourceCodeForURL: function(url) {}, |
| 182 | 181 |
| 183 /** | 182 /** |
| 184 * @return {!Array.<!WebInspector.UISourceCode>} | 183 * @return {!Array.<!WebInspector.UISourceCode>} |
| 185 */ | 184 */ |
| 186 uiSourceCodes: function() { } | 185 uiSourceCodes: function() {} |
| 187 }; | 186 }; |
| 188 | 187 |
| 189 /** | 188 /** |
| 190 * @enum {string} | 189 * @enum {string} |
| 191 */ | 190 */ |
| 192 WebInspector.projectTypes = { | 191 WebInspector.projectTypes = { |
| 193 Debugger: "debugger", | 192 Debugger: 'debugger', |
| 194 Formatter: "formatter", | 193 Formatter: 'formatter', |
| 195 Network: "network", | 194 Network: 'network', |
| 196 Snippets: "snippets", | 195 Snippets: 'snippets', |
| 197 FileSystem: "filesystem", | 196 FileSystem: 'filesystem', |
| 198 ContentScripts: "contentscripts", | 197 ContentScripts: 'contentscripts', |
| 199 Service: "service" | 198 Service: 'service' |
| 200 }; | 199 }; |
| 201 | 200 |
| 202 /** | 201 /** |
| 203 * @constructor | 202 * @unrestricted |
| 204 * @param {!WebInspector.Workspace} workspace | |
| 205 * @param {string} id | |
| 206 * @param {!WebInspector.projectTypes} type | |
| 207 * @param {string} displayName | |
| 208 */ | 203 */ |
| 209 WebInspector.ProjectStore = function(workspace, id, type, displayName) | 204 WebInspector.ProjectStore = class { |
| 210 { | 205 /** |
| 206 * @param {!WebInspector.Workspace} workspace |
| 207 * @param {string} id |
| 208 * @param {!WebInspector.projectTypes} type |
| 209 * @param {string} displayName |
| 210 */ |
| 211 constructor(workspace, id, type, displayName) { |
| 211 this._workspace = workspace; | 212 this._workspace = workspace; |
| 212 this._id = id; | 213 this._id = id; |
| 213 this._type = type; | 214 this._type = type; |
| 214 this._displayName = displayName; | 215 this._displayName = displayName; |
| 215 | 216 |
| 216 /** @type {!Map.<string, !{uiSourceCode: !WebInspector.UISourceCode, index:
number}>} */ | 217 /** @type {!Map.<string, !{uiSourceCode: !WebInspector.UISourceCode, index:
number}>} */ |
| 217 this._uiSourceCodesMap = new Map(); | 218 this._uiSourceCodesMap = new Map(); |
| 218 /** @type {!Array.<!WebInspector.UISourceCode>} */ | 219 /** @type {!Array.<!WebInspector.UISourceCode>} */ |
| 219 this._uiSourceCodesList = []; | 220 this._uiSourceCodesList = []; |
| 220 | 221 |
| 221 this._project = /** @type {!WebInspector.Project} */(this); | 222 this._project = /** @type {!WebInspector.Project} */ (this); |
| 223 } |
| 224 |
| 225 /** |
| 226 * @return {string} |
| 227 */ |
| 228 id() { |
| 229 return this._id; |
| 230 } |
| 231 |
| 232 /** |
| 233 * @return {string} |
| 234 */ |
| 235 type() { |
| 236 return this._type; |
| 237 } |
| 238 |
| 239 /** |
| 240 * @return {string} |
| 241 */ |
| 242 displayName() { |
| 243 return this._displayName; |
| 244 } |
| 245 |
| 246 /** |
| 247 * @return {!WebInspector.Workspace} |
| 248 */ |
| 249 workspace() { |
| 250 return this._workspace; |
| 251 } |
| 252 |
| 253 /** |
| 254 * @param {string} url |
| 255 * @param {!WebInspector.ResourceType} contentType |
| 256 * @return {!WebInspector.UISourceCode} |
| 257 */ |
| 258 createUISourceCode(url, contentType) { |
| 259 return new WebInspector.UISourceCode(this._project, url, contentType); |
| 260 } |
| 261 |
| 262 /** |
| 263 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 264 * @param {boolean=} replace |
| 265 * @return {boolean} |
| 266 */ |
| 267 addUISourceCode(uiSourceCode, replace) { |
| 268 var url = uiSourceCode.url(); |
| 269 if (this.uiSourceCodeForURL(url)) { |
| 270 if (replace) |
| 271 this.removeUISourceCode(url); |
| 272 else |
| 273 return false; |
| 274 } |
| 275 this._uiSourceCodesMap.set(url, {uiSourceCode: uiSourceCode, index: this._ui
SourceCodesList.length}); |
| 276 this._uiSourceCodesList.push(uiSourceCode); |
| 277 this._workspace.dispatchEventToListeners(WebInspector.Workspace.Events.UISou
rceCodeAdded, uiSourceCode); |
| 278 return true; |
| 279 } |
| 280 |
| 281 /** |
| 282 * @param {string} url |
| 283 */ |
| 284 removeUISourceCode(url) { |
| 285 var uiSourceCode = this.uiSourceCodeForURL(url); |
| 286 if (!uiSourceCode) |
| 287 return; |
| 288 |
| 289 var entry = this._uiSourceCodesMap.get(url); |
| 290 var movedUISourceCode = this._uiSourceCodesList[this._uiSourceCodesList.leng
th - 1]; |
| 291 this._uiSourceCodesList[entry.index] = movedUISourceCode; |
| 292 var movedEntry = this._uiSourceCodesMap.get(movedUISourceCode.url()); |
| 293 movedEntry.index = entry.index; |
| 294 this._uiSourceCodesList.splice(this._uiSourceCodesList.length - 1, 1); |
| 295 this._uiSourceCodesMap.delete(url); |
| 296 this._workspace.dispatchEventToListeners(WebInspector.Workspace.Events.UISou
rceCodeRemoved, entry.uiSourceCode); |
| 297 } |
| 298 |
| 299 removeProject() { |
| 300 this._workspace._removeProject(this._project); |
| 301 this._uiSourceCodesMap = new Map(); |
| 302 this._uiSourceCodesList = []; |
| 303 } |
| 304 |
| 305 /** |
| 306 * @param {string} url |
| 307 * @return {?WebInspector.UISourceCode} |
| 308 */ |
| 309 uiSourceCodeForURL(url) { |
| 310 var entry = this._uiSourceCodesMap.get(url); |
| 311 return entry ? entry.uiSourceCode : null; |
| 312 } |
| 313 |
| 314 /** |
| 315 * @return {!Array.<!WebInspector.UISourceCode>} |
| 316 */ |
| 317 uiSourceCodes() { |
| 318 return this._uiSourceCodesList; |
| 319 } |
| 320 |
| 321 /** |
| 322 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 323 * @param {string} newName |
| 324 */ |
| 325 renameUISourceCode(uiSourceCode, newName) { |
| 326 var oldPath = uiSourceCode.url(); |
| 327 var newPath = uiSourceCode.parentURL() ? uiSourceCode.parentURL() + '/' + ne
wName : newName; |
| 328 var value = |
| 329 /** @type {!{uiSourceCode: !WebInspector.UISourceCode, index: number}} *
/ (this._uiSourceCodesMap.get(oldPath)); |
| 330 this._uiSourceCodesMap.set(newPath, value); |
| 331 this._uiSourceCodesMap.delete(oldPath); |
| 332 } |
| 222 }; | 333 }; |
| 223 | 334 |
| 224 WebInspector.ProjectStore.prototype = { | |
| 225 /** | |
| 226 * @return {string} | |
| 227 */ | |
| 228 id: function() | |
| 229 { | |
| 230 return this._id; | |
| 231 }, | |
| 232 | |
| 233 /** | |
| 234 * @return {string} | |
| 235 */ | |
| 236 type: function() | |
| 237 { | |
| 238 return this._type; | |
| 239 }, | |
| 240 | |
| 241 /** | |
| 242 * @return {string} | |
| 243 */ | |
| 244 displayName: function() | |
| 245 { | |
| 246 return this._displayName; | |
| 247 }, | |
| 248 | |
| 249 /** | |
| 250 * @return {!WebInspector.Workspace} | |
| 251 */ | |
| 252 workspace: function() | |
| 253 { | |
| 254 return this._workspace; | |
| 255 }, | |
| 256 | |
| 257 /** | |
| 258 * @param {string} url | |
| 259 * @param {!WebInspector.ResourceType} contentType | |
| 260 * @return {!WebInspector.UISourceCode} | |
| 261 */ | |
| 262 createUISourceCode: function(url, contentType) | |
| 263 { | |
| 264 return new WebInspector.UISourceCode(this._project, url, contentType); | |
| 265 }, | |
| 266 | |
| 267 /** | |
| 268 * @param {!WebInspector.UISourceCode} uiSourceCode | |
| 269 * @param {boolean=} replace | |
| 270 * @return {boolean} | |
| 271 */ | |
| 272 addUISourceCode: function(uiSourceCode, replace) | |
| 273 { | |
| 274 var url = uiSourceCode.url(); | |
| 275 if (this.uiSourceCodeForURL(url)) { | |
| 276 if (replace) | |
| 277 this.removeUISourceCode(url); | |
| 278 else | |
| 279 return false; | |
| 280 } | |
| 281 this._uiSourceCodesMap.set(url, {uiSourceCode: uiSourceCode, index: this
._uiSourceCodesList.length}); | |
| 282 this._uiSourceCodesList.push(uiSourceCode); | |
| 283 this._workspace.dispatchEventToListeners(WebInspector.Workspace.Events.U
ISourceCodeAdded, uiSourceCode); | |
| 284 return true; | |
| 285 }, | |
| 286 | |
| 287 /** | |
| 288 * @param {string} url | |
| 289 */ | |
| 290 removeUISourceCode: function(url) | |
| 291 { | |
| 292 var uiSourceCode = this.uiSourceCodeForURL(url); | |
| 293 if (!uiSourceCode) | |
| 294 return; | |
| 295 | |
| 296 var entry = this._uiSourceCodesMap.get(url); | |
| 297 var movedUISourceCode = this._uiSourceCodesList[this._uiSourceCodesList.
length - 1]; | |
| 298 this._uiSourceCodesList[entry.index] = movedUISourceCode; | |
| 299 var movedEntry = this._uiSourceCodesMap.get(movedUISourceCode.url()); | |
| 300 movedEntry.index = entry.index; | |
| 301 this._uiSourceCodesList.splice(this._uiSourceCodesList.length - 1, 1); | |
| 302 this._uiSourceCodesMap.delete(url); | |
| 303 this._workspace.dispatchEventToListeners(WebInspector.Workspace.Events.U
ISourceCodeRemoved, entry.uiSourceCode); | |
| 304 }, | |
| 305 | |
| 306 removeProject: function() | |
| 307 { | |
| 308 this._workspace._removeProject(this._project); | |
| 309 this._uiSourceCodesMap = new Map(); | |
| 310 this._uiSourceCodesList = []; | |
| 311 }, | |
| 312 | |
| 313 /** | |
| 314 * @param {string} url | |
| 315 * @return {?WebInspector.UISourceCode} | |
| 316 */ | |
| 317 uiSourceCodeForURL: function(url) | |
| 318 { | |
| 319 var entry = this._uiSourceCodesMap.get(url); | |
| 320 return entry ? entry.uiSourceCode : null; | |
| 321 }, | |
| 322 | |
| 323 /** | |
| 324 * @return {!Array.<!WebInspector.UISourceCode>} | |
| 325 */ | |
| 326 uiSourceCodes: function() | |
| 327 { | |
| 328 return this._uiSourceCodesList; | |
| 329 }, | |
| 330 | |
| 331 /** | |
| 332 * @param {!WebInspector.UISourceCode} uiSourceCode | |
| 333 * @param {string} newName | |
| 334 */ | |
| 335 renameUISourceCode: function(uiSourceCode, newName) | |
| 336 { | |
| 337 var oldPath = uiSourceCode.url(); | |
| 338 var newPath = uiSourceCode.parentURL() ? uiSourceCode.parentURL() + "/"
+ newName : newName; | |
| 339 var value = /** @type {!{uiSourceCode: !WebInspector.UISourceCode, index
: number}} */ (this._uiSourceCodesMap.get(oldPath)); | |
| 340 this._uiSourceCodesMap.set(newPath, value); | |
| 341 this._uiSourceCodesMap.delete(oldPath); | |
| 342 } | |
| 343 }; | |
| 344 | |
| 345 /** | 335 /** |
| 346 * @constructor | 336 * @unrestricted |
| 347 * @extends {WebInspector.Object} | |
| 348 */ | 337 */ |
| 349 WebInspector.Workspace = function() | 338 WebInspector.Workspace = class extends WebInspector.Object { |
| 350 { | 339 constructor() { |
| 340 super(); |
| 351 /** @type {!Map<string, !WebInspector.Project>} */ | 341 /** @type {!Map<string, !WebInspector.Project>} */ |
| 352 this._projects = new Map(); | 342 this._projects = new Map(); |
| 353 this._hasResourceContentTrackingExtensions = false; | 343 this._hasResourceContentTrackingExtensions = false; |
| 344 } |
| 345 |
| 346 /** |
| 347 * @param {string} projectId |
| 348 * @param {string} url |
| 349 * @return {?WebInspector.UISourceCode} |
| 350 */ |
| 351 uiSourceCode(projectId, url) { |
| 352 var project = this._projects.get(projectId); |
| 353 return project ? project.uiSourceCodeForURL(url) : null; |
| 354 } |
| 355 |
| 356 /** |
| 357 * @param {string} url |
| 358 * @return {?WebInspector.UISourceCode} |
| 359 */ |
| 360 uiSourceCodeForURL(url) { |
| 361 for (var project of this._projects.values()) { |
| 362 var uiSourceCode = project.uiSourceCodeForURL(url); |
| 363 if (uiSourceCode) |
| 364 return uiSourceCode; |
| 365 } |
| 366 return null; |
| 367 } |
| 368 |
| 369 /** |
| 370 * @param {string} type |
| 371 * @return {!Array.<!WebInspector.UISourceCode>} |
| 372 */ |
| 373 uiSourceCodesForProjectType(type) { |
| 374 var result = []; |
| 375 for (var project of this._projects.values()) { |
| 376 if (project.type() === type) |
| 377 result = result.concat(project.uiSourceCodes()); |
| 378 } |
| 379 return result; |
| 380 } |
| 381 |
| 382 /** |
| 383 * @param {!WebInspector.Project} project |
| 384 */ |
| 385 addProject(project) { |
| 386 console.assert(!this._projects.has(project.id()), `A project with id ${proje
ct.id()} already exists!`); |
| 387 this._projects.set(project.id(), project); |
| 388 this.dispatchEventToListeners(WebInspector.Workspace.Events.ProjectAdded, pr
oject); |
| 389 } |
| 390 |
| 391 /** |
| 392 * @param {!WebInspector.Project} project |
| 393 */ |
| 394 _removeProject(project) { |
| 395 this._projects.delete(project.id()); |
| 396 this.dispatchEventToListeners(WebInspector.Workspace.Events.ProjectRemoved,
project); |
| 397 } |
| 398 |
| 399 /** |
| 400 * @param {string} projectId |
| 401 * @return {?WebInspector.Project} |
| 402 */ |
| 403 project(projectId) { |
| 404 return this._projects.get(projectId) || null; |
| 405 } |
| 406 |
| 407 /** |
| 408 * @return {!Array.<!WebInspector.Project>} |
| 409 */ |
| 410 projects() { |
| 411 return this._projects.valuesArray(); |
| 412 } |
| 413 |
| 414 /** |
| 415 * @param {string} type |
| 416 * @return {!Array.<!WebInspector.Project>} |
| 417 */ |
| 418 projectsForType(type) { |
| 419 function filterByType(project) { |
| 420 return project.type() === type; |
| 421 } |
| 422 return this.projects().filter(filterByType); |
| 423 } |
| 424 |
| 425 /** |
| 426 * @return {!Array.<!WebInspector.UISourceCode>} |
| 427 */ |
| 428 uiSourceCodes() { |
| 429 var result = []; |
| 430 for (var project of this._projects.values()) |
| 431 result = result.concat(project.uiSourceCodes()); |
| 432 return result; |
| 433 } |
| 434 |
| 435 /** |
| 436 * @param {boolean} hasExtensions |
| 437 */ |
| 438 setHasResourceContentTrackingExtensions(hasExtensions) { |
| 439 this._hasResourceContentTrackingExtensions = hasExtensions; |
| 440 } |
| 441 |
| 442 /** |
| 443 * @return {boolean} |
| 444 */ |
| 445 hasResourceContentTrackingExtensions() { |
| 446 return this._hasResourceContentTrackingExtensions; |
| 447 } |
| 354 }; | 448 }; |
| 355 | 449 |
| 356 /** @enum {symbol} */ | 450 /** @enum {symbol} */ |
| 357 WebInspector.Workspace.Events = { | 451 WebInspector.Workspace.Events = { |
| 358 UISourceCodeAdded: Symbol("UISourceCodeAdded"), | 452 UISourceCodeAdded: Symbol('UISourceCodeAdded'), |
| 359 UISourceCodeRemoved: Symbol("UISourceCodeRemoved"), | 453 UISourceCodeRemoved: Symbol('UISourceCodeRemoved'), |
| 360 WorkingCopyChanged: Symbol("WorkingCopyChanged"), | 454 WorkingCopyChanged: Symbol('WorkingCopyChanged'), |
| 361 WorkingCopyCommitted: Symbol("WorkingCopyCommitted"), | 455 WorkingCopyCommitted: Symbol('WorkingCopyCommitted'), |
| 362 WorkingCopyCommittedByUser: Symbol("WorkingCopyCommittedByUser"), | 456 WorkingCopyCommittedByUser: Symbol('WorkingCopyCommittedByUser'), |
| 363 ProjectAdded: Symbol("ProjectAdded"), | 457 ProjectAdded: Symbol('ProjectAdded'), |
| 364 ProjectRemoved: Symbol("ProjectRemoved") | 458 ProjectRemoved: Symbol('ProjectRemoved') |
| 365 }; | 459 }; |
| 366 | 460 |
| 367 WebInspector.Workspace.prototype = { | |
| 368 /** | |
| 369 * @param {string} projectId | |
| 370 * @param {string} url | |
| 371 * @return {?WebInspector.UISourceCode} | |
| 372 */ | |
| 373 uiSourceCode: function(projectId, url) | |
| 374 { | |
| 375 var project = this._projects.get(projectId); | |
| 376 return project ? project.uiSourceCodeForURL(url) : null; | |
| 377 }, | |
| 378 | |
| 379 /** | |
| 380 * @param {string} url | |
| 381 * @return {?WebInspector.UISourceCode} | |
| 382 */ | |
| 383 uiSourceCodeForURL: function(url) | |
| 384 { | |
| 385 for (var project of this._projects.values()) { | |
| 386 var uiSourceCode = project.uiSourceCodeForURL(url); | |
| 387 if (uiSourceCode) | |
| 388 return uiSourceCode; | |
| 389 } | |
| 390 return null; | |
| 391 }, | |
| 392 | |
| 393 /** | |
| 394 * @param {string} type | |
| 395 * @return {!Array.<!WebInspector.UISourceCode>} | |
| 396 */ | |
| 397 uiSourceCodesForProjectType: function(type) | |
| 398 { | |
| 399 var result = []; | |
| 400 for (var project of this._projects.values()) { | |
| 401 if (project.type() === type) | |
| 402 result = result.concat(project.uiSourceCodes()); | |
| 403 } | |
| 404 return result; | |
| 405 }, | |
| 406 | |
| 407 /** | |
| 408 * @param {!WebInspector.Project} project | |
| 409 */ | |
| 410 addProject: function(project) | |
| 411 { | |
| 412 console.assert(!this._projects.has(project.id()), `A project with id ${p
roject.id()} already exists!`); | |
| 413 this._projects.set(project.id(), project); | |
| 414 this.dispatchEventToListeners(WebInspector.Workspace.Events.ProjectAdded
, project); | |
| 415 }, | |
| 416 | |
| 417 /** | |
| 418 * @param {!WebInspector.Project} project | |
| 419 */ | |
| 420 _removeProject: function(project) | |
| 421 { | |
| 422 this._projects.delete(project.id()); | |
| 423 this.dispatchEventToListeners(WebInspector.Workspace.Events.ProjectRemov
ed, project); | |
| 424 }, | |
| 425 | |
| 426 /** | |
| 427 * @param {string} projectId | |
| 428 * @return {?WebInspector.Project} | |
| 429 */ | |
| 430 project: function(projectId) | |
| 431 { | |
| 432 return this._projects.get(projectId) || null; | |
| 433 }, | |
| 434 | |
| 435 /** | |
| 436 * @return {!Array.<!WebInspector.Project>} | |
| 437 */ | |
| 438 projects: function() | |
| 439 { | |
| 440 return this._projects.valuesArray(); | |
| 441 }, | |
| 442 | |
| 443 /** | |
| 444 * @param {string} type | |
| 445 * @return {!Array.<!WebInspector.Project>} | |
| 446 */ | |
| 447 projectsForType: function(type) | |
| 448 { | |
| 449 function filterByType(project) | |
| 450 { | |
| 451 return project.type() === type; | |
| 452 } | |
| 453 return this.projects().filter(filterByType); | |
| 454 }, | |
| 455 | |
| 456 /** | |
| 457 * @return {!Array.<!WebInspector.UISourceCode>} | |
| 458 */ | |
| 459 uiSourceCodes: function() | |
| 460 { | |
| 461 var result = []; | |
| 462 for (var project of this._projects.values()) | |
| 463 result = result.concat(project.uiSourceCodes()); | |
| 464 return result; | |
| 465 }, | |
| 466 | |
| 467 /** | |
| 468 * @param {boolean} hasExtensions | |
| 469 */ | |
| 470 setHasResourceContentTrackingExtensions: function(hasExtensions) | |
| 471 { | |
| 472 this._hasResourceContentTrackingExtensions = hasExtensions; | |
| 473 }, | |
| 474 | |
| 475 /** | |
| 476 * @return {boolean} | |
| 477 */ | |
| 478 hasResourceContentTrackingExtensions: function() | |
| 479 { | |
| 480 return this._hasResourceContentTrackingExtensions; | |
| 481 }, | |
| 482 | |
| 483 __proto__: WebInspector.Object.prototype | |
| 484 }; | |
| 485 | |
| 486 /** | 461 /** |
| 487 * @type {!WebInspector.Workspace} | 462 * @type {!WebInspector.Workspace} |
| 488 */ | 463 */ |
| 489 WebInspector.workspace; | 464 WebInspector.workspace; |
| OLD | NEW |