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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 this._name += '?' + parsedURL.queryParams; | 51 this._name += '?' + parsedURL.queryParams; |
| 52 } else { | 52 } else { |
| 53 this._origin = ''; | 53 this._origin = ''; |
| 54 this._parentURL = ''; | 54 this._parentURL = ''; |
| 55 this._name = url; | 55 this._name = url; |
| 56 } | 56 } |
| 57 | 57 |
| 58 this._contentType = contentType; | 58 this._contentType = contentType; |
| 59 /** @type {?Promise<?string>} */ | 59 /** @type {?Promise<?string>} */ |
| 60 this._requestContentPromise = null; | 60 this._requestContentPromise = null; |
| 61 /** @type {!Multimap<string, !Workspace.UISourceCode.LineMarker>} */ | 61 /** @type {?Multimap<string, !Workspace.UISourceCode.LineMarker>} */ |
| 62 this._decorations = new Multimap(); | 62 this._decorations = null; |
|
dgozman
2017/01/04 01:04:08
Do "Multimap|undefined" and don't assign here.
pfeldman
2017/01/04 01:13:48
should be = null;
| |
| 63 | 63 /** @type {?Array.<!Workspace.Revision>} */ |
| 64 /** @type {!Array.<!Workspace.Revision>} */ | 64 this._history = []; |
|
dgozman
2017/01/04 01:04:08
ditto
pfeldman
2017/01/04 01:13:48
Acknowledged.
| |
| 65 this.history = []; | 65 /** @type {?Array<!Workspace.UISourceCode.Message>} */ |
| 66 | 66 this._messages = null; |
|
dgozman
2017/01/04 01:04:08
ditto
pfeldman
2017/01/04 01:13:48
Acknowledged.
| |
| 67 /** @type {!Array<!Workspace.UISourceCode.Message>} */ | |
| 68 this._messages = []; | |
| 69 | |
| 70 this._contentLoaded = false; | 67 this._contentLoaded = false; |
| 71 /** @type {?string} */ | 68 /** @type {?string} */ |
| 72 this._content = null; | 69 this._content = null; |
| 73 this._forceLoadOnCheckContent = false; | 70 this._forceLoadOnCheckContent = false; |
| 74 this._checkingContent = false; | 71 this._checkingContent = false; |
| 75 /** @type {?string} */ | 72 /** @type {?string} */ |
| 76 this._lastAcceptedContent = null; | 73 this._lastAcceptedContent = null; |
| 77 /** @type {?string} */ | 74 /** @type {?string} */ |
| 78 this._workingCopy = null; | 75 this._workingCopy = null; |
| 79 /** @type {?function() : string} */ | 76 /** @type {?function() : string} */ |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 /** | 303 /** |
| 307 * @param {string} content | 304 * @param {string} content |
| 308 * @param {boolean} committedByUser | 305 * @param {boolean} committedByUser |
| 309 */ | 306 */ |
| 310 _contentCommitted(content, committedByUser) { | 307 _contentCommitted(content, committedByUser) { |
| 311 this._lastAcceptedContent = null; | 308 this._lastAcceptedContent = null; |
| 312 this._content = content; | 309 this._content = content; |
| 313 this._contentLoaded = true; | 310 this._contentLoaded = true; |
| 314 this._requestContentPromise = null; | 311 this._requestContentPromise = null; |
| 315 | 312 |
| 316 var lastRevision = this.history.length ? this.history[this.history.length - 1] : null; | 313 |
| 314 if (!this._history) | |
| 315 this._history = []; | |
| 316 | |
| 317 var lastRevision = this._history.length ? this._history[this._history.length - 1] : null; | |
| 317 if (!lastRevision || lastRevision._content !== this._content) { | 318 if (!lastRevision || lastRevision._content !== this._content) { |
| 318 var revision = new Workspace.Revision(this, this._content, new Date()); | 319 var revision = new Workspace.Revision(this, this._content, new Date()); |
| 319 this.history.push(revision); | 320 this._history.push(revision); |
| 320 } | 321 } |
| 321 | 322 |
| 322 this._innerResetWorkingCopy(); | 323 this._innerResetWorkingCopy(); |
| 323 this.dispatchEventToListeners( | 324 this.dispatchEventToListeners( |
| 324 Workspace.UISourceCode.Events.WorkingCopyCommitted, {uiSourceCode: this, content: content}); | 325 Workspace.UISourceCode.Events.WorkingCopyCommitted, {uiSourceCode: this, content: content}); |
| 325 this._project.workspace().dispatchEventToListeners( | 326 this._project.workspace().dispatchEventToListeners( |
| 326 Workspace.Workspace.Events.WorkingCopyCommitted, {uiSourceCode: this, co ntent: content}); | 327 Workspace.Workspace.Events.WorkingCopyCommitted, {uiSourceCode: this, co ntent: content}); |
| 327 if (committedByUser) { | 328 if (committedByUser) { |
| 328 this._project.workspace().dispatchEventToListeners( | 329 this._project.workspace().dispatchEventToListeners( |
| 329 Workspace.Workspace.Events.WorkingCopyCommittedByUser, {uiSourceCode: this, content: content}); | 330 Workspace.Workspace.Events.WorkingCopyCommittedByUser, {uiSourceCode: this, content: content}); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 376 revertAndClearHistory(callback) { | 377 revertAndClearHistory(callback) { |
| 377 /** | 378 /** |
| 378 * @this {Workspace.UISourceCode} | 379 * @this {Workspace.UISourceCode} |
| 379 * @param {?string} content | 380 * @param {?string} content |
| 380 */ | 381 */ |
| 381 function revert(content) { | 382 function revert(content) { |
| 382 if (typeof content !== 'string') | 383 if (typeof content !== 'string') |
| 383 return; | 384 return; |
| 384 | 385 |
| 385 this.addRevision(content); | 386 this.addRevision(content); |
| 386 this.history = []; | 387 this._history = null; |
| 387 callback(this); | 388 callback(this); |
| 388 } | 389 } |
| 389 | 390 |
| 390 Host.userMetrics.actionTaken(Host.UserMetrics.Action.RevisionApplied); | 391 Host.userMetrics.actionTaken(Host.UserMetrics.Action.RevisionApplied); |
| 391 this.requestOriginalContent().then(revert.bind(this)); | 392 this.requestOriginalContent().then(revert.bind(this)); |
| 392 } | 393 } |
| 393 | 394 |
| 394 /** | 395 /** |
| 396 * @return {!Array<!Workspace.Revision>} | |
| 397 */ | |
| 398 history() { | |
| 399 if (!this._history) | |
| 400 this._history = []; | |
| 401 return this._history; | |
| 402 } | |
| 403 | |
| 404 /** | |
| 395 * @return {string} | 405 * @return {string} |
| 396 */ | 406 */ |
| 397 workingCopy() { | 407 workingCopy() { |
| 398 if (this._workingCopyGetter) { | 408 if (this._workingCopyGetter) { |
| 399 this._workingCopy = this._workingCopyGetter(); | 409 this._workingCopy = this._workingCopyGetter(); |
| 400 this._workingCopyGetter = null; | 410 this._workingCopyGetter = null; |
| 401 } | 411 } |
| 402 if (this.isDirty()) | 412 if (this.isDirty()) |
| 403 return /** @type {string} */ (this._workingCopy); | 413 return /** @type {string} */ (this._workingCopy); |
| 404 return this._content || ''; | 414 return this._content || ''; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 511 uiLocation(lineNumber, columnNumber) { | 521 uiLocation(lineNumber, columnNumber) { |
| 512 if (typeof columnNumber === 'undefined') | 522 if (typeof columnNumber === 'undefined') |
| 513 columnNumber = 0; | 523 columnNumber = 0; |
| 514 return new Workspace.UILocation(this, lineNumber, columnNumber); | 524 return new Workspace.UILocation(this, lineNumber, columnNumber); |
| 515 } | 525 } |
| 516 | 526 |
| 517 /** | 527 /** |
| 518 * @return {!Array<!Workspace.UISourceCode.Message>} | 528 * @return {!Array<!Workspace.UISourceCode.Message>} |
| 519 */ | 529 */ |
| 520 messages() { | 530 messages() { |
| 521 return this._messages.slice(); | 531 return this._messages ? this._messages.slice() : []; |
| 522 } | 532 } |
| 523 | 533 |
| 524 /** | 534 /** |
| 525 * @param {!Workspace.UISourceCode.Message.Level} level | 535 * @param {!Workspace.UISourceCode.Message.Level} level |
| 526 * @param {string} text | 536 * @param {string} text |
| 527 * @param {number} lineNumber | 537 * @param {number} lineNumber |
| 528 * @param {number=} columnNumber | 538 * @param {number=} columnNumber |
| 529 * @return {!Workspace.UISourceCode.Message} message | 539 * @return {!Workspace.UISourceCode.Message} message |
| 530 */ | 540 */ |
| 531 addLineMessage(level, text, lineNumber, columnNumber) { | 541 addLineMessage(level, text, lineNumber, columnNumber) { |
| 532 return this.addMessage( | 542 return this.addMessage( |
| 533 level, text, new Common.TextRange(lineNumber, columnNumber || 0, lineNum ber, columnNumber || 0)); | 543 level, text, new Common.TextRange(lineNumber, columnNumber || 0, lineNum ber, columnNumber || 0)); |
| 534 } | 544 } |
| 535 | 545 |
| 536 /** | 546 /** |
| 537 * @param {!Workspace.UISourceCode.Message.Level} level | 547 * @param {!Workspace.UISourceCode.Message.Level} level |
| 538 * @param {string} text | 548 * @param {string} text |
| 539 * @param {!Common.TextRange} range | 549 * @param {!Common.TextRange} range |
| 540 * @return {!Workspace.UISourceCode.Message} message | 550 * @return {!Workspace.UISourceCode.Message} message |
| 541 */ | 551 */ |
| 542 addMessage(level, text, range) { | 552 addMessage(level, text, range) { |
| 543 var message = new Workspace.UISourceCode.Message(this, level, text, range); | 553 var message = new Workspace.UISourceCode.Message(this, level, text, range); |
| 554 if (!this._messages) | |
| 555 this._messages = []; | |
| 544 this._messages.push(message); | 556 this._messages.push(message); |
| 545 this.dispatchEventToListeners(Workspace.UISourceCode.Events.MessageAdded, me ssage); | 557 this.dispatchEventToListeners(Workspace.UISourceCode.Events.MessageAdded, me ssage); |
| 546 return message; | 558 return message; |
| 547 } | 559 } |
| 548 | 560 |
| 549 /** | 561 /** |
| 550 * @param {!Workspace.UISourceCode.Message} message | 562 * @param {!Workspace.UISourceCode.Message} message |
| 551 */ | 563 */ |
| 552 removeMessage(message) { | 564 removeMessage(message) { |
| 553 if (this._messages.remove(message)) | 565 if (this._messages && this._messages.remove(message)) |
| 554 this.dispatchEventToListeners(Workspace.UISourceCode.Events.MessageRemoved , message); | 566 this.dispatchEventToListeners(Workspace.UISourceCode.Events.MessageRemoved , message); |
| 555 } | 567 } |
| 556 | 568 |
| 557 _removeAllMessages() { | 569 _removeAllMessages() { |
| 558 var messages = this._messages; | 570 if (!this._messages) |
| 559 this._messages = []; | 571 return; |
| 560 for (var message of messages) | 572 for (var message of this._messages) |
| 561 this.dispatchEventToListeners(Workspace.UISourceCode.Events.MessageRemoved , message); | 573 this.dispatchEventToListeners(Workspace.UISourceCode.Events.MessageRemoved , message); |
| 574 this._messages = null; | |
| 562 } | 575 } |
| 563 | 576 |
| 564 /** | 577 /** |
| 565 * @param {number} lineNumber | 578 * @param {number} lineNumber |
| 566 * @param {string} type | 579 * @param {string} type |
| 567 * @param {?} data | 580 * @param {?} data |
| 568 */ | 581 */ |
| 569 addLineDecoration(lineNumber, type, data) { | 582 addLineDecoration(lineNumber, type, data) { |
| 570 this.addDecoration(Common.TextRange.createFromLocation(lineNumber, 0), type, data); | 583 this.addDecoration(Common.TextRange.createFromLocation(lineNumber, 0), type, data); |
| 571 } | 584 } |
| 572 | 585 |
| 573 /** | 586 /** |
| 574 * @param {!Common.TextRange} range | 587 * @param {!Common.TextRange} range |
| 575 * @param {string} type | 588 * @param {string} type |
| 576 * @param {?} data | 589 * @param {?} data |
| 577 */ | 590 */ |
| 578 addDecoration(range, type, data) { | 591 addDecoration(range, type, data) { |
| 579 var marker = new Workspace.UISourceCode.LineMarker(range, type, data); | 592 var marker = new Workspace.UISourceCode.LineMarker(range, type, data); |
| 593 if (!this._decorations) | |
| 594 this._decorations = new Multimap(); | |
| 580 this._decorations.set(type, marker); | 595 this._decorations.set(type, marker); |
| 581 this.dispatchEventToListeners(Workspace.UISourceCode.Events.LineDecorationAd ded, marker); | 596 this.dispatchEventToListeners(Workspace.UISourceCode.Events.LineDecorationAd ded, marker); |
| 582 } | 597 } |
| 583 | 598 |
| 584 /** | 599 /** |
| 585 * @param {string} type | 600 * @param {string} type |
| 586 */ | 601 */ |
| 587 removeDecorationsForType(type) { | 602 removeDecorationsForType(type) { |
| 603 if (!this._decorations) | |
| 604 return; | |
| 588 var markers = this._decorations.get(type); | 605 var markers = this._decorations.get(type); |
| 589 this._decorations.removeAll(type); | 606 this._decorations.removeAll(type); |
| 590 markers.forEach(marker => { | 607 markers.forEach(marker => { |
| 591 this.dispatchEventToListeners(Workspace.UISourceCode.Events.LineDecoration Removed, marker); | 608 this.dispatchEventToListeners(Workspace.UISourceCode.Events.LineDecoration Removed, marker); |
| 592 }); | 609 }); |
| 593 } | 610 } |
| 594 | 611 |
| 595 /** | 612 /** |
| 596 * @return {!Array<!Workspace.UISourceCode.LineMarker>} | 613 * @return {!Array<!Workspace.UISourceCode.LineMarker>} |
| 597 */ | 614 */ |
| 598 allDecorations() { | 615 allDecorations() { |
| 599 return this._decorations.valuesArray(); | 616 return this._decorations ? this._decorations.valuesArray() : []; |
| 600 } | 617 } |
| 601 | 618 |
| 602 removeAllDecorations() { | 619 removeAllDecorations() { |
| 620 if (!this._decorations) | |
| 621 return; | |
| 603 var decorationList = this._decorations.valuesArray(); | 622 var decorationList = this._decorations.valuesArray(); |
| 604 this._decorations.clear(); | 623 this._decorations.clear(); |
| 605 decorationList.forEach( | 624 decorationList.forEach( |
| 606 marker => this.dispatchEventToListeners(Workspace.UISourceCode.Events.Li neDecorationRemoved, marker)); | 625 marker => this.dispatchEventToListeners(Workspace.UISourceCode.Events.Li neDecorationRemoved, marker)); |
| 607 } | 626 } |
| 608 | 627 |
| 609 /** | 628 /** |
| 610 * @param {string} type | 629 * @param {string} type |
| 611 * @return {!Set<!Workspace.UISourceCode.LineMarker>} | 630 * @return {?Set<!Workspace.UISourceCode.LineMarker>} |
| 612 */ | 631 */ |
| 613 decorationsForType(type) { | 632 decorationsForType(type) { |
| 614 return this._decorations.get(type); | 633 return this._decorations ? this._decorations.get(type) : null; |
| 615 } | 634 } |
| 616 }; | 635 }; |
| 617 | 636 |
| 618 /** @enum {symbol} */ | 637 /** @enum {symbol} */ |
| 619 Workspace.UISourceCode.Events = { | 638 Workspace.UISourceCode.Events = { |
| 620 WorkingCopyChanged: Symbol('WorkingCopyChanged'), | 639 WorkingCopyChanged: Symbol('WorkingCopyChanged'), |
| 621 WorkingCopyCommitted: Symbol('WorkingCopyCommitted'), | 640 WorkingCopyCommitted: Symbol('WorkingCopyCommitted'), |
| 622 TitleChanged: Symbol('TitleChanged'), | 641 TitleChanged: Symbol('TitleChanged'), |
| 623 MessageAdded: Symbol('MessageAdded'), | 642 MessageAdded: Symbol('MessageAdded'), |
| 624 MessageRemoved: Symbol('MessageRemoved'), | 643 MessageRemoved: Symbol('MessageRemoved'), |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 901 Workspace.UISourceCodeMetadata = class { | 920 Workspace.UISourceCodeMetadata = class { |
| 902 /** | 921 /** |
| 903 * @param {?Date} modificationTime | 922 * @param {?Date} modificationTime |
| 904 * @param {?number} contentSize | 923 * @param {?number} contentSize |
| 905 */ | 924 */ |
| 906 constructor(modificationTime, contentSize) { | 925 constructor(modificationTime, contentSize) { |
| 907 this.modificationTime = modificationTime; | 926 this.modificationTime = modificationTime; |
| 908 this.contentSize = contentSize; | 927 this.contentSize = contentSize; |
| 909 } | 928 } |
| 910 }; | 929 }; |
| OLD | NEW |