Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 /** @type {?Promise<?string>} */ | 61 /** @type {?Promise<?string>} */ |
| 62 this._requestContentPromise = null; | 62 this._requestContentPromise = null; |
| 63 /** @type {!Multimap<string, !Workspace.UISourceCode.LineMarker>} */ | 63 /** @type {!Multimap<string, !Workspace.UISourceCode.LineMarker>} */ |
| 64 this._decorations = new Multimap(); | 64 this._decorations = new Multimap(); |
| 65 | 65 |
| 66 /** @type {!Array.<!Workspace.Revision>} */ | 66 /** @type {!Array.<!Workspace.Revision>} */ |
| 67 this.history = []; | 67 this.history = []; |
| 68 | 68 |
| 69 /** @type {!Array<!Workspace.UISourceCode.Message>} */ | 69 /** @type {!Array<!Workspace.UISourceCode.Message>} */ |
| 70 this._messages = []; | 70 this._messages = []; |
| 71 | |
| 72 this._contentLoaded = false; | |
| 73 /** @type {?string} */ | |
| 74 this._originalContent = null; | |
| 75 /** @type {?string} */ | |
| 76 this._content = null; | |
| 71 } | 77 } |
| 72 | 78 |
| 73 /** | 79 /** |
| 74 * @return {!Promise<?Workspace.UISourceCodeMetadata>} | 80 * @return {!Promise<?Workspace.UISourceCodeMetadata>} |
| 75 */ | 81 */ |
| 76 requestMetadata() { | 82 requestMetadata() { |
| 77 return this._project.requestMetadata(this); | 83 return this._project.requestMetadata(this); |
| 78 } | 84 } |
| 79 | 85 |
| 80 /** | 86 /** |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 } | 272 } |
| 267 | 273 |
| 268 forceLoadOnCheckContent() { | 274 forceLoadOnCheckContent() { |
| 269 this._forceLoadOnCheckContent = true; | 275 this._forceLoadOnCheckContent = true; |
| 270 } | 276 } |
| 271 | 277 |
| 272 /** | 278 /** |
| 273 * @return {!Promise<?string>} | 279 * @return {!Promise<?string>} |
| 274 */ | 280 */ |
| 275 requestOriginalContent() { | 281 requestOriginalContent() { |
| 276 var callback; | 282 if (this._contentLoaded) |
| 277 var promise = new Promise(fulfill => callback = fulfill); | 283 return Promise.resolve(this._originalContent); |
| 278 this._project.requestFileContent(this, callback); | 284 return this.requestContent(); |
| 279 return promise; | |
| 280 } | 285 } |
| 281 | 286 |
| 282 /** | 287 /** |
| 283 * @param {string} content | 288 * @param {string} content |
| 284 */ | 289 */ |
| 285 _commitContent(content) { | 290 _commitContent(content) { |
| 286 if (this._project.canSetFileContent()) { | 291 if (this._project.canSetFileContent()) { |
| 287 this._project.setFileContent(this, content, function() {}); | 292 this._project.setFileContent(this, content, function() {}); |
| 288 } else if (this._url && Workspace.fileManager.isURLSaved(this._url)) { | 293 } else if (this._url && Workspace.fileManager.isURLSaved(this._url)) { |
| 289 Workspace.fileManager.save(this._url, content, false, function() {}); | 294 Workspace.fileManager.save(this._url, content, false, function() {}); |
| 290 Workspace.fileManager.close(this._url); | 295 Workspace.fileManager.close(this._url); |
| 291 } | 296 } |
| 292 this._contentCommitted(content, true); | 297 this._contentCommitted(content, true); |
| 293 } | 298 } |
| 294 | 299 |
| 295 /** | 300 /** |
| 296 * @param {string} content | 301 * @param {string} content |
| 297 * @param {boolean} committedByUser | 302 * @param {boolean} committedByUser |
| 298 */ | 303 */ |
| 299 _contentCommitted(content, committedByUser) { | 304 _contentCommitted(content, committedByUser) { |
| 300 delete this._lastAcceptedContent; | 305 delete this._lastAcceptedContent; |
| 301 this._content = content; | 306 this._setContent(content); |
|
lushnikov
2016/12/17 00:10:51
why do you want to link original content to the co
einbinder
2016/12/20 00:56:55
Yep. Done.
| |
| 302 this._contentLoaded = true; | |
| 303 | 307 |
| 304 var lastRevision = this.history.length ? this.history[this.history.length - 1] : null; | 308 var lastRevision = this.history.length ? this.history[this.history.length - 1] : null; |
| 305 if (!lastRevision || lastRevision._content !== this._content) { | 309 if (!lastRevision || lastRevision._content !== this._content) { |
| 306 var revision = new Workspace.Revision(this, this._content, new Date()); | 310 var revision = new Workspace.Revision(this, this._content, new Date()); |
| 307 this.history.push(revision); | 311 this.history.push(revision); |
| 308 } | 312 } |
| 309 | 313 |
| 310 this._innerResetWorkingCopy(); | 314 this._innerResetWorkingCopy(); |
| 311 this.dispatchEventToListeners( | 315 this.dispatchEventToListeners( |
| 312 Workspace.UISourceCode.Events.WorkingCopyCommitted, {uiSourceCode: this, content: content}); | 316 Workspace.UISourceCode.Events.WorkingCopyCommitted, {uiSourceCode: this, content: content}); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 /** | 386 /** |
| 383 * @return {string} | 387 * @return {string} |
| 384 */ | 388 */ |
| 385 workingCopy() { | 389 workingCopy() { |
| 386 if (this._workingCopyGetter) { | 390 if (this._workingCopyGetter) { |
| 387 this._workingCopy = this._workingCopyGetter(); | 391 this._workingCopy = this._workingCopyGetter(); |
| 388 delete this._workingCopyGetter; | 392 delete this._workingCopyGetter; |
| 389 } | 393 } |
| 390 if (this.isDirty()) | 394 if (this.isDirty()) |
| 391 return this._workingCopy; | 395 return this._workingCopy; |
| 392 return this._content; | 396 return this._content || ''; |
|
einbinder
2016/12/16 23:43:00
This could have returned null before.
| |
| 393 } | 397 } |
| 394 | 398 |
| 395 resetWorkingCopy() { | 399 resetWorkingCopy() { |
| 396 this._innerResetWorkingCopy(); | 400 this._innerResetWorkingCopy(); |
| 397 this._workingCopyChanged(); | 401 this._workingCopyChanged(); |
| 398 } | 402 } |
| 399 | 403 |
| 400 _innerResetWorkingCopy() { | 404 _innerResetWorkingCopy() { |
| 401 delete this._workingCopy; | 405 delete this._workingCopy; |
| 402 delete this._workingCopyGetter; | 406 delete this._workingCopyGetter; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 478 */ | 482 */ |
| 479 function doSearch(content) { | 483 function doSearch(content) { |
| 480 callback(Common.ContentProvider.performSearchInContent(content, query, cas eSensitive, isRegex)); | 484 callback(Common.ContentProvider.performSearchInContent(content, query, cas eSensitive, isRegex)); |
| 481 } | 485 } |
| 482 } | 486 } |
| 483 | 487 |
| 484 /** | 488 /** |
| 485 * @param {?string} content | 489 * @param {?string} content |
| 486 */ | 490 */ |
| 487 _fireContentAvailable(content) { | 491 _fireContentAvailable(content) { |
| 488 this._contentLoaded = true; | 492 this._setContent(content); |
| 489 this._content = content; | |
| 490 | 493 |
| 491 var callback = this._requestContentCallback; | 494 var callback = this._requestContentCallback; |
| 492 this._requestContentCallback = null; | 495 this._requestContentCallback = null; |
| 493 this._requestContentPromise = null; | 496 this._requestContentPromise = null; |
| 494 | 497 |
| 495 callback.call(null, content); | 498 callback.call(null, content); |
| 496 } | 499 } |
| 497 | 500 |
| 498 /** | 501 /** |
| 502 * @param {?string} content | |
| 503 */ | |
| 504 _setContent(content) { | |
| 505 if (!this._contentLoaded) | |
| 506 this._originalContent = content; | |
| 507 this._contentLoaded = true; | |
| 508 this._content = content; | |
| 509 } | |
| 510 | |
| 511 /** | |
| 499 * @return {boolean} | 512 * @return {boolean} |
| 500 */ | 513 */ |
| 501 contentLoaded() { | 514 contentLoaded() { |
| 502 return this._contentLoaded; | 515 return this._contentLoaded; |
| 503 } | 516 } |
| 504 | 517 |
| 505 /** | 518 /** |
| 506 * @param {number} lineNumber | 519 * @param {number} lineNumber |
| 507 * @param {number=} columnNumber | 520 * @param {number=} columnNumber |
| 508 * @return {!Workspace.UILocation} | 521 * @return {!Workspace.UILocation} |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 901 Workspace.UISourceCodeMetadata = class { | 914 Workspace.UISourceCodeMetadata = class { |
| 902 /** | 915 /** |
| 903 * @param {?Date} modificationTime | 916 * @param {?Date} modificationTime |
| 904 * @param {?number} contentSize | 917 * @param {?number} contentSize |
| 905 */ | 918 */ |
| 906 constructor(modificationTime, contentSize) { | 919 constructor(modificationTime, contentSize) { |
| 907 this.modificationTime = modificationTime; | 920 this.modificationTime = modificationTime; |
| 908 this.contentSize = contentSize; | 921 this.contentSize = contentSize; |
| 909 } | 922 } |
| 910 }; | 923 }; |
| OLD | NEW |