Chromium Code Reviews| 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 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * | 10 * |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 | 36 |
| 37 var scriptsOutlineElement = this.element.createChild("div", "navigator"); | 37 var scriptsOutlineElement = this.element.createChild("div", "navigator"); |
| 38 this._scriptsTree = new TreeOutlineInShadow(); | 38 this._scriptsTree = new TreeOutlineInShadow(); |
| 39 this._scriptsTree.registerRequiredCSS("sources/navigatorView.css"); | 39 this._scriptsTree.registerRequiredCSS("sources/navigatorView.css"); |
| 40 this._scriptsTree.setComparator(WebInspector.NavigatorView._treeElementsComp are); | 40 this._scriptsTree.setComparator(WebInspector.NavigatorView._treeElementsComp are); |
| 41 this.element.appendChild(this._scriptsTree.element); | 41 this.element.appendChild(this._scriptsTree.element); |
| 42 this.setDefaultFocusedElement(this._scriptsTree.element); | 42 this.setDefaultFocusedElement(this._scriptsTree.element); |
| 43 | 43 |
| 44 /** @type {!Map.<!WebInspector.UISourceCode, !WebInspector.NavigatorUISource CodeTreeNode>} */ | 44 /** @type {!Map.<!WebInspector.UISourceCode, !WebInspector.NavigatorUISource CodeTreeNode>} */ |
| 45 this._uiSourceCodeNodes = new Map(); | 45 this._uiSourceCodeNodes = new Map(); |
| 46 /** @type {!Map.<!WebInspector.NavigatorTreeNode, !Map.<string, !WebInspecto r.NavigatorFolderTreeNode>>} */ | 46 /** @type {!Map.<string, !WebInspector.NavigatorFolderTreeNode>} */ |
| 47 this._subfolderNodes = new Map(); | 47 this._subfolderNodes = new Map(); |
| 48 | 48 |
| 49 this._rootNode = new WebInspector.NavigatorRootTreeNode(this); | 49 this._rootNode = new WebInspector.NavigatorRootTreeNode(this); |
| 50 this._rootNode.populate(); | 50 this._rootNode.populate(); |
| 51 | 51 |
| 52 this.element.addEventListener("contextmenu", this.handleContextMenu.bind(thi s), false); | 52 this.element.addEventListener("contextmenu", this.handleContextMenu.bind(thi s), false); |
| 53 } | 53 } |
| 54 | 54 |
| 55 WebInspector.NavigatorView.Events = { | 55 WebInspector.NavigatorView.Events = { |
| 56 ItemSelected: "ItemSelected", | 56 ItemSelected: "ItemSelected", |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 }, | 108 }, |
| 109 | 109 |
| 110 /** | 110 /** |
| 111 * @param {!WebInspector.UISourceCode} uiSourceCode | 111 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 112 */ | 112 */ |
| 113 _addUISourceCode: function(uiSourceCode) | 113 _addUISourceCode: function(uiSourceCode) |
| 114 { | 114 { |
| 115 if (!this.accept(uiSourceCode)) | 115 if (!this.accept(uiSourceCode)) |
| 116 return; | 116 return; |
| 117 var isFromSourceMap = uiSourceCode.contentType().isFromSourceMap(); | 117 var isFromSourceMap = uiSourceCode.contentType().isFromSourceMap(); |
| 118 var projectNode = this._projectNode(uiSourceCode.project(), isFromSource Map); | 118 var path = WebInspector.ParsedURL.splitURLIntoPathComponents(uiSourceCod e.path()); |
| 119 var folderNode = this._folderNode(projectNode, uiSourceCode.parentPath() , isFromSourceMap); | 119 var folderNode = this._folderNode(uiSourceCode.project(), path.slice(0, -1), isFromSourceMap); |
| 120 var uiSourceCodeNode = new WebInspector.NavigatorUISourceCodeTreeNode(th is, uiSourceCode); | 120 var uiSourceCodeNode = new WebInspector.NavigatorUISourceCodeTreeNode(th is, uiSourceCode); |
| 121 this._uiSourceCodeNodes.set(uiSourceCode, uiSourceCodeNode); | 121 this._uiSourceCodeNodes.set(uiSourceCode, uiSourceCodeNode); |
| 122 folderNode.appendChild(uiSourceCodeNode); | 122 folderNode.appendChild(uiSourceCodeNode); |
| 123 }, | 123 }, |
| 124 | 124 |
| 125 /** | 125 /** |
| 126 * @param {!WebInspector.Event} event | 126 * @param {!WebInspector.Event} event |
| 127 */ | 127 */ |
| 128 _uiSourceCodeAdded: function(event) | 128 _uiSourceCodeAdded: function(event) |
| 129 { | 129 { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 145 */ | 145 */ |
| 146 _projectRemoved: function(event) | 146 _projectRemoved: function(event) |
| 147 { | 147 { |
| 148 var project = /** @type {!WebInspector.Project} */ (event.data); | 148 var project = /** @type {!WebInspector.Project} */ (event.data); |
| 149 var uiSourceCodes = project.uiSourceCodes(); | 149 var uiSourceCodes = project.uiSourceCodes(); |
| 150 for (var i = 0; i < uiSourceCodes.length; ++i) | 150 for (var i = 0; i < uiSourceCodes.length; ++i) |
| 151 this._removeUISourceCode(uiSourceCodes[i]); | 151 this._removeUISourceCode(uiSourceCodes[i]); |
| 152 }, | 152 }, |
| 153 | 153 |
| 154 /** | 154 /** |
| 155 * @param {!WebInspector.Project} project | 155 * @param {!WebInspector.Project} project |
|
dgozman
2015/12/15 22:22:47
indentation off
pfeldman
2015/12/16 01:34:28
Done.
| |
| 156 * @param {boolean} isFromSourceMap | 156 * @param {!Array<string>} path |
| 157 * @return {!WebInspector.NavigatorTreeNode} | |
| 158 */ | |
| 159 _projectNode: function(project, isFromSourceMap) | |
| 160 { | |
| 161 if (!project.displayName()) | |
| 162 return this._rootNode; | |
| 163 | |
| 164 var projectNode = this._rootNode.child(project.id()); | |
| 165 if (!projectNode) { | |
| 166 projectNode = this._createProjectNode(project, isFromSourceMap); | |
| 167 this._rootNode.appendChild(projectNode); | |
| 168 } | |
| 169 return projectNode; | |
| 170 }, | |
| 171 | |
| 172 /** | |
| 173 * @param {!WebInspector.Project} project | |
| 174 * @param {boolean} isFromSourceMap | |
| 175 * @return {!WebInspector.NavigatorTreeNode} | |
| 176 */ | |
| 177 _createProjectNode: function(project, isFromSourceMap) | |
| 178 { | |
| 179 var type; | |
| 180 if (isFromSourceMap) | |
| 181 type = WebInspector.NavigatorView.Types.SourceMapFolder; | |
| 182 else | |
| 183 type = project.type() === WebInspector.projectTypes.FileSystem ? Web Inspector.NavigatorView.Types.FileSystem : WebInspector.NavigatorView.Types.Doma in; | |
| 184 var projectNode = new WebInspector.NavigatorFolderTreeNode(this, project , project.id(), type, "", project.displayName()); | |
| 185 return projectNode; | |
| 186 }, | |
| 187 | |
| 188 /** | |
| 189 * @param {!WebInspector.NavigatorTreeNode} projectNode | |
| 190 * @param {string} folderPath | |
| 191 * @param {boolean} fromSourceMap | 157 * @param {boolean} fromSourceMap |
| 192 * @return {!WebInspector.NavigatorTreeNode} | 158 * @return {!WebInspector.NavigatorTreeNode} |
| 193 */ | 159 */ |
| 194 _folderNode: function(projectNode, folderPath, fromSourceMap) | 160 _folderNode: function(project, path, fromSourceMap) |
| 195 { | 161 { |
| 196 if (!folderPath) | 162 var folderPath = path.join("/"); |
| 197 return projectNode; | |
| 198 | 163 |
| 199 var subfolderNodes = this._subfolderNodes.get(projectNode); | 164 var folderNode = this._subfolderNodes.get(folderPath); |
| 200 if (!subfolderNodes) { | |
| 201 subfolderNodes = /** @type {!Map.<string, !WebInspector.NavigatorFol derTreeNode>} */ (new Map()); | |
| 202 this._subfolderNodes.set(projectNode, subfolderNodes); | |
| 203 } | |
| 204 | |
| 205 var folderNode = subfolderNodes.get(folderPath); | |
| 206 if (folderNode) | 165 if (folderNode) |
| 207 return folderNode; | 166 return folderNode; |
| 208 | 167 |
| 209 var parentNode = projectNode; | 168 if (path.length === 1 && path[0] === "file://") |
|
dgozman
2015/12/15 22:22:47
What is this for? Needs a comment.
pfeldman
2015/12/16 01:34:28
Done.
| |
| 210 var index = folderPath.lastIndexOf("/"); | 169 return this._rootNode; |
| 211 if (index !== -1) | |
| 212 parentNode = this._folderNode(projectNode, folderPath.substring(0, i ndex), fromSourceMap); | |
| 213 | 170 |
| 214 var name = folderPath.substring(index + 1); | 171 var parentNode = this._rootNode; |
| 215 folderNode = new WebInspector.NavigatorFolderTreeNode(this, null, name, fromSourceMap ? WebInspector.NavigatorView.Types.SourceMapFolder : WebInspector. NavigatorView.Types.Folder, folderPath, name); | 172 if (path.length > 1) |
| 216 subfolderNodes.set(folderPath, folderNode); | 173 parentNode = this._folderNode(project, path.slice(0, -1), fromSource Map); |
| 174 var type = fromSourceMap ? WebInspector.NavigatorView.Types.SourceMapFol der : WebInspector.NavigatorView.Types.Folder; | |
| 175 | |
| 176 var isFromNetwork = project.type() !== WebInspector.projectTypes.FileSys tem; | |
|
dgozman
2015/12/15 22:22:47
I'd rather call some NetworkProject method here.
pfeldman
2015/12/16 01:34:28
Done.
| |
| 177 var name = path[path.length - 1]; | |
| 178 if (parentNode === this._rootNode && isFromNetwork) { | |
| 179 type = WebInspector.NavigatorView.Types.Domain; | |
| 180 if (!name) | |
| 181 name = WebInspector.UIString("(no domain)"); | |
| 182 if (name.startsWith("http://")) | |
| 183 name = name.substring(7); | |
| 184 if (name.startsWith("https://")) | |
| 185 name = name.substring(8); | |
| 186 } | |
| 187 | |
| 188 folderNode = new WebInspector.NavigatorFolderTreeNode(this, null, folder Path, type, folderPath, name); | |
|
dgozman
2015/12/15 22:22:47
Why passing null as project?
dgozman
2015/12/15 22:22:47
3rd and 5th parameters are always equal. Remove on
pfeldman
2015/12/16 01:34:28
They are no longer equal.
pfeldman
2015/12/16 01:34:28
To preserve the behavior of context menu...
| |
| 189 this._subfolderNodes.set(folderPath, folderNode); | |
| 217 parentNode.appendChild(folderNode); | 190 parentNode.appendChild(folderNode); |
| 218 return folderNode; | 191 return folderNode; |
| 219 }, | 192 }, |
| 220 | 193 |
| 221 /** | 194 /** |
| 222 * @param {!WebInspector.UISourceCode} uiSourceCode | 195 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 223 * @param {boolean=} select | 196 * @param {boolean=} select |
| 224 */ | 197 */ |
| 225 revealUISourceCode: function(uiSourceCode, select) | 198 revealUISourceCode: function(uiSourceCode, select) |
| 226 { | 199 { |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 253 | 226 |
| 254 /** | 227 /** |
| 255 * @param {!WebInspector.UISourceCode} uiSourceCode | 228 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 256 */ | 229 */ |
| 257 _removeUISourceCode: function(uiSourceCode) | 230 _removeUISourceCode: function(uiSourceCode) |
| 258 { | 231 { |
| 259 var node = this._uiSourceCodeNodes.get(uiSourceCode); | 232 var node = this._uiSourceCodeNodes.get(uiSourceCode); |
| 260 if (!node) | 233 if (!node) |
| 261 return; | 234 return; |
| 262 | 235 |
| 263 var projectNode = this._projectNode(uiSourceCode.project(), false); | |
| 264 var subfolderNodes = this._subfolderNodes.get(projectNode); | |
| 265 var parentNode = node.parent; | 236 var parentNode = node.parent; |
| 266 this._uiSourceCodeNodes.remove(uiSourceCode); | 237 this._uiSourceCodeNodes.remove(uiSourceCode); |
| 267 parentNode.removeChild(node); | 238 parentNode.removeChild(node); |
| 268 node = parentNode; | 239 node = parentNode; |
| 269 | 240 |
| 270 while (node) { | 241 while (node) { |
| 271 parentNode = node.parent; | 242 parentNode = node.parent; |
| 272 if (!parentNode || !node.isEmpty()) | 243 if (!parentNode || !node.isEmpty()) |
| 273 break; | 244 break; |
| 274 if (subfolderNodes) | 245 this._subfolderNodes.remove(node._folderPath); |
| 275 subfolderNodes.remove(node._folderPath); | |
| 276 parentNode.removeChild(node); | 246 parentNode.removeChild(node); |
| 277 node = parentNode; | 247 node = parentNode; |
| 278 } | 248 } |
| 279 }, | 249 }, |
| 280 | 250 |
| 281 reset: function() | 251 reset: function() |
| 282 { | 252 { |
| 283 var nodes = this._uiSourceCodeNodes.valuesArray(); | 253 var nodes = this._uiSourceCodeNodes.valuesArray(); |
| 284 for (var i = 0; i < nodes.length; ++i) | 254 for (var i = 0; i < nodes.length; ++i) |
| 285 nodes[i].dispose(); | 255 nodes[i].dispose(); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 374 }, | 344 }, |
| 375 | 345 |
| 376 /** | 346 /** |
| 377 * @param {!Event} event | 347 * @param {!Event} event |
| 378 * @param {!WebInspector.NavigatorFolderTreeNode} node | 348 * @param {!WebInspector.NavigatorFolderTreeNode} node |
| 379 */ | 349 */ |
| 380 handleFolderContextMenu: function(event, node) | 350 handleFolderContextMenu: function(event, node) |
| 381 { | 351 { |
| 382 var contextMenu = new WebInspector.ContextMenu(event); | 352 var contextMenu = new WebInspector.ContextMenu(event); |
| 383 var path = "/"; | 353 var path = "/"; |
| 384 var projectNode = node; | 354 var folderNode = node; |
| 385 while (projectNode.parent !== this._rootNode) { | 355 while (folderNode.parent !== this._rootNode) { |
| 386 path = "/" + projectNode.id + path; | 356 path = "/" + folderNode.id + path; |
| 387 projectNode = projectNode.parent; | 357 folderNode = folderNode.parent; |
| 388 } | 358 } |
| 389 | 359 |
| 390 var project = projectNode._project; | 360 var project = folderNode._project; |
| 391 | 361 |
| 392 if (project.type() === WebInspector.projectTypes.FileSystem) { | 362 if (project && project.type() === WebInspector.projectTypes.FileSystem) { |
| 393 contextMenu.appendItem(WebInspector.UIString.capitalize("Refresh"), this._handleContextMenuRefresh.bind(this, project, path)); | 363 contextMenu.appendItem(WebInspector.UIString.capitalize("Refresh"), this._handleContextMenuRefresh.bind(this, project, path)); |
| 394 contextMenu.appendItem(WebInspector.UIString.capitalize("New ^file") , this._handleContextMenuCreate.bind(this, project, path)); | 364 contextMenu.appendItem(WebInspector.UIString.capitalize("New ^file") , this._handleContextMenuCreate.bind(this, project, path)); |
| 395 contextMenu.appendItem(WebInspector.UIString.capitalize("Exclude ^fo lder"), this._handleContextMenuExclude.bind(this, project, path)); | 365 contextMenu.appendItem(WebInspector.UIString.capitalize("Exclude ^fo lder"), this._handleContextMenuExclude.bind(this, project, path)); |
| 396 } | 366 } |
| 397 contextMenu.appendSeparator(); | 367 contextMenu.appendSeparator(); |
| 398 WebInspector.NavigatorView.appendAddFolderItem(contextMenu); | 368 WebInspector.NavigatorView.appendAddFolderItem(contextMenu); |
| 399 | 369 |
| 400 function removeFolder() | 370 function removeFolder() |
| 401 { | 371 { |
| 402 var shouldRemove = window.confirm(WebInspector.UIString("Are you sur e you want to remove this folder?")); | 372 var shouldRemove = window.confirm(WebInspector.UIString("Are you sur e you want to remove this folder?")); |
| 403 if (shouldRemove) | 373 if (shouldRemove) |
| 404 project.remove(); | 374 project.remove(); |
| 405 } | 375 } |
| 406 | 376 |
| 407 if (project.type() === WebInspector.projectTypes.FileSystem && node === projectNode) { | 377 if (project.type() === WebInspector.projectTypes.FileSystem && node === folderNode) { |
| 408 var removeFolderLabel = WebInspector.UIString.capitalize("Remove ^fo lder from ^workspace"); | 378 var removeFolderLabel = WebInspector.UIString.capitalize("Remove ^fo lder from ^workspace"); |
| 409 contextMenu.appendItem(removeFolderLabel, removeFolder); | 379 contextMenu.appendItem(removeFolderLabel, removeFolder); |
| 410 } | 380 } |
| 411 | 381 |
| 412 contextMenu.show(); | 382 contextMenu.show(); |
| 413 }, | 383 }, |
| 414 | 384 |
| 415 /** | 385 /** |
| 416 * @param {!WebInspector.UISourceCode} uiSourceCode | 386 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 417 * @param {boolean} deleteIfCanceled | 387 * @param {boolean} deleteIfCanceled |
| (...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1027 if (!this._treeElement) | 997 if (!this._treeElement) |
| 1028 return; | 998 return; |
| 1029 | 999 |
| 1030 var titleText = this._uiSourceCode.displayName(); | 1000 var titleText = this._uiSourceCode.displayName(); |
| 1031 if (!ignoreIsDirty && (this._uiSourceCode.isDirty() || this._uiSourceCod e.hasUnsavedCommittedChanges())) | 1001 if (!ignoreIsDirty && (this._uiSourceCode.isDirty() || this._uiSourceCod e.hasUnsavedCommittedChanges())) |
| 1032 titleText = "*" + titleText; | 1002 titleText = "*" + titleText; |
| 1033 var tooltip = titleText; | 1003 var tooltip = titleText; |
| 1034 if (this._uiSourceCode.contentType().isFromSourceMap()) | 1004 if (this._uiSourceCode.contentType().isFromSourceMap()) |
| 1035 tooltip = WebInspector.UIString("%s (from source map)", this._uiSour ceCode.displayName()); | 1005 tooltip = WebInspector.UIString("%s (from source map)", this._uiSour ceCode.displayName()); |
| 1036 this._treeElement.title = titleText; | 1006 this._treeElement.title = titleText; |
| 1037 this._treeElement.tooltip = tooltip; | 1007 this._treeElement.tooltip = this._uiSourceCode.originURL(); |
| 1038 }, | 1008 }, |
| 1039 | 1009 |
| 1040 /** | 1010 /** |
| 1041 * @override | 1011 * @override |
| 1042 * @return {boolean} | 1012 * @return {boolean} |
| 1043 */ | 1013 */ |
| 1044 hasChildren: function() | 1014 hasChildren: function() |
| 1045 { | 1015 { |
| 1046 return false; | 1016 return false; |
| 1047 }, | 1017 }, |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1282 | 1252 |
| 1283 willRemoveChild: function(node) | 1253 willRemoveChild: function(node) |
| 1284 { | 1254 { |
| 1285 if (node._isMerged || !this.isPopulated()) | 1255 if (node._isMerged || !this.isPopulated()) |
| 1286 return; | 1256 return; |
| 1287 this._treeElement.removeChild(node._treeElement); | 1257 this._treeElement.removeChild(node._treeElement); |
| 1288 }, | 1258 }, |
| 1289 | 1259 |
| 1290 __proto__: WebInspector.NavigatorTreeNode.prototype | 1260 __proto__: WebInspector.NavigatorTreeNode.prototype |
| 1291 } | 1261 } |
| OLD | NEW |