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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sources/RevisionHistoryView.js

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots Created 4 years, 1 month 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
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 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 /** 31 /**
32 * @unrestricted 32 * @unrestricted
33 */ 33 */
34 WebInspector.RevisionHistoryView = class extends WebInspector.VBox { 34 Sources.RevisionHistoryView = class extends UI.VBox {
35 constructor() { 35 constructor() {
36 super(); 36 super();
37 this._uiSourceCodeItems = new Map(); 37 this._uiSourceCodeItems = new Map();
38 38
39 this._treeOutline = new TreeOutlineInShadow(); 39 this._treeOutline = new TreeOutlineInShadow();
40 this._treeOutline.registerRequiredCSS('sources/revisionHistory.css'); 40 this._treeOutline.registerRequiredCSS('sources/revisionHistory.css');
41 this._treeOutline.makeDense(); 41 this._treeOutline.makeDense();
42 this.element.appendChild(this._treeOutline.element); 42 this.element.appendChild(this._treeOutline.element);
43 43
44 /** 44 /**
45 * @param {!WebInspector.UISourceCode} uiSourceCode 45 * @param {!Workspace.UISourceCode} uiSourceCode
46 * @this {WebInspector.RevisionHistoryView} 46 * @this {Sources.RevisionHistoryView}
47 */ 47 */
48 function populateRevisions(uiSourceCode) { 48 function populateRevisions(uiSourceCode) {
49 if (uiSourceCode.history.length) 49 if (uiSourceCode.history.length)
50 this._createUISourceCodeItem(uiSourceCode); 50 this._createUISourceCodeItem(uiSourceCode);
51 } 51 }
52 52
53 WebInspector.workspace.uiSourceCodes().forEach(populateRevisions.bind(this)) ; 53 Workspace.workspace.uiSourceCodes().forEach(populateRevisions.bind(this));
54 WebInspector.workspace.addEventListener( 54 Workspace.workspace.addEventListener(
55 WebInspector.Workspace.Events.WorkingCopyCommittedByUser, this._revision Added, this); 55 Workspace.Workspace.Events.WorkingCopyCommittedByUser, this._revisionAdd ed, this);
56 WebInspector.workspace.addEventListener( 56 Workspace.workspace.addEventListener(
57 WebInspector.Workspace.Events.UISourceCodeRemoved, this._uiSourceCodeRem oved, this); 57 Workspace.Workspace.Events.UISourceCodeRemoved, this._uiSourceCodeRemove d, this);
58 WebInspector.workspace.addEventListener(WebInspector.Workspace.Events.Projec tRemoved, this._projectRemoved, this); 58 Workspace.workspace.addEventListener(Workspace.Workspace.Events.ProjectRemov ed, this._projectRemoved, this);
59 } 59 }
60 60
61 /** 61 /**
62 * @param {!WebInspector.UISourceCode} uiSourceCode 62 * @param {!Workspace.UISourceCode} uiSourceCode
63 */ 63 */
64 static showHistory(uiSourceCode) { 64 static showHistory(uiSourceCode) {
65 WebInspector.viewManager.showView('sources.history'); 65 UI.viewManager.showView('sources.history');
66 var historyView = /** @type {!WebInspector.RevisionHistoryView} */ ( 66 var historyView = /** @type {!Sources.RevisionHistoryView} */ (
67 self.runtime.sharedInstance(WebInspector.RevisionHistoryView)); 67 self.runtime.sharedInstance(Sources.RevisionHistoryView));
68 historyView._revealUISourceCode(uiSourceCode); 68 historyView._revealUISourceCode(uiSourceCode);
69 } 69 }
70 70
71 /** 71 /**
72 * @param {!WebInspector.UISourceCode} uiSourceCode 72 * @param {!Workspace.UISourceCode} uiSourceCode
73 */ 73 */
74 _createUISourceCodeItem(uiSourceCode) { 74 _createUISourceCodeItem(uiSourceCode) {
75 var uiSourceCodeItem = new TreeElement(uiSourceCode.displayName(), true); 75 var uiSourceCodeItem = new TreeElement(uiSourceCode.displayName(), true);
76 uiSourceCodeItem.selectable = false; 76 uiSourceCodeItem.selectable = false;
77 77
78 // Insert in sorted order 78 // Insert in sorted order
79 var rootElement = this._treeOutline.rootElement(); 79 var rootElement = this._treeOutline.rootElement();
80 for (var i = 0; i < rootElement.childCount(); ++i) { 80 for (var i = 0; i < rootElement.childCount(); ++i) {
81 if (rootElement.childAt(i).title.localeCompare(uiSourceCode.displayName()) > 0) { 81 if (rootElement.childAt(i).title.localeCompare(uiSourceCode.displayName()) > 0) {
82 rootElement.insertChild(uiSourceCodeItem, i); 82 rootElement.insertChild(uiSourceCodeItem, i);
83 break; 83 break;
84 } 84 }
85 } 85 }
86 if (i === rootElement.childCount()) 86 if (i === rootElement.childCount())
87 rootElement.appendChild(uiSourceCodeItem); 87 rootElement.appendChild(uiSourceCodeItem);
88 88
89 this._uiSourceCodeItems.set(uiSourceCode, uiSourceCodeItem); 89 this._uiSourceCodeItems.set(uiSourceCode, uiSourceCodeItem);
90 90
91 var revisionCount = uiSourceCode.history.length; 91 var revisionCount = uiSourceCode.history.length;
92 for (var i = revisionCount - 1; i >= 0; --i) { 92 for (var i = revisionCount - 1; i >= 0; --i) {
93 var revision = uiSourceCode.history[i]; 93 var revision = uiSourceCode.history[i];
94 var historyItem = 94 var historyItem =
95 new WebInspector.RevisionHistoryTreeElement(revision, uiSourceCode.his tory[i - 1], i !== revisionCount - 1); 95 new Sources.RevisionHistoryTreeElement(revision, uiSourceCode.history[ i - 1], i !== revisionCount - 1);
96 uiSourceCodeItem.appendChild(historyItem); 96 uiSourceCodeItem.appendChild(historyItem);
97 } 97 }
98 98
99 var linkItem = new TreeElement(); 99 var linkItem = new TreeElement();
100 linkItem.selectable = false; 100 linkItem.selectable = false;
101 uiSourceCodeItem.appendChild(linkItem); 101 uiSourceCodeItem.appendChild(linkItem);
102 102
103 var revertToOriginal = 103 var revertToOriginal =
104 linkItem.listItemElement.createChild('span', 'revision-history-link revi sion-history-link-row'); 104 linkItem.listItemElement.createChild('span', 'revision-history-link revi sion-history-link-row');
105 revertToOriginal.textContent = WebInspector.UIString('apply original content '); 105 revertToOriginal.textContent = Common.UIString('apply original content');
106 revertToOriginal.addEventListener('click', this._revertToOriginal.bind(this, uiSourceCode)); 106 revertToOriginal.addEventListener('click', this._revertToOriginal.bind(this, uiSourceCode));
107 107
108 var clearHistoryElement = uiSourceCodeItem.listItemElement.createChild('span ', 'revision-history-link'); 108 var clearHistoryElement = uiSourceCodeItem.listItemElement.createChild('span ', 'revision-history-link');
109 clearHistoryElement.textContent = WebInspector.UIString('revert'); 109 clearHistoryElement.textContent = Common.UIString('revert');
110 clearHistoryElement.addEventListener('click', this._clearHistory.bind(this, uiSourceCode)); 110 clearHistoryElement.addEventListener('click', this._clearHistory.bind(this, uiSourceCode));
111 return uiSourceCodeItem; 111 return uiSourceCodeItem;
112 } 112 }
113 113
114 /** 114 /**
115 * @param {!WebInspector.UISourceCode} uiSourceCode 115 * @param {!Workspace.UISourceCode} uiSourceCode
116 */ 116 */
117 _revertToOriginal(uiSourceCode) { 117 _revertToOriginal(uiSourceCode) {
118 uiSourceCode.revertToOriginal(); 118 uiSourceCode.revertToOriginal();
119 } 119 }
120 120
121 /** 121 /**
122 * @param {!WebInspector.UISourceCode} uiSourceCode 122 * @param {!Workspace.UISourceCode} uiSourceCode
123 */ 123 */
124 _clearHistory(uiSourceCode) { 124 _clearHistory(uiSourceCode) {
125 uiSourceCode.revertAndClearHistory(this._removeUISourceCode.bind(this)); 125 uiSourceCode.revertAndClearHistory(this._removeUISourceCode.bind(this));
126 } 126 }
127 127
128 _revisionAdded(event) { 128 _revisionAdded(event) {
129 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data.uiS ourceCode); 129 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data.uiSour ceCode);
130 var uiSourceCodeItem = this._uiSourceCodeItems.get(uiSourceCode); 130 var uiSourceCodeItem = this._uiSourceCodeItems.get(uiSourceCode);
131 if (!uiSourceCodeItem) { 131 if (!uiSourceCodeItem) {
132 uiSourceCodeItem = this._createUISourceCodeItem(uiSourceCode); 132 uiSourceCodeItem = this._createUISourceCodeItem(uiSourceCode);
133 return; 133 return;
134 } 134 }
135 135
136 var historyLength = uiSourceCode.history.length; 136 var historyLength = uiSourceCode.history.length;
137 var historyItem = new WebInspector.RevisionHistoryTreeElement( 137 var historyItem = new Sources.RevisionHistoryTreeElement(
138 uiSourceCode.history[historyLength - 1], uiSourceCode.history[historyLen gth - 2], false); 138 uiSourceCode.history[historyLength - 1], uiSourceCode.history[historyLen gth - 2], false);
139 if (uiSourceCodeItem.firstChild()) 139 if (uiSourceCodeItem.firstChild())
140 uiSourceCodeItem.firstChild().allowRevert(); 140 uiSourceCodeItem.firstChild().allowRevert();
141 uiSourceCodeItem.insertChild(historyItem, 0); 141 uiSourceCodeItem.insertChild(historyItem, 0);
142 } 142 }
143 143
144 /** 144 /**
145 * @param {!WebInspector.UISourceCode} uiSourceCode 145 * @param {!Workspace.UISourceCode} uiSourceCode
146 */ 146 */
147 _revealUISourceCode(uiSourceCode) { 147 _revealUISourceCode(uiSourceCode) {
148 var uiSourceCodeItem = this._uiSourceCodeItems.get(uiSourceCode); 148 var uiSourceCodeItem = this._uiSourceCodeItems.get(uiSourceCode);
149 if (uiSourceCodeItem) { 149 if (uiSourceCodeItem) {
150 uiSourceCodeItem.reveal(); 150 uiSourceCodeItem.reveal();
151 uiSourceCodeItem.expand(); 151 uiSourceCodeItem.expand();
152 } 152 }
153 } 153 }
154 154
155 _uiSourceCodeRemoved(event) { 155 _uiSourceCodeRemoved(event) {
156 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data); 156 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data);
157 this._removeUISourceCode(uiSourceCode); 157 this._removeUISourceCode(uiSourceCode);
158 } 158 }
159 159
160 /** 160 /**
161 * @param {!WebInspector.UISourceCode} uiSourceCode 161 * @param {!Workspace.UISourceCode} uiSourceCode
162 */ 162 */
163 _removeUISourceCode(uiSourceCode) { 163 _removeUISourceCode(uiSourceCode) {
164 var uiSourceCodeItem = this._uiSourceCodeItems.get(uiSourceCode); 164 var uiSourceCodeItem = this._uiSourceCodeItems.get(uiSourceCode);
165 if (!uiSourceCodeItem) 165 if (!uiSourceCodeItem)
166 return; 166 return;
167 this._treeOutline.removeChild(uiSourceCodeItem); 167 this._treeOutline.removeChild(uiSourceCodeItem);
168 this._uiSourceCodeItems.remove(uiSourceCode); 168 this._uiSourceCodeItems.remove(uiSourceCode);
169 } 169 }
170 170
171 _projectRemoved(event) { 171 _projectRemoved(event) {
172 var project = event.data; 172 var project = event.data;
173 project.uiSourceCodes().forEach(this._removeUISourceCode.bind(this)); 173 project.uiSourceCodes().forEach(this._removeUISourceCode.bind(this));
174 } 174 }
175 }; 175 };
176 176
177 177
178 /** 178 /**
179 * @unrestricted 179 * @unrestricted
180 */ 180 */
181 WebInspector.RevisionHistoryTreeElement = class extends TreeElement { 181 Sources.RevisionHistoryTreeElement = class extends TreeElement {
182 /** 182 /**
183 * @param {!WebInspector.Revision} revision 183 * @param {!Workspace.Revision} revision
184 * @param {!WebInspector.Revision} baseRevision 184 * @param {!Workspace.Revision} baseRevision
185 * @param {boolean} allowRevert 185 * @param {boolean} allowRevert
186 */ 186 */
187 constructor(revision, baseRevision, allowRevert) { 187 constructor(revision, baseRevision, allowRevert) {
188 super(revision.timestamp.toLocaleTimeString(), true); 188 super(revision.timestamp.toLocaleTimeString(), true);
189 this.selectable = false; 189 this.selectable = false;
190 190
191 this._revision = revision; 191 this._revision = revision;
192 this._baseRevision = baseRevision; 192 this._baseRevision = baseRevision;
193 193
194 this._revertElement = createElement('span'); 194 this._revertElement = createElement('span');
195 this._revertElement.className = 'revision-history-link'; 195 this._revertElement.className = 'revision-history-link';
196 this._revertElement.textContent = WebInspector.UIString('apply revision cont ent'); 196 this._revertElement.textContent = Common.UIString('apply revision content');
197 this._revertElement.addEventListener('click', event => { 197 this._revertElement.addEventListener('click', event => {
198 this._revision.revertToThis(); 198 this._revision.revertToThis();
199 }, false); 199 }, false);
200 if (!allowRevert) 200 if (!allowRevert)
201 this._revertElement.classList.add('hidden'); 201 this._revertElement.classList.add('hidden');
202 } 202 }
203 203
204 /** 204 /**
205 * @override 205 * @override
206 */ 206 */
(...skipping 12 matching lines...) Expand all
219 .all([ 219 .all([
220 this._baseRevision ? this._baseRevision.requestContent() : 220 this._baseRevision ? this._baseRevision.requestContent() :
221 this._revision.uiSourceCode.requestOriginalConten t(), 221 this._revision.uiSourceCode.requestOriginalConten t(),
222 this._revision.requestContent() 222 this._revision.requestContent()
223 ]) 223 ])
224 .spread(diff.bind(this)); 224 .spread(diff.bind(this));
225 225
226 /** 226 /**
227 * @param {?string} baseContent 227 * @param {?string} baseContent
228 * @param {?string} newContent 228 * @param {?string} newContent
229 * @this {WebInspector.RevisionHistoryTreeElement} 229 * @this {Sources.RevisionHistoryTreeElement}
230 */ 230 */
231 function diff(baseContent, newContent) { 231 function diff(baseContent, newContent) {
232 var baseLines = baseContent.split('\n'); 232 var baseLines = baseContent.split('\n');
233 var newLines = newContent.split('\n'); 233 var newLines = newContent.split('\n');
234 var opcodes = WebInspector.Diff.lineDiff(baseLines, newLines); 234 var opcodes = Diff.Diff.lineDiff(baseLines, newLines);
235 var lastWasSeparator = false; 235 var lastWasSeparator = false;
236 236
237 var baseLineNumber = 0; 237 var baseLineNumber = 0;
238 var newLineNumber = 0; 238 var newLineNumber = 0;
239 for (var idx = 0; idx < opcodes.length; idx++) { 239 for (var idx = 0; idx < opcodes.length; idx++) {
240 var code = opcodes[idx][0]; 240 var code = opcodes[idx][0];
241 var rowCount = opcodes[idx][1].length; 241 var rowCount = opcodes[idx][1].length;
242 if (code === WebInspector.Diff.Operation.Equal) { 242 if (code === Diff.Diff.Operation.Equal) {
243 baseLineNumber += rowCount; 243 baseLineNumber += rowCount;
244 newLineNumber += rowCount; 244 newLineNumber += rowCount;
245 if (!lastWasSeparator) 245 if (!lastWasSeparator)
246 this._createLine(null, null, ' \u2026', 'separator'); 246 this._createLine(null, null, ' \u2026', 'separator');
247 lastWasSeparator = true; 247 lastWasSeparator = true;
248 } else if (code === WebInspector.Diff.Operation.Delete) { 248 } else if (code === Diff.Diff.Operation.Delete) {
249 lastWasSeparator = false; 249 lastWasSeparator = false;
250 for (var i = 0; i < rowCount; ++i) 250 for (var i = 0; i < rowCount; ++i)
251 this._createLine(baseLineNumber + i, null, baseLines[baseLineNumber + i], 'removed'); 251 this._createLine(baseLineNumber + i, null, baseLines[baseLineNumber + i], 'removed');
252 baseLineNumber += rowCount; 252 baseLineNumber += rowCount;
253 } else if (code === WebInspector.Diff.Operation.Insert) { 253 } else if (code === Diff.Diff.Operation.Insert) {
254 lastWasSeparator = false; 254 lastWasSeparator = false;
255 for (var i = 0; i < rowCount; ++i) 255 for (var i = 0; i < rowCount; ++i)
256 this._createLine(null, newLineNumber + i, newLines[newLineNumber + i ], 'added'); 256 this._createLine(null, newLineNumber + i, newLines[newLineNumber + i ], 'added');
257 newLineNumber += rowCount; 257 newLineNumber += rowCount;
258 } 258 }
259 } 259 }
260 } 260 }
261 } 261 }
262 262
263 /** 263 /**
(...skipping 29 matching lines...) Expand all
293 contentSpan.textContent = lineContent; 293 contentSpan.textContent = lineContent;
294 child.listItemElement.appendChild(contentSpan); 294 child.listItemElement.appendChild(contentSpan);
295 child.listItemElement.classList.add('revision-history-line'); 295 child.listItemElement.classList.add('revision-history-line');
296 contentSpan.classList.add('revision-history-line-' + changeType); 296 contentSpan.classList.add('revision-history-line-' + changeType);
297 } 297 }
298 298
299 allowRevert() { 299 allowRevert() {
300 this._revertElement.classList.remove('hidden'); 300 this._revertElement.classList.remove('hidden');
301 } 301 }
302 }; 302 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698