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.UISourceCodeList = 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/uiSourceCodeList.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.UISourceCodeList.UISourceC odeTreeElement>} */ | |
| 19 this._treeElements = new Map(); | |
| 20 /** @type {!Map<!UI.TreeElement, !Workspace.UISourceCode>} */ | |
| 21 this._uiSourceCodes = new Map(); | |
|
lushnikov
2017/03/24 04:02:34
this map is not needed - just use treeElements
einbinder
2017/03/28 00:07:24
Done.
| |
| 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 _selectionChanged() { | |
| 36 var uiSourceCode = null; | |
| 37 if (this._treeoutline.selectedTreeElement) | |
| 38 uiSourceCode = this._uiSourceCodes.get(this._treeoutline.selectedTreeEleme nt) || null; | |
| 39 this.emit(new Changes.UISourceCodeList.SelectedUISourceCodeChanged(uiSourceC ode)); | |
| 40 } | |
| 41 | |
| 42 /** | |
| 43 * @param {!Workspace.UISourceCode} uiSourceCode | |
| 44 */ | |
| 45 _removeUISourceCode(uiSourceCode) { | |
| 46 var treeElement = this._treeElements.get(uiSourceCode); | |
| 47 if (!treeElement) | |
|
lushnikov
2017/03/24 04:02:34
how could it be? console.assert instead
einbinder
2017/03/28 00:07:24
Removed.
| |
| 48 return; | |
| 49 this._treeElements.delete(uiSourceCode); | |
| 50 this._uiSourceCodes.delete(treeElement); | |
| 51 var wasSelected = this._treeoutline.selectedTreeElement === treeElement; | |
| 52 this._treeoutline.removeChild(treeElement); | |
| 53 treeElement.dispose(); | |
| 54 if (wasSelected) { | |
| 55 if (this._treeElements.size) | |
| 56 this._treeElements.values().next().value.select(true); | |
|
lushnikov
2017/03/24 04:02:34
let's have nextSibling()
einbinder
2017/03/28 00:07:24
Done.
| |
| 57 else | |
| 58 this._selectionChanged(); | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 /** | |
| 63 * @param {!Workspace.UISourceCode} uiSourceCode | |
| 64 */ | |
| 65 _addUISourceCode(uiSourceCode) { | |
| 66 if (this._treeElements.has(uiSourceCode)) | |
|
lushnikov
2017/03/24 04:02:34
let's assert instead
einbinder
2017/03/28 00:07:24
Removed.
| |
| 67 return; | |
| 68 var treeElement = new Changes.UISourceCodeList.UISourceCodeTreeElement(uiSou rceCode); | |
| 69 this._treeElements.set(uiSourceCode, treeElement); | |
| 70 this._uiSourceCodes.set(treeElement, uiSourceCode); | |
| 71 this._treeoutline.appendChild(treeElement); | |
| 72 if (!this._treeoutline.selectedTreeElement) | |
| 73 treeElement.select(true); | |
| 74 } | |
| 75 }; | |
| 76 | |
| 77 /** | |
| 78 * @implements {Common.Emittable} | |
| 79 */ | |
| 80 Changes.UISourceCodeList.SelectedUISourceCodeChanged = class { | |
| 81 /** | |
| 82 * @param {?Workspace.UISourceCode} uiSourceCode | |
| 83 */ | |
| 84 constructor(uiSourceCode) { | |
| 85 this.uiSourceCode = uiSourceCode; | |
| 86 } | |
| 87 }; | |
| 88 | |
| 89 Changes.UISourceCodeList.UISourceCodeTreeElement = class extends UI.TreeElement { | |
| 90 /** | |
| 91 * @param {!Workspace.UISourceCode} uiSourceCode | |
| 92 */ | |
| 93 constructor(uiSourceCode) { | |
| 94 super(); | |
| 95 this._uiSourceCode = uiSourceCode; | |
| 96 this.listItemElement.classList.add('navigator-' + uiSourceCode.contentType() .name() + '-tree-item'); | |
| 97 | |
| 98 var iconType = 'largeicon-navigator-file'; | |
| 99 if (this._uiSourceCode.contentType() === Common.resourceTypes.Snippet) | |
| 100 iconType = 'largeicon-navigator-snippet'; | |
| 101 var defaultIcon = UI.Icon.create(iconType, 'icon'); | |
| 102 this.setLeadingIcons([defaultIcon]); | |
| 103 | |
| 104 this._eventListeners = [ | |
| 105 uiSourceCode.addEventListener(Workspace.UISourceCode.Events.TitleChanged, this._updateTitle, this), | |
| 106 uiSourceCode.addEventListener(Workspace.UISourceCode.Events.WorkingCopyCha nged, this._updateTitle, this), | |
| 107 uiSourceCode.addEventListener(Workspace.UISourceCode.Events.WorkingCopyCom mitted, this._updateTitle, this) | |
| 108 ]; | |
| 109 | |
| 110 this._updateTitle(); | |
| 111 } | |
| 112 | |
| 113 _updateTitle() { | |
| 114 var titleText = this._uiSourceCode.displayName(); | |
| 115 if (this._uiSourceCode.isDirty() || Persistence.persistence.hasUnsavedCommit tedChanges(this._uiSourceCode)) | |
| 116 titleText = '*' + titleText; | |
| 117 this.title = titleText; | |
| 118 | |
| 119 var tooltip = this._uiSourceCode.url(); | |
| 120 if (this._uiSourceCode.contentType().isFromSourceMap()) | |
| 121 tooltip = Common.UIString('%s (from source map)', this._uiSourceCode.displ ayName()); | |
| 122 this.tooltip = tooltip; | |
| 123 } | |
| 124 | |
| 125 dispose() { | |
| 126 Common.EventTarget.removeEventListeners(this._eventListeners); | |
| 127 } | |
| 128 }; | |
| OLD | NEW |