| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 /** @type {?string} */ | 68 /** @type {?string} */ |
| 69 this._content = null; | 69 this._content = null; |
| 70 this._forceLoadOnCheckContent = false; | 70 this._forceLoadOnCheckContent = false; |
| 71 this._checkingContent = false; | 71 this._checkingContent = false; |
| 72 /** @type {?string} */ | 72 /** @type {?string} */ |
| 73 this._lastAcceptedContent = null; | 73 this._lastAcceptedContent = null; |
| 74 /** @type {?string} */ | 74 /** @type {?string} */ |
| 75 this._workingCopy = null; | 75 this._workingCopy = null; |
| 76 /** @type {?function() : string} */ | 76 /** @type {?function() : string} */ |
| 77 this._workingCopyGetter = null; | 77 this._workingCopyGetter = null; |
| 78 this._mightHaveChanges = false; |
| 78 } | 79 } |
| 79 | 80 |
| 80 /** | 81 /** |
| 81 * @return {!Promise<?Workspace.UISourceCodeMetadata>} | 82 * @return {!Promise<?Workspace.UISourceCodeMetadata>} |
| 82 */ | 83 */ |
| 83 requestMetadata() { | 84 requestMetadata() { |
| 84 return this._project.requestMetadata(this); | 85 return this._project.requestMetadata(this); |
| 85 } | 86 } |
| 86 | 87 |
| 87 /** | 88 /** |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 this._requestContentPromise = null; | 312 this._requestContentPromise = null; |
| 312 | 313 |
| 313 | 314 |
| 314 if (!this._history) | 315 if (!this._history) |
| 315 this._history = []; | 316 this._history = []; |
| 316 | 317 |
| 317 var lastRevision = this._history.length ? this._history[this._history.length
- 1] : null; | 318 var lastRevision = this._history.length ? this._history[this._history.length
- 1] : null; |
| 318 if (!lastRevision || lastRevision._content !== this._content) { | 319 if (!lastRevision || lastRevision._content !== this._content) { |
| 319 var revision = new Workspace.Revision(this, this._content, new Date()); | 320 var revision = new Workspace.Revision(this, this._content, new Date()); |
| 320 this._history.push(revision); | 321 this._history.push(revision); |
| 322 this.mightHaveChanges = true; |
| 321 } | 323 } |
| 322 | 324 |
| 323 this._innerResetWorkingCopy(); | 325 this._innerResetWorkingCopy(); |
| 324 this.dispatchEventToListeners( | 326 this.dispatchEventToListeners( |
| 325 Workspace.UISourceCode.Events.WorkingCopyCommitted, {uiSourceCode: this,
content: content}); | 327 Workspace.UISourceCode.Events.WorkingCopyCommitted, {uiSourceCode: this,
content: content}); |
| 326 this._project.workspace().dispatchEventToListeners( | 328 this._project.workspace().dispatchEventToListeners( |
| 327 Workspace.Workspace.Events.WorkingCopyCommitted, {uiSourceCode: this, co
ntent: content}); | 329 Workspace.Workspace.Events.WorkingCopyCommitted, {uiSourceCode: this, co
ntent: content}); |
| 328 if (committedByUser) { | 330 if (committedByUser) { |
| 329 this._project.workspace().dispatchEventToListeners( | 331 this._project.workspace().dispatchEventToListeners( |
| 330 Workspace.Workspace.Events.WorkingCopyCommittedByUser, {uiSourceCode:
this, content: content}); | 332 Workspace.Workspace.Events.WorkingCopyCommittedByUser, {uiSourceCode:
this, content: content}); |
| 331 } | 333 } |
| 332 } | 334 } |
| 333 | 335 |
| 336 /** |
| 337 * @return {!Promise<boolean>} |
| 338 */ |
| 339 hasChanges() { |
| 340 if (!this.mightHaveChanges) |
| 341 return Promise.resolve(false); |
| 342 return this.requestOriginalContent().then(content => this.mightHaveChanges =
content !== this.workingCopy()); |
| 343 } |
| 344 |
| 334 saveAs() { | 345 saveAs() { |
| 335 Workspace.fileManager.save(this._url, this.workingCopy(), true, callback.bin
d(this)); | 346 Workspace.fileManager.save(this._url, this.workingCopy(), true, callback.bin
d(this)); |
| 336 Workspace.fileManager.close(this._url); | 347 Workspace.fileManager.close(this._url); |
| 337 | 348 |
| 338 /** | 349 /** |
| 339 * @param {boolean} accepted | 350 * @param {boolean} accepted |
| 340 * @this {Workspace.UISourceCode} | 351 * @this {Workspace.UISourceCode} |
| 341 */ | 352 */ |
| 342 function callback(accepted) { | 353 function callback(accepted) { |
| 343 if (accepted) | 354 if (accepted) |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 | 446 |
| 436 /** | 447 /** |
| 437 * @param {function(): string } workingCopyGetter | 448 * @param {function(): string } workingCopyGetter |
| 438 */ | 449 */ |
| 439 setWorkingCopyGetter(workingCopyGetter) { | 450 setWorkingCopyGetter(workingCopyGetter) { |
| 440 this._workingCopyGetter = workingCopyGetter; | 451 this._workingCopyGetter = workingCopyGetter; |
| 441 this._workingCopyChanged(); | 452 this._workingCopyChanged(); |
| 442 } | 453 } |
| 443 | 454 |
| 444 _workingCopyChanged() { | 455 _workingCopyChanged() { |
| 456 this.mightHaveChanges = true; |
| 445 this._removeAllMessages(); | 457 this._removeAllMessages(); |
| 446 this.dispatchEventToListeners(Workspace.UISourceCode.Events.WorkingCopyChang
ed, this); | 458 this.dispatchEventToListeners(Workspace.UISourceCode.Events.WorkingCopyChang
ed, this); |
| 447 this._project.workspace().dispatchEventToListeners( | 459 this._project.workspace().dispatchEventToListeners( |
| 448 Workspace.Workspace.Events.WorkingCopyChanged, {uiSourceCode: this}); | 460 Workspace.Workspace.Events.WorkingCopyChanged, {uiSourceCode: this}); |
| 449 } | 461 } |
| 450 | 462 |
| 451 removeWorkingCopyGetter() { | 463 removeWorkingCopyGetter() { |
| 452 if (!this._workingCopyGetter) | 464 if (!this._workingCopyGetter) |
| 453 return; | 465 return; |
| 454 this._workingCopy = this._workingCopyGetter(); | 466 this._workingCopy = this._workingCopyGetter(); |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 Workspace.UISourceCodeMetadata = class { | 932 Workspace.UISourceCodeMetadata = class { |
| 921 /** | 933 /** |
| 922 * @param {?Date} modificationTime | 934 * @param {?Date} modificationTime |
| 923 * @param {?number} contentSize | 935 * @param {?number} contentSize |
| 924 */ | 936 */ |
| 925 constructor(modificationTime, contentSize) { | 937 constructor(modificationTime, contentSize) { |
| 926 this.modificationTime = modificationTime; | 938 this.modificationTime = modificationTime; |
| 927 this.contentSize = contentSize; | 939 this.contentSize = contentSize; |
| 928 } | 940 } |
| 929 }; | 941 }; |
| OLD | NEW |