Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/changes/UISourceCodeList.js

Issue 2772643002: DevTools: Changes View (Closed)
Patch Set: no highlighting Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 {
lushnikov 2017/03/28 03:32:10 ChangesSidebar!
einbinder 2017/03/28 23:51:04 Done.
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 this._workspaceDiff = workspaceDiff;
21 this._workspaceDiff.modifiedUISourceCodes().forEach(this._addUISourceCode.bi nd(this));
22 this._workspaceDiff.on(WorkspaceDiff.ModifiedStatusChangedEvent, this._uiSou rceCodeMofiedStatusChanged, this);
23 }
24
25 /**
26 * @return {?Workspace.UISourceCode}
27 */
28 selectedUISourceCode() {
29 return this._treeoutline.selectedTreeElement ? this._treeoutline.selectedTre eElement.uiSourceCode : null;
30 }
31
32 _selectionChanged() {
33 this.emit(new Changes.UISourceCodeList.SelectedUISourceCodeChanged());
34 }
35
36 _uiSourceCodeMofiedStatusChanged(event) {
37 if (event.status)
38 this._addUISourceCode(event.uiSourceCode);
39 else
40 this._removeUISourceCode(event.uiSourceCode);
41 }
42
43 /**
44 * @param {!Workspace.UISourceCode} uiSourceCode
45 */
46 _removeUISourceCode(uiSourceCode) {
47 var treeElement = this._treeElements.get(uiSourceCode);
48 this._treeElements.delete(uiSourceCode);
49 if (this._treeoutline.selectedTreeElement === treeElement) {
50 var nextElementToSelect = treeElement.previousSibling || treeElement.nextS ibling;
51 if (nextElementToSelect) {
52 nextElementToSelect.select(true);
53 } else {
54 treeElement.deselect();
55 this._selectionChanged();
56 }
57 }
58 this._treeoutline.removeChild(treeElement);
59 treeElement.dispose();
60 }
61
62 /**
63 * @param {!Workspace.UISourceCode} uiSourceCode
64 */
65 _addUISourceCode(uiSourceCode) {
66 var treeElement = new Changes.UISourceCodeList.UISourceCodeTreeElement(uiSou rceCode);
67 this._treeElements.set(uiSourceCode, treeElement);
68 this._treeoutline.appendChild(treeElement);
69 if (!this._treeoutline.selectedTreeElement)
70 treeElement.select(true);
71 }
72 };
73
74 /**
75 * @implements {Common.Emittable}
76 */
77 Changes.UISourceCodeList.SelectedUISourceCodeChanged = class {
78 constructor() {
79 }
80 };
81
82 Changes.UISourceCodeList.UISourceCodeTreeElement = class extends UI.TreeElement {
83 /**
84 * @param {!Workspace.UISourceCode} uiSourceCode
85 */
86 constructor(uiSourceCode) {
87 super();
88 this.uiSourceCode = uiSourceCode;
89 this.listItemElement.classList.add('navigator-' + uiSourceCode.contentType() .name() + '-tree-item');
90
91 var iconType = 'largeicon-navigator-file';
92 if (this.uiSourceCode.contentType() === Common.resourceTypes.Snippet)
93 iconType = 'largeicon-navigator-snippet';
94 var defaultIcon = UI.Icon.create(iconType, 'icon');
95 this.setLeadingIcons([defaultIcon]);
96
97 this._eventListeners = [
98 uiSourceCode.addEventListener(Workspace.UISourceCode.Events.TitleChanged, this._updateTitle, this),
99 uiSourceCode.addEventListener(Workspace.UISourceCode.Events.WorkingCopyCha nged, this._updateTitle, this),
100 uiSourceCode.addEventListener(Workspace.UISourceCode.Events.WorkingCopyCom mitted, this._updateTitle, this)
101 ];
102
103 this._updateTitle();
104 }
105
106 _updateTitle() {
107 var titleText = this.uiSourceCode.displayName();
108 if (this.uiSourceCode.isDirty() || Persistence.persistence.hasUnsavedCommitt edChanges(this.uiSourceCode))
109 titleText = '*' + titleText;
110 this.title = titleText;
111
112 var tooltip = this.uiSourceCode.url();
113 if (this.uiSourceCode.contentType().isFromSourceMap())
114 tooltip = Common.UIString('%s (from source map)', this.uiSourceCode.displa yName());
115 this.tooltip = tooltip;
116 }
117
118 dispose() {
119 Common.EventTarget.removeEventListeners(this._eventListeners);
120 }
121 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698