| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 Changes.ChangesSidebar = class extends UI.Widget { |
| 6 /** |
| 7 * @param {!WorkspaceDiff.WorkspaceDiff} workspaceDiff |
| 8 */ |
| 9 constructor(workspaceDiff) { |
| 10 super(); |
| 11 this._treeoutline = new UI.TreeOutlineInShadow(); |
| 12 this._treeoutline.registerRequiredCSS('changes/changesSidebar.css'); |
| 13 this._treeoutline.setComparator((a, b) => a.titleAsText().compareTo(b.titleA
sText())); |
| 14 this._treeoutline.addEventListener(UI.TreeOutline.Events.ElementSelected, th
is._selectionChanged, this); |
| 15 |
| 16 this.element.appendChild(this._treeoutline.element); |
| 17 |
| 18 /** @type {!Map<!Workspace.UISourceCode, !Changes.ChangesSidebar.UISourceCod
eTreeElement>} */ |
| 19 this._treeElements = new Map(); |
| 20 this._workspaceDiff = workspaceDiff; |
| 21 this._workspaceDiff.modifiedUISourceCodes().forEach(this._addUISourceCode.bi
nd(this)); |
| 22 this._workspaceDiff.addEventListener( |
| 23 WorkspaceDiff.Events.ModifiedStatusChanged, this._uiSourceCodeMofiedStat
usChanged, this); |
| 24 } |
| 25 |
| 26 /** |
| 27 * @return {?Workspace.UISourceCode} |
| 28 */ |
| 29 selectedUISourceCode() { |
| 30 return this._treeoutline.selectedTreeElement ? this._treeoutline.selectedTre
eElement.uiSourceCode : null; |
| 31 } |
| 32 |
| 33 _selectionChanged() { |
| 34 this.dispatchEventToListeners(Changes.ChangesSidebar.Events.SelectedUISource
CodeChanged); |
| 35 } |
| 36 |
| 37 /** |
| 38 * @param {!Common.Event} event |
| 39 */ |
| 40 _uiSourceCodeMofiedStatusChanged(event) { |
| 41 if (event.data.isModified) |
| 42 this._addUISourceCode(event.data.uiSourceCode); |
| 43 else |
| 44 this._removeUISourceCode(event.data.uiSourceCode); |
| 45 } |
| 46 |
| 47 /** |
| 48 * @param {!Workspace.UISourceCode} uiSourceCode |
| 49 */ |
| 50 _removeUISourceCode(uiSourceCode) { |
| 51 var treeElement = this._treeElements.get(uiSourceCode); |
| 52 this._treeElements.delete(uiSourceCode); |
| 53 if (this._treeoutline.selectedTreeElement === treeElement) { |
| 54 var nextElementToSelect = treeElement.previousSibling || treeElement.nextS
ibling; |
| 55 if (nextElementToSelect) { |
| 56 nextElementToSelect.select(true); |
| 57 } else { |
| 58 treeElement.deselect(); |
| 59 this._selectionChanged(); |
| 60 } |
| 61 } |
| 62 this._treeoutline.removeChild(treeElement); |
| 63 treeElement.dispose(); |
| 64 } |
| 65 |
| 66 /** |
| 67 * @param {!Workspace.UISourceCode} uiSourceCode |
| 68 */ |
| 69 _addUISourceCode(uiSourceCode) { |
| 70 var treeElement = new Changes.ChangesSidebar.UISourceCodeTreeElement(uiSourc
eCode); |
| 71 this._treeElements.set(uiSourceCode, treeElement); |
| 72 this._treeoutline.appendChild(treeElement); |
| 73 if (!this._treeoutline.selectedTreeElement) |
| 74 treeElement.select(true); |
| 75 } |
| 76 }; |
| 77 |
| 78 /** |
| 79 * @enum {symbol} |
| 80 */ |
| 81 Changes.ChangesSidebar.Events = { |
| 82 SelectedUISourceCodeChanged: Symbol('SelectedUISourceCodeChanged') |
| 83 }; |
| 84 |
| 85 Changes.ChangesSidebar.UISourceCodeTreeElement = class extends UI.TreeElement { |
| 86 /** |
| 87 * @param {!Workspace.UISourceCode} uiSourceCode |
| 88 */ |
| 89 constructor(uiSourceCode) { |
| 90 super(); |
| 91 this.uiSourceCode = uiSourceCode; |
| 92 this.listItemElement.classList.add('navigator-' + uiSourceCode.contentType()
.name() + '-tree-item'); |
| 93 |
| 94 var iconType = 'largeicon-navigator-file'; |
| 95 if (this.uiSourceCode.contentType() === Common.resourceTypes.Snippet) |
| 96 iconType = 'largeicon-navigator-snippet'; |
| 97 var defaultIcon = UI.Icon.create(iconType, 'icon'); |
| 98 this.setLeadingIcons([defaultIcon]); |
| 99 |
| 100 this._eventListeners = [ |
| 101 uiSourceCode.addEventListener(Workspace.UISourceCode.Events.TitleChanged,
this._updateTitle, this), |
| 102 uiSourceCode.addEventListener(Workspace.UISourceCode.Events.WorkingCopyCha
nged, this._updateTitle, this), |
| 103 uiSourceCode.addEventListener(Workspace.UISourceCode.Events.WorkingCopyCom
mitted, this._updateTitle, this) |
| 104 ]; |
| 105 |
| 106 this._updateTitle(); |
| 107 } |
| 108 |
| 109 _updateTitle() { |
| 110 var titleText = this.uiSourceCode.displayName(); |
| 111 if (this.uiSourceCode.isDirty() || Persistence.persistence.hasUnsavedCommitt
edChanges(this.uiSourceCode)) |
| 112 titleText = '*' + titleText; |
| 113 this.title = titleText; |
| 114 |
| 115 var tooltip = this.uiSourceCode.url(); |
| 116 if (this.uiSourceCode.contentType().isFromSourceMap()) |
| 117 tooltip = Common.UIString('%s (from source map)', this.uiSourceCode.displa
yName()); |
| 118 this.tooltip = tooltip; |
| 119 } |
| 120 |
| 121 dispose() { |
| 122 Common.EventTarget.removeEventListeners(this._eventListeners); |
| 123 } |
| 124 }; |
| OLD | NEW |