| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 this._subfolderNodes = new Map(); | 46 this._subfolderNodes = new Map(); |
| 47 | 47 |
| 48 this._rootNode = new Sources.NavigatorRootTreeNode(this); | 48 this._rootNode = new Sources.NavigatorRootTreeNode(this); |
| 49 this._rootNode.populate(); | 49 this._rootNode.populate(); |
| 50 | 50 |
| 51 /** @type {!Map.<!SDK.ResourceTreeFrame, !Sources.NavigatorGroupTreeNode>} *
/ | 51 /** @type {!Map.<!SDK.ResourceTreeFrame, !Sources.NavigatorGroupTreeNode>} *
/ |
| 52 this._frameNodes = new Map(); | 52 this._frameNodes = new Map(); |
| 53 | 53 |
| 54 this.element.addEventListener('contextmenu', this.handleContextMenu.bind(thi
s), false); | 54 this.element.addEventListener('contextmenu', this.handleContextMenu.bind(thi
s), false); |
| 55 | 55 |
| 56 this._dontGroup = false; |
| 56 this._navigatorGroupByFolderSetting = Common.moduleSetting('navigatorGroupBy
Folder'); | 57 this._navigatorGroupByFolderSetting = Common.moduleSetting('navigatorGroupBy
Folder'); |
| 57 this._navigatorGroupByFolderSetting.addChangeListener(this._groupingChanged.
bind(this)); | 58 this._navigatorGroupByFolderSetting.addChangeListener(this._groupingChanged.
bind(this)); |
| 58 | 59 |
| 59 this._initGrouping(); | 60 this._initGrouping(); |
| 60 SDK.targetManager.addModelListener( | 61 SDK.targetManager.addModelListener( |
| 61 SDK.ResourceTreeModel, SDK.ResourceTreeModel.Events.FrameNavigated, this
._frameNavigated, this); | 62 SDK.ResourceTreeModel, SDK.ResourceTreeModel.Events.FrameNavigated, this
._frameNavigated, this); |
| 62 SDK.targetManager.addModelListener( | 63 SDK.targetManager.addModelListener( |
| 63 SDK.ResourceTreeModel, SDK.ResourceTreeModel.Events.FrameDetached, this.
_frameDetached, this); | 64 SDK.ResourceTreeModel, SDK.ResourceTreeModel.Events.FrameDetached, this.
_frameDetached, this); |
| 64 | 65 |
| 65 if (Runtime.experiments.isEnabled('persistence2')) { | 66 if (Runtime.experiments.isEnabled('persistence2')) { |
| 66 Persistence.persistence.addEventListener( | 67 Persistence.persistence.addEventListener( |
| 67 Persistence.Persistence.Events.BindingCreated, this._onBindingChanged,
this); | 68 Persistence.Persistence.Events.BindingCreated, this._onBindingChanged,
this); |
| 68 Persistence.persistence.addEventListener( | 69 Persistence.persistence.addEventListener( |
| 69 Persistence.Persistence.Events.BindingRemoved, this._onBindingChanged,
this); | 70 Persistence.Persistence.Events.BindingRemoved, this._onBindingChanged,
this); |
| 70 } else { | 71 } else { |
| 71 Persistence.persistence.addEventListener( | 72 Persistence.persistence.addEventListener( |
| 72 Persistence.Persistence.Events.BindingCreated, this._onBindingCreated,
this); | 73 Persistence.Persistence.Events.BindingCreated, this._onBindingCreated,
this); |
| 73 Persistence.persistence.addEventListener( | 74 Persistence.persistence.addEventListener( |
| 74 Persistence.Persistence.Events.BindingRemoved, this._onBindingRemoved,
this); | 75 Persistence.Persistence.Events.BindingRemoved, this._onBindingRemoved,
this); |
| 75 } | 76 } |
| 76 SDK.targetManager.addEventListener(SDK.TargetManager.Events.NameChanged, thi
s._targetNameChanged, this); | 77 SDK.targetManager.addEventListener(SDK.TargetManager.Events.NameChanged, thi
s._targetNameChanged, this); |
| 77 | 78 |
| 78 SDK.targetManager.observeTargets(this); | 79 SDK.targetManager.observeTargets(this); |
| 79 this._resetWorkspace(Workspace.workspace); | 80 this._resetWorkspace(Workspace.workspace); |
| 80 this._workspace.uiSourceCodes().forEach(this._addUISourceCode.bind(this)); | 81 this._workspace.uiSourceCodes().forEach(this.refreshUISourceCode.bind(this))
; |
| 81 } | 82 } |
| 82 | 83 |
| 83 /** | 84 /** |
| 84 * @param {!UI.TreeElement} treeElement | 85 * @param {!UI.TreeElement} treeElement |
| 85 */ | 86 */ |
| 86 static _treeElementOrder(treeElement) { | 87 static _treeElementOrder(treeElement) { |
| 87 if (treeElement._boostOrder) | 88 if (treeElement._boostOrder) |
| 88 return 0; | 89 return 0; |
| 89 | 90 |
| 90 if (!Sources.NavigatorView._typeOrders) { | 91 if (!Sources.NavigatorView._typeOrders) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 if (typeWeight1 < typeWeight2) | 162 if (typeWeight1 < typeWeight2) |
| 162 return -1; | 163 return -1; |
| 163 return treeElement1.titleAsText().compareTo(treeElement2.titleAsText()); | 164 return treeElement1.titleAsText().compareTo(treeElement2.titleAsText()); |
| 164 } | 165 } |
| 165 | 166 |
| 166 /** | 167 /** |
| 167 * @param {!Common.Event} event | 168 * @param {!Common.Event} event |
| 168 */ | 169 */ |
| 169 _onBindingCreated(event) { | 170 _onBindingCreated(event) { |
| 170 var binding = /** @type {!Persistence.PersistenceBinding} */ (event.data); | 171 var binding = /** @type {!Persistence.PersistenceBinding} */ (event.data); |
| 171 this._removeUISourceCode(binding.network); | 172 this.refreshUISourceCode(binding.network); |
| 172 } | 173 } |
| 173 | 174 |
| 174 /** | 175 /** |
| 175 * @param {!Common.Event} event | 176 * @param {!Common.Event} event |
| 176 */ | 177 */ |
| 177 _onBindingRemoved(event) { | 178 _onBindingRemoved(event) { |
| 178 var binding = /** @type {!Persistence.PersistenceBinding} */ (event.data); | 179 var binding = /** @type {!Persistence.PersistenceBinding} */ (event.data); |
| 179 this._addUISourceCode(binding.network); | 180 this.refreshUISourceCode(binding.network); |
| 180 } | 181 } |
| 181 | 182 |
| 182 /** | 183 /** |
| 183 * @param {!Common.Event} event | 184 * @param {!Common.Event} event |
| 184 */ | 185 */ |
| 185 _onBindingChanged(event) { | 186 _onBindingChanged(event) { |
| 186 var binding = /** @type {!Persistence.PersistenceBinding} */ (event.data); | 187 var binding = /** @type {!Persistence.PersistenceBinding} */ (event.data); |
| 187 | 188 |
| 188 // Update UISourceCode titles. | 189 // Update UISourceCode titles. |
| 189 var networkNodes = this._uiSourceCodeNodes.get(binding.network) || []; | 190 var networkNodes = this._uiSourceCodeNodes.get(binding.network) || []; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 var resourceTreeModel = target && SDK.ResourceTreeModel.fromTarget(target)
; | 257 var resourceTreeModel = target && SDK.ResourceTreeModel.fromTarget(target)
; |
| 257 frame = resourceTreeModel && resourceTreeModel.mainFrame; | 258 frame = resourceTreeModel && resourceTreeModel.mainFrame; |
| 258 } | 259 } |
| 259 return frame; | 260 return frame; |
| 260 } | 261 } |
| 261 | 262 |
| 262 /** | 263 /** |
| 263 * @param {!Workspace.UISourceCode} uiSourceCode | 264 * @param {!Workspace.UISourceCode} uiSourceCode |
| 264 */ | 265 */ |
| 265 _addUISourceCode(uiSourceCode) { | 266 _addUISourceCode(uiSourceCode) { |
| 266 if (!this.accept(uiSourceCode)) | 267 if (this._uiSourceCodeNodes.has(uiSourceCode)) |
| 267 return; | 268 return; |
| 268 | 269 |
| 269 var binding = Persistence.persistence.binding(uiSourceCode); | 270 var binding = Persistence.persistence.binding(uiSourceCode); |
| 270 if (!Runtime.experiments.isEnabled('persistence2') && binding && binding.net
work === uiSourceCode) | 271 if (!Runtime.experiments.isEnabled('persistence2') && binding && binding.net
work === uiSourceCode) |
| 271 return; | 272 return; |
| 272 | 273 |
| 273 var isFromSourceMap = uiSourceCode.contentType().isFromSourceMap(); | 274 var isFromSourceMap = uiSourceCode.contentType().isFromSourceMap(); |
| 274 var path; | 275 var path; |
| 275 if (uiSourceCode.project().type() === Workspace.projectTypes.FileSystem) | 276 if (uiSourceCode.project().type() === Workspace.projectTypes.FileSystem) |
| 276 path = Persistence.FileSystemWorkspaceBinding.relativePath(uiSourceCode).s
lice(0, -1); | 277 path = Persistence.FileSystemWorkspaceBinding.relativePath(uiSourceCode).s
lice(0, -1); |
| 277 else | 278 else |
| 278 path = Common.ParsedURL.extractPath(uiSourceCode.url()).split('/').slice(1
, -1); | 279 path = Common.ParsedURL.extractPath(uiSourceCode.url()).split('/').slice(1
, -1); |
| 279 | 280 |
| 280 var project = uiSourceCode.project(); | 281 var project = uiSourceCode.project(); |
| 281 var target = Bindings.NetworkProject.targetForUISourceCode(uiSourceCode); | 282 var target = Bindings.NetworkProject.targetForUISourceCode(uiSourceCode); |
| 282 var frame = this._uiSourceCodeFrame(uiSourceCode); | 283 var frame = this._uiSourceCodeFrame(uiSourceCode); |
| 283 | 284 |
| 284 var folderNode = | 285 var folderNode = |
| 285 this._folderNode(uiSourceCode, project, target, frame, uiSourceCode.orig
in(), path, isFromSourceMap); | 286 this._folderNode(uiSourceCode, project, target, frame, uiSourceCode.orig
in(), path, isFromSourceMap); |
| 286 var uiSourceCodeNode = new Sources.NavigatorUISourceCodeTreeNode(this, uiSou
rceCode); | 287 var uiSourceCodeNode = new Sources.NavigatorUISourceCodeTreeNode(this, uiSou
rceCode); |
| 287 this._uiSourceCodeNodes.set(uiSourceCode, [uiSourceCodeNode]); | 288 this._uiSourceCodeNodes.set(uiSourceCode, [uiSourceCodeNode]); |
| 288 folderNode.appendChild(uiSourceCodeNode); | 289 folderNode.appendChild(uiSourceCodeNode); |
| 289 this.uiSourceCodeAdded(uiSourceCode); | 290 this.uiSourceCodeAdded(uiSourceCode); |
| 290 } | 291 } |
| 291 | 292 |
| 292 /** | 293 /** |
| 293 * @param {!Workspace.UISourceCode} uiSourceCode | 294 * @param {!Workspace.UISourceCode} uiSourceCode |
| 294 */ | 295 */ |
| 296 refreshUISourceCode(uiSourceCode) { |
| 297 if (this.accept(uiSourceCode)) |
| 298 this._addUISourceCode(uiSourceCode); |
| 299 else |
| 300 this._removeUISourceCode(uiSourceCode); |
| 301 } |
| 302 |
| 303 /** |
| 304 * @param {!Workspace.UISourceCode} uiSourceCode |
| 305 */ |
| 295 uiSourceCodeAdded(uiSourceCode) { | 306 uiSourceCodeAdded(uiSourceCode) { |
| 296 } | 307 } |
| 297 | 308 |
| 298 /** | 309 /** |
| 310 * @param {!Workspace.UISourceCode} uiSourceCode |
| 311 */ |
| 312 uiSourceCodeRemoved(uiSourceCode) { |
| 313 } |
| 314 |
| 315 /** |
| 299 * @param {!Common.Event} event | 316 * @param {!Common.Event} event |
| 300 */ | 317 */ |
| 301 _uiSourceCodeAdded(event) { | 318 _uiSourceCodeAdded(event) { |
| 302 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data); | 319 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data); |
| 303 this._addUISourceCode(uiSourceCode); | 320 this.refreshUISourceCode(uiSourceCode); |
| 304 } | 321 } |
| 305 | 322 |
| 306 /** | 323 /** |
| 307 * @param {!Common.Event} event | 324 * @param {!Common.Event} event |
| 308 */ | 325 */ |
| 309 _uiSourceCodeRemoved(event) { | 326 _uiSourceCodeRemoved(event) { |
| 310 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data); | 327 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data); |
| 311 this._removeUISourceCode(uiSourceCode); | 328 this._removeUISourceCode(uiSourceCode); |
| 312 } | 329 } |
| 313 | 330 |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 return null; | 518 return null; |
| 502 if (this._scriptsTree.selectedTreeElement) | 519 if (this._scriptsTree.selectedTreeElement) |
| 503 this._scriptsTree.selectedTreeElement.deselect(); | 520 this._scriptsTree.selectedTreeElement.deselect(); |
| 504 this._lastSelectedUISourceCode = uiSourceCode; | 521 this._lastSelectedUISourceCode = uiSourceCode; |
| 505 // TODO(dgozman): figure out revealing multiple. | 522 // TODO(dgozman): figure out revealing multiple. |
| 506 nodes[0].reveal(select); | 523 nodes[0].reveal(select); |
| 507 return nodes[0]; | 524 return nodes[0]; |
| 508 } | 525 } |
| 509 | 526 |
| 510 /** | 527 /** |
| 528 * @return {?Workspace.UISourceCode} |
| 529 */ |
| 530 anyUISourceCode() { |
| 531 if (this._uiSourceCodeNodes.has(this._lastSelectedUISourceCode)) |
| 532 return this._lastSelectedUISourceCode; |
| 533 return this._uiSourceCodeNodes.keys().next().value || null; |
| 534 } |
| 535 |
| 536 /** |
| 511 * @param {!Workspace.UISourceCode} uiSourceCode | 537 * @param {!Workspace.UISourceCode} uiSourceCode |
| 512 * @param {boolean} focusSource | 538 * @param {boolean} focusSource |
| 513 */ | 539 */ |
| 514 _sourceSelected(uiSourceCode, focusSource) { | 540 _sourceSelected(uiSourceCode, focusSource) { |
| 515 this._lastSelectedUISourceCode = uiSourceCode; | 541 this._lastSelectedUISourceCode = uiSourceCode; |
| 542 this.revealSource(uiSourceCode, focusSource); |
| 543 } |
| 544 |
| 545 /** |
| 546 * @param {!Workspace.UISourceCode} uiSourceCode |
| 547 * @param {boolean} focusSource |
| 548 */ |
| 549 revealSource(uiSourceCode, focusSource) { |
| 516 Common.Revealer.reveal(uiSourceCode, !focusSource); | 550 Common.Revealer.reveal(uiSourceCode, !focusSource); |
| 517 } | 551 } |
| 518 | 552 |
| 519 /** | 553 /** |
| 520 * @param {!Workspace.UISourceCode} uiSourceCode | 554 * @param {!Workspace.UISourceCode} uiSourceCode |
| 521 */ | 555 */ |
| 522 sourceDeleted(uiSourceCode) { | 556 sourceDeleted(uiSourceCode) { |
| 523 } | 557 } |
| 524 | 558 |
| 525 /** | 559 /** |
| (...skipping 23 matching lines...) Expand all Loading... |
| 549 break; | 583 break; |
| 550 } | 584 } |
| 551 | 585 |
| 552 var folderId = this._folderNodeId(project, target, frame, uiSourceCode.o
rigin(), node._folderPath); | 586 var folderId = this._folderNodeId(project, target, frame, uiSourceCode.o
rigin(), node._folderPath); |
| 553 this._subfolderNodes.delete(folderId); | 587 this._subfolderNodes.delete(folderId); |
| 554 parentNode.removeChild(node); | 588 parentNode.removeChild(node); |
| 555 node = parentNode; | 589 node = parentNode; |
| 556 } | 590 } |
| 557 } | 591 } |
| 558 this._uiSourceCodeNodes.delete(uiSourceCode); | 592 this._uiSourceCodeNodes.delete(uiSourceCode); |
| 593 this.uiSourceCodeRemoved(uiSourceCode); |
| 559 } | 594 } |
| 560 | 595 |
| 561 reset() { | 596 reset() { |
| 562 for (var entry of this._uiSourceCodeNodes) { | 597 for (var entry of this._uiSourceCodeNodes) { |
| 563 var nodes = /** @type {!Array<!Sources.NavigatorUISourceCodeTreeNode>} */
(entry[1]); | 598 var nodes = /** @type {!Array<!Sources.NavigatorUISourceCodeTreeNode>} */
(entry[1]); |
| 564 for (var i = 0; i < nodes.length; i++) | 599 for (var i = 0; i < nodes.length; i++) |
| 565 nodes[i].dispose(); | 600 nodes[i].dispose(); |
| 566 } | 601 } |
| 567 | 602 |
| 568 this._scriptsTree.removeChildren(); | 603 this._scriptsTree.removeChildren(); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 function fileCreated(uiSourceCode) { | 766 function fileCreated(uiSourceCode) { |
| 732 if (!uiSourceCode) | 767 if (!uiSourceCode) |
| 733 return; | 768 return; |
| 734 this._sourceSelected(uiSourceCode, false); | 769 this._sourceSelected(uiSourceCode, false); |
| 735 var node = this.revealUISourceCode(uiSourceCode, true); | 770 var node = this.revealUISourceCode(uiSourceCode, true); |
| 736 if (node) | 771 if (node) |
| 737 this.rename(node, true); | 772 this.rename(node, true); |
| 738 } | 773 } |
| 739 } | 774 } |
| 740 | 775 |
| 776 dontGroup() { |
| 777 this._dontGroup = true; |
| 778 this._groupingChanged(); |
| 779 } |
| 780 |
| 741 _groupingChanged() { | 781 _groupingChanged() { |
| 742 this.reset(); | 782 this.reset(); |
| 743 this._initGrouping(); | 783 this._initGrouping(); |
| 744 this._workspace.uiSourceCodes().forEach(this._addUISourceCode.bind(this)); | 784 this._workspace.uiSourceCodes().forEach(this.refreshUISourceCode.bind(this))
; |
| 745 } | 785 } |
| 746 | 786 |
| 747 _initGrouping() { | 787 _initGrouping() { |
| 788 if (this._dontGroup) { |
| 789 this._groupByFrame = false; |
| 790 this._groupByDomain = false; |
| 791 this._groupByFolder = false; |
| 792 return; |
| 793 } |
| 748 this._groupByFrame = true; | 794 this._groupByFrame = true; |
| 749 this._groupByDomain = this._navigatorGroupByFolderSetting.get(); | 795 this._groupByDomain = this._navigatorGroupByFolderSetting.get(); |
| 750 this._groupByFolder = this._groupByDomain; | 796 this._groupByFolder = this._groupByDomain; |
| 751 } | 797 } |
| 752 | 798 |
| 753 _resetForTest() { | 799 _resetForTest() { |
| 754 this.reset(); | 800 this.reset(); |
| 755 this._workspace.uiSourceCodes().forEach(this._addUISourceCode.bind(this)); | 801 this._workspace.uiSourceCodes().forEach(this.refreshUISourceCode.bind(this))
; |
| 756 } | 802 } |
| 757 | 803 |
| 758 /** | 804 /** |
| 759 * @param {!Common.Event} event | 805 * @param {!Common.Event} event |
| 760 */ | 806 */ |
| 761 _frameNavigated(event) { | 807 _frameNavigated(event) { |
| 762 var frame = /** @type {!SDK.ResourceTreeFrame} */ (event.data); | 808 var frame = /** @type {!SDK.ResourceTreeFrame} */ (event.data); |
| 763 var node = this._frameNodes.get(frame); | 809 var node = this._frameNodes.get(frame); |
| 764 if (!node) | 810 if (!node) |
| 765 return; | 811 return; |
| (...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1610 /** | 1656 /** |
| 1611 * @param {string} title | 1657 * @param {string} title |
| 1612 * @override | 1658 * @override |
| 1613 */ | 1659 */ |
| 1614 setTitle(title) { | 1660 setTitle(title) { |
| 1615 this._title = title; | 1661 this._title = title; |
| 1616 if (this._treeElement) | 1662 if (this._treeElement) |
| 1617 this._treeElement.title = this._title; | 1663 this._treeElement.title = this._title; |
| 1618 } | 1664 } |
| 1619 }; | 1665 }; |
| OLD | NEW |