Chromium Code Reviews| 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.FileList = 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/fileList.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.FileList.UISourceCodeTreeE lement>} */ | |
| 19 this._treeElements = new Map(); | |
| 20 /** @type {!Map<!UI.TreeElement, !Workspace.UISourceCode>} */ | |
| 21 this._uiSourceCodes = new Map(); | |
| 22 this._workspaceDiff = workspaceDiff; | |
| 23 this._workspaceDiff.modifiedUISourceCodes().forEach(this._addUISourceCode.bi nd(this)); | |
| 24 this._workspaceDiff.on(WorkspaceDiff.ModifiedEvent, event => this._addUISour ceCode(event.uiSourceCode)); | |
| 25 this._workspaceDiff.on(WorkspaceDiff.UnmodifiedEvent, event => this._removeU ISourceCode(event.uiSourceCode)); | |
| 26 } | |
| 27 | |
| 28 /** | |
| 29 * @override | |
| 30 */ | |
| 31 wasShown() { | |
| 32 this._selectionChanged(); | |
| 33 } | |
| 34 | |
| 35 /** | |
| 36 * @override | |
| 37 */ | |
| 38 willHide() { | |
| 39 for (var uiSourceCode of this._uiSourceCodes.values()) | |
| 40 this._removeUISourceCode(uiSourceCode); | |
|
luoe
2017/03/23 02:03:16
joel: remove this
einbinder
2017/03/23 04:32:48
Done.
| |
| 41 this._workspaceDiff.off(WorkspaceDiff.ModifiedEvent, event => this._addUISou rceCode(event.uiSourceCode)); | |
| 42 this._workspaceDiff.off(WorkspaceDiff.UnmodifiedEvent, event => this._remove UISourceCode(event.uiSourceCode)); | |
| 43 } | |
| 44 | |
| 45 _selectionChanged() { | |
| 46 var uiSourceCode = null; | |
| 47 if (this._treeoutline.selectedTreeElement) | |
| 48 uiSourceCode = this._uiSourceCodes.get(this._treeoutline.selectedTreeEleme nt) || null; | |
| 49 this.emit(new Changes.FileList.SelectionChanged(uiSourceCode)); | |
| 50 } | |
| 51 | |
| 52 /** | |
| 53 * @param {!Workspace.UISourceCode} uiSourceCode | |
| 54 */ | |
| 55 _removeUISourceCode(uiSourceCode) { | |
| 56 var treeElement = this._treeElements.get(uiSourceCode); | |
| 57 if (!treeElement) | |
| 58 return; | |
| 59 this._treeElements.delete(uiSourceCode); | |
| 60 this._uiSourceCodes.delete(treeElement); | |
| 61 var wasSelected = this._treeoutline.selectedTreeElement === treeElement; | |
| 62 this._treeoutline.removeChild(treeElement); | |
| 63 treeElement.dispose(); | |
| 64 if (wasSelected) { | |
| 65 if (this._treeElements.size) | |
| 66 this._treeElements.values().next().value.select(true); | |
| 67 else | |
| 68 this._selectionChanged(); | |
| 69 } | |
| 70 } | |
| 71 | |
| 72 /** | |
| 73 * @param {!Workspace.UISourceCode} uiSourceCode | |
| 74 */ | |
| 75 _addUISourceCode(uiSourceCode) { | |
| 76 if (this._treeElements.has(uiSourceCode)) | |
| 77 return; | |
| 78 var treeElement = new Changes.FileList.UISourceCodeTreeElement(uiSourceCode) ; | |
| 79 this._treeElements.set(uiSourceCode, treeElement); | |
| 80 this._uiSourceCodes.set(treeElement, uiSourceCode); | |
| 81 this._treeoutline.appendChild(treeElement); | |
| 82 if (!this._treeoutline.selectedTreeElement) | |
| 83 treeElement.select(true); | |
| 84 } | |
| 85 }; | |
| 86 | |
| 87 /** | |
| 88 * @implements {Common.Emittable} | |
| 89 */ | |
| 90 Changes.FileList.SelectionChanged = class { | |
| 91 /** | |
| 92 * @param {?Workspace.UISourceCode} uiSourceCode | |
| 93 */ | |
| 94 constructor(uiSourceCode) { | |
| 95 this.uiSourceCode = uiSourceCode; | |
| 96 } | |
| 97 }; | |
| 98 | |
| 99 Changes.FileList.UISourceCodeTreeElement = class extends UI.TreeElement { | |
| 100 /** | |
| 101 * @param {!Workspace.UISourceCode} uiSourceCode | |
| 102 */ | |
| 103 constructor(uiSourceCode) { | |
| 104 super(); | |
| 105 this._uiSourceCode = uiSourceCode; | |
| 106 this.listItemElement.classList.add('navigator-' + uiSourceCode.contentType() .name() + '-tree-item'); | |
| 107 | |
| 108 var iconType = 'largeicon-navigator-file'; | |
| 109 if (this._uiSourceCode.contentType() === Common.resourceTypes.Snippet) | |
| 110 iconType = 'largeicon-navigator-snippet'; | |
| 111 var defaultIcon = UI.Icon.create(iconType, 'icon'); | |
| 112 this.setLeadingIcons([defaultIcon]); | |
| 113 | |
| 114 this._eventListeners = [ | |
| 115 uiSourceCode.addEventListener(Workspace.UISourceCode.Events.TitleChanged, this.updateTitle, this), | |
| 116 uiSourceCode.addEventListener(Workspace.UISourceCode.Events.WorkingCopyCha nged, this.updateTitle, this), | |
| 117 uiSourceCode.addEventListener(Workspace.UISourceCode.Events.WorkingCopyCom mitted, this.updateTitle, this) | |
| 118 ]; | |
| 119 | |
| 120 this.updateTitle(); | |
| 121 } | |
| 122 | |
| 123 updateTitle() { | |
| 124 var titleText = this._uiSourceCode.displayName(); | |
| 125 if (this._uiSourceCode.isDirty() || Persistence.persistence.hasUnsavedCommit tedChanges(this._uiSourceCode)) | |
| 126 titleText = '*' + titleText; | |
| 127 this.title = titleText; | |
| 128 | |
| 129 var tooltip = this._uiSourceCode.url(); | |
| 130 if (this._uiSourceCode.contentType().isFromSourceMap()) | |
| 131 tooltip = Common.UIString('%s (from source map)', this._uiSourceCode.displ ayName()); | |
| 132 this.tooltip = tooltip; | |
| 133 } | |
| 134 | |
| 135 dispose() { | |
| 136 Common.EventTarget.removeEventListeners(this._eventListeners); | |
| 137 } | |
| 138 }; | |
| OLD | NEW |